repo stringlengths 1 99 | file stringlengths 13 215 | code stringlengths 12 59.2M | file_length int64 12 59.2M | avg_line_length float64 3.82 1.48M | max_line_length int64 12 2.51M | extension_type stringclasses 1
value |
|---|---|---|---|---|---|---|
Seq-NAT | Seq-NAT-main/fairseq/data/prepend_token_dataset.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
import torch
from . import BaseWrapperDataset
class PrependTokenDataset(BaseWrapperDataset):
def __init__(self, dat... | 1,067 | 23.837209 | 65 | py |
Seq-NAT | Seq-NAT-main/fairseq/data/numel_dataset.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
import torch
from . import BaseWrapperDataset
class NumelDataset(BaseWrapperDataset):
def __init__(self, dataset, r... | 787 | 22.878788 | 65 | py |
Seq-NAT | Seq-NAT-main/fairseq/data/noising.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch
import numpy as np
from fairseq.data import data_utils
class WordNoising(object):
"""Generate a noisy version of a sentenc... | 12,177 | 37.537975 | 110 | py |
Seq-NAT | Seq-NAT-main/fairseq/data/concat_sentences_dataset.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch
from . import FairseqDataset
class ConcatSentencesDataset(FairseqDataset):
def __init__(self, *datasets):
super()... | 1,573 | 26.614035 | 75 | py |
Seq-NAT | Seq-NAT-main/fairseq/data/fairseq_dataset.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
import torch.utils.data
class EpochListening:
"""Mixin for receiving updates whenever the epoch increments."""
de... | 2,202 | 29.178082 | 80 | py |
Seq-NAT | Seq-NAT-main/fairseq/data/transform_eos_dataset.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch
from . import FairseqDataset
class TransformEosDataset(FairseqDataset):
"""A :class:`~fairseq.data.FairseqDataset` wrapper... | 4,576 | 36.516393 | 88 | py |
Seq-NAT | Seq-NAT-main/fairseq/data/audio/raw_audio_dataset.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import os
import numpy as np
import sys
import torch
import torch.nn.functional as F
from .. import FairseqDataset
class RawAudioDataset(... | 4,571 | 28.121019 | 84 | py |
Seq-NAT | Seq-NAT-main/fairseq/data/encoders/utils.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch
from fairseq.data import encoders
def get_whole_word_mask(args, dictionary):
bpe = encoders.build_bpe(args)
if bpe is n... | 907 | 30.310345 | 67 | py |
Seq-NAT | Seq-NAT-main/fairseq/data/encoders/hf_bert_bpe.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from fairseq.data.encoders import register_bpe
@register_bpe('bert')
class BertBPE(object):
@staticmethod
def add_args(parser):
... | 1,799 | 33.615385 | 90 | py |
Seq-NAT | Seq-NAT-main/fairseq/data/legacy/block_pair_dataset.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import math
import numpy as np
import torch
from fairseq.data import FairseqDataset
class BlockPairDataset(FairseqDataset):
"""Break a... | 12,878 | 40.146965 | 99 | py |
Seq-NAT | Seq-NAT-main/fairseq/data/legacy/masked_lm_dataset.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import math
import numpy as np
import torch
from typing import Dict, List, Tuple
from fairseq.data import FairseqDataset, data_utils
from ... | 12,468 | 37.603715 | 83 | py |
Seq-NAT | Seq-NAT-main/fairseq/tasks/language_modeling.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import logging
import os
import numpy as np
import torch
from fairseq import utils
from fairseq.data import (
data_utils,
Dictionary... | 10,098 | 36.682836 | 112 | py |
Seq-NAT | Seq-NAT-main/fairseq/tasks/multilingual_masked_lm.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import logging
import os
import numpy as np
import torch
from fairseq.data import (
data_utils,
Dictionary,
encoders,
Concat... | 12,582 | 38.694006 | 98 | py |
Seq-NAT | Seq-NAT-main/fairseq/tasks/multilingual_translation.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from collections import OrderedDict
import logging
import os
import torch
from fairseq import metrics, options
from fairseq.data import (
... | 15,069 | 43.064327 | 116 | py |
Seq-NAT | Seq-NAT-main/fairseq/tasks/translation_lev.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import pdb
import os
import torch
from fairseq.utils import new_arange
from fairseq.tasks import register_task
from fairseq.tasks.translation... | 6,587 | 39.919255 | 87 | py |
Seq-NAT | Seq-NAT-main/fairseq/tasks/translation_moe.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch
from fairseq import metrics, modules, utils
from fairseq.tasks import register_task
from fairseq.tasks.translation import Transl... | 8,990 | 40.43318 | 96 | py |
Seq-NAT | Seq-NAT-main/fairseq/tasks/fairseq_task.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import warnings
import torch
from fairseq import metrics, search, tokenizer, utils
from fairseq.data import (
data_utils,
FairseqDat... | 15,232 | 38.463731 | 99 | py |
Seq-NAT | Seq-NAT-main/docs/conf.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# fairseq documentation build configuration file, created by
# sphinx-quickstart on Fri Aug 17 21:45:30 2018.
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in this
# au... | 4,235 | 30.849624 | 80 | py |
Seq-NAT | Seq-NAT-main/fairseq_cli/generate.py | #!/usr/bin/env python3 -u
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
"""
Translate pre-processed data with a trained model.
"""
import logging
import math
import os
import sys
import t... | 9,154 | 38.978166 | 110 | py |
Seq-NAT | Seq-NAT-main/fairseq_cli/validate.py | #!/usr/bin/env python3 -u
#!/usr/bin/env python3 -u
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import logging
import sys
import torch
from fairseq import checkpoint_utils, metrics, op... | 3,655 | 30.517241 | 88 | py |
Seq-NAT | Seq-NAT-main/fairseq_cli/eval_lm.py | #!/usr/bin/env python3 -u
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
"""
Evaluate the perplexity of a trained language model.
"""
import logging
import math
import os
import torch
fr... | 8,509 | 33.734694 | 112 | py |
Seq-NAT | Seq-NAT-main/fairseq_cli/interactive.py | #!/usr/bin/env python3 -u
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
"""
Translate raw text with a trained model. Batches data on-the-fly.
"""
from collections import namedtuple
import ... | 7,084 | 31.953488 | 103 | py |
Seq-NAT | Seq-NAT-main/fairseq_cli/train.py | #!/usr/bin/env python3 -u
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
"""
Train a new model on one or across multiple GPUs.
"""
import logging
import math
import os
import random
import ... | 11,083 | 34.525641 | 117 | py |
Medical-Transformer | Medical-Transformer-main/utils_gray.py | import os
import numpy as np
import torch
from skimage import io,color
from PIL import Image
from torch.utils.data import Dataset
from torchvision import transforms as T
from torchvision.transforms import functional as F
from typing import Callable
import os
import cv2
import pandas as pd
from numbers import Number
... | 9,774 | 33.419014 | 120 | py |
Medical-Transformer | Medical-Transformer-main/test.py | import argparse
import lib
import torch
import torchvision
from torch import nn
from torch.autograd import Variable
from torch.utils.data import DataLoader
from torchvision import transforms
from torchvision.utils import save_image
from torchvision.datasets import MNIST
import torch.nn.functional as F
import os
import ... | 5,150 | 33.34 | 92 | py |
Medical-Transformer | Medical-Transformer-main/utils.py | import os
import numpy as np
import torch
from skimage import io,color
from PIL import Image
from torch.utils.data import Dataset
from torchvision import transforms as T
from torchvision.transforms import functional as F
from typing import Callable
import os
import cv2
import pandas as pd
from numbers import Number
... | 9,769 | 33.522968 | 120 | py |
Medical-Transformer | Medical-Transformer-main/metrics.py | import torch
from torch.nn.functional import cross_entropy
from torch.nn.modules.loss import _WeightedLoss
EPSILON = 1e-32
class LogNLLLoss(_WeightedLoss):
__constants__ = ['weight', 'reduction', 'ignore_index']
def __init__(self, weight=None, size_average=None, reduce=None, reduction=None,
... | 3,107 | 31.041237 | 104 | py |
Medical-Transformer | Medical-Transformer-main/extractors.py | from collections import OrderedDict
import math
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.utils import model_zoo
from torchvision.models.densenet import densenet121, densenet161
from torchvision.models.squeezenet import squeezenet1_1
def load_weights_sequential(target, source_stat... | 13,607 | 35.385027 | 109 | py |
Medical-Transformer | Medical-Transformer-main/train.py | # Code for MedT
import torch
import lib
import argparse
import torch
import torchvision
from torch import nn
from torch.autograd import Variable
from torch.utils.data import DataLoader
from torchvision import transforms
from torchvision.utils import save_image
import torch.nn.functional as F
import os
import matplotli... | 7,715 | 33.914027 | 92 | py |
Medical-Transformer | Medical-Transformer-main/lib/utils.py | import math
import os
import torch
import torch.nn.functional as F
def adjust_learning_rate(args, optimizer, epoch, batch_idx, data_nums, type="cosine"):
if epoch < args.warmup_epochs:
epoch += float(batch_idx + 1) / data_nums
lr_adj = 1. * (epoch / args.warmup_epochs)
elif type == "linear":
... | 5,487 | 31.666667 | 100 | py |
Medical-Transformer | Medical-Transformer-main/lib/build_optimizer.py | import torch.optim as optim
def build_optimizer(args, model):
if args.optim == 'sgd':
optimizer = optim.SGD(model.parameters(), lr=args.lr,
momentum=args.momentum, weight_decay=args.weight_decay,
nesterov=args.nesterov)
else:
raise As... | 355 | 26.384615 | 85 | py |
Medical-Transformer | Medical-Transformer-main/lib/metrics.py | import torch
class Metric(object):
def __init__(self, name):
self.name = name
self.sum = torch.tensor(0.)
self.n = torch.tensor(0.)
def update(self, val):
self.sum += val.detach().cpu()
self.n += 1
@property
def avg(self):
return self.sum / self.n | 315 | 18.75 | 38 | py |
Medical-Transformer | Medical-Transformer-main/lib/models/resnet.py | import torch
import torch.nn as nn
__all__ = ['ResNet', 'resnet26', 'resnet18', 'resnet34', 'resnet50', 'resnet101',
'resnet152',]
model_urls = {
'resnet18': 'https://download.pytorch.org/models/resnet18-5c106cde.pth',
'resnet34': 'https://download.pytorch.org/models/resnet34-333f7ec4.pth',
'... | 11,433 | 38.701389 | 106 | py |
Medical-Transformer | Medical-Transformer-main/lib/models/utils.py | import torch.nn as nn
class qkv_transform(nn.Conv1d):
"""Conv1d for qkv_transform"""
| 92 | 12.285714 | 34 | py |
Medical-Transformer | Medical-Transformer-main/lib/models/model_codes.py | import pdb
import math
import torch
import torch.nn as nn
import torch.nn.functional as F
from .utils import *
import pdb
import matplotlib.pyplot as plt
import random
__all__ = ['axial26s', 'axial50s', 'axial50m', 'axial50l']
def conv1x1(in_planes, out_planes, stride=1):
"""1x1 convolution"""
return nn.Co... | 105,319 | 44.318417 | 164 | py |
Medical-Transformer | Medical-Transformer-main/lib/models/axialnet.py | import pdb
import math
import torch
import torch.nn as nn
import torch.nn.functional as F
from .utils import *
import pdb
import matplotlib.pyplot as plt
import random
def conv1x1(in_planes, out_planes, stride=1):
"""1x1 convolution"""
return nn.Conv2d(in_planes, out_planes, kernel_size=1, stride=stride, b... | 30,838 | 41.245205 | 164 | py |
Medical-Transformer | Medical-Transformer-main/lib/datasets/imagenet1k.py | import torch
import torchvision
from torchvision import datasets, transforms
def imagenet1k(args, distributed=False):
train_dirs = args.train_dirs
val_dirs = args.val_dirs
batch_size = args.batch_size
val_batch_size = args.val_batch_size
num_workers = args.num_workers
color_jitter = args.color... | 1,938 | 33.017544 | 113 | py |
DeepRaNE | DeepRaNE-master/precipitation nowcasting/inference.py | import numpy as np
import torch
from model import UNetClassificationV2
from pyproj import Proj
from itertools import chain
import gzip
import os
def load_data(point, timestamp, data_path, gap):
target_year = int(timestamp[:4])
center, radius = (1024, 1024), 734
days = [31, 28, 31, 30, 31, 30, 31, 31, ... | 4,963 | 44.541284 | 168 | py |
DeepRaNE | DeepRaNE-master/precipitation nowcasting/pretrain.py | from tqdm import tqdm
import torch
from torch.utils.data import random_split, DataLoader
import numpy as np
from dataset import RadarOnlyMultiDataset
from model import UNetClassificationV2
def train(args):
train_dataset = RadarOnlyMultiDataset(data_path = args.data_path, year_from=2014, year_to=2018) # changed to... | 4,471 | 43.277228 | 118 | py |
DeepRaNE | DeepRaNE-master/precipitation nowcasting/finetuning-focal.py | from tqdm import tqdm
import numpy as np
import torch
from torch.utils.data import random_split, DataLoader
import time
from dataset import RadarAndRainMultiDataset
from model import UNetClassificationV2
import os
import torch.nn.functional as F
class FocalLoss(torch.nn.Module):
def __init__(self, gamma=0, eps=... | 8,503 | 49.922156 | 185 | py |
DeepRaNE | DeepRaNE-master/precipitation nowcasting/model.py | import torch
from torch import nn
class ConvBNAct(nn.Module):
def __init__(self, in_channels, out_channels, act_fn = nn.ReLU):
super(ConvBNAct, self).__init__()
self.conv = nn.Conv2d(in_channels, out_channels, 3)
self.bn = nn.BatchNorm2d(out_channels)
self.act = act_fn()
... | 5,485 | 41.2 | 126 | py |
DeepRaNE | DeepRaNE-master/precipitation nowcasting/dataset.py | import gzip
import numpy as np
import torch
import torch.nn as nn
from itertools import chain
import pickle
import os
import random
import tqdm
class RadarOnlyMultiDataset(torch.utils.data.Dataset):
def __init__(self, data_path, year_from=2014, year_to=2018, min_interval=10, max_interval=360, input_dim=7, center=(... | 7,462 | 55.112782 | 179 | py |
DeepRaNE | DeepRaNE-master/precipitation nowcasting/evaluation.py | from tqdm import tqdm
import numpy as np
import torch
from torch.utils.data import random_split, DataLoader
from dataset import RadarAndRainMultiDataset
from model import UNetClassificationV2
import os
def evaluation(args):
test_dataset = RadarAndRainMultiDataset(sampled_path = args.sampled_path, data_path = arg... | 5,653 | 56.111111 | 228 | py |
DeepRaNE | DeepRaNE-master/precipitation nowcasting/finetuning-CE.py | from tqdm import tqdm
import numpy as np
import torch
from torch.utils.data import random_split, DataLoader
import time
from dataset import RadarAndRainMultiDataset
from model import UNetClassificationV2
import os
def train(args):
train_dataset = RadarAndRainMultiDataset(sampled_path = args.sampled_path, data_pa... | 8,010 | 52.406667 | 185 | py |
DeepRaNE | DeepRaNE-master/precipitation nowcasting/finetuning-ours.py | from tqdm import tqdm
import numpy as np
import torch
from torch.utils.data import random_split, DataLoader
import time
from dataset import RadarAndRainMultiDataset
from model import UNetClassificationV2
import os
def train(args):
train_dataset = RadarAndRainMultiDataset(sampled_path = args.sampled_path, data_pa... | 9,526 | 55.041176 | 185 | py |
DeepRaNE | DeepRaNE-master/precipitation estimation/pretrain.py | from tqdm import tqdm
import torch
from torch.utils.data import random_split, DataLoader, Subset
import numpy as np
import pickle
from dataset import RadarOnlyDataset
from model import UNetPretrain
import time
def train(args):
train_dataset = RadarOnlyDataset(data_path = args.data_path, year_from=2014, year_to=201... | 5,899 | 50.304348 | 245 | py |
DeepRaNE | DeepRaNE-master/precipitation estimation/model.py | import torch
from torch import nn
class ConvBNAct(nn.Module):
def __init__(self, in_channels, out_channels, act_fn = nn.ReLU):
super(ConvBNAct, self).__init__()
self.conv = nn.Conv2d(in_channels, out_channels, 3)
self.bn = nn.BatchNorm2d(out_channels)
self.act = act_fn()
... | 3,090 | 38.628205 | 126 | py |
DeepRaNE | DeepRaNE-master/precipitation estimation/dataset.py | import gzip
import numpy as np
import torch
import torch.nn as nn
from itertools import chain
import pickle
import os
import random
import tqdm
import math
class RadarAndRainCumulatedDataset(torch.utils.data.Dataset):
def __init__(self, sampled_path, data_path, year_from=2014, year_to=2018, interval=0, input_dim=7... | 10,783 | 51.604878 | 174 | py |
DeepRaNE | DeepRaNE-master/precipitation estimation/evaluation.py | from tqdm import tqdm
import torch
from torch.utils.data import random_split, DataLoader
import numpy as np
import os
import pickle
from dataset import RadarAndRainCumulatedDataset
from model import UNetV2
from scipy.stats import linregress
def evaluation(args):
test_dataset = RadarAndRainCumulatedDataset(sampled... | 3,671 | 39.351648 | 209 | py |
DeepRaNE | DeepRaNE-master/precipitation estimation/finetuning.py | from tqdm import tqdm
import torch
from torch.utils.data import random_split, DataLoader
import numpy as np
from dataset import RadarAndRainCumulatedDataset
from model import UNetV2
import time
def train(args):
train_dataset = RadarAndRainCumulatedDataset(sampled_path = args.sampled_path, data_path = args.data_pat... | 5,311 | 45.191304 | 217 | py |
GF_CF | GF_CF-main/Fig1/main.py | import world
import utils
from world import cprint
import torch
import numpy as np
from tensorboardX import SummaryWriter
import time
import Procedure
from os.path import join
# ==============================
utils.set_seed(world.seed)
print(">>SEED:", world.seed)
# ==============================
import register
from r... | 1,654 | 30.826923 | 115 | py |
GF_CF | GF_CF-main/Fig1/Procedure.py | '''
Created on Mar 1, 2020
Pytorch Implementation of LightGCN in
Xiangnan He et al. LightGCN: Simplifying and Powering Graph Convolution Network for Recommendation
@author: Jianbai Ye (gusye@mail.ustc.edu.cn)
Design training and test process
'''
import world
import numpy as np
import torch
import utils
import dataload... | 5,950 | 37.642857 | 113 | py |
GF_CF | GF_CF-main/Fig1/dataloader.py | """
Created on Mar 1, 2020
Pytorch Implementation of LightGCN in
Xiangnan He et al. LightGCN: Simplifying and Powering Graph Convolution Network for Recommendation
@author: Shuxian Bi (stanbi@mail.ustc.edu.cn),Jianbai Ye (gusye@mail.ustc.edu.cn)
Design Dataset here
Every dataset's index has to start at 0
"""
import os... | 13,905 | 32.83455 | 141 | py |
GF_CF | GF_CF-main/Fig1/utils.py | '''
Created on Mar 1, 2020
Pytorch Implementation of LightGCN in
Xiangnan He et al. LightGCN: Simplifying and Powering Graph Convolution Network for Recommendation
@author: Jianbai Ye (gusye@mail.ustc.edu.cn)
'''
import world
import torch
from torch import nn, optim
import numpy as np
from torch import log
from datalo... | 8,395 | 28.77305 | 114 | py |
GF_CF | GF_CF-main/Fig1/model.py | """
Created on Mar 1, 2020
Pytorch Implementation of LightGCN in
Xiangnan He et al. LightGCN: Simplifying and Powering Graph Convolution Network for Recommendation
@author: Jianbai Ye (gusye@mail.ustc.edu.cn)
Define models here
"""
import world
import torch
from dataloader import BasicDataset
from torch import nn
imp... | 8,364 | 37.37156 | 116 | py |
GF_CF | GF_CF-main/Fig1/world.py | '''
Created on Mar 1, 2020
Pytorch Implementation of LightGCN in
Xiangnan He et al. LightGCN: Simplifying and Powering Graph Convolution Network for Recommendation
@author: Jianbai Ye (gusye@mail.ustc.edu.cn)
'''
import os
from os.path import join
import torch
from enum import Enum
from parse import parse_args
import... | 2,343 | 24.758242 | 98 | py |
GF_CF | GF_CF-main/Fig1/parse.py | '''
Created on Mar 1, 2020
Pytorch Implementation of LightGCN in
Xiangnan He et al. LightGCN: Simplifying and Powering Graph Convolution Network for Recommendation
@author: Jianbai Ye (gusye@mail.ustc.edu.cn)
'''
import argparse
def parse_args():
parser = argparse.ArgumentParser(description="Go lightGCN")
pa... | 2,555 | 53.382979 | 113 | py |
GF_CF | GF_CF-main/Table3&4/main.py | import world
import utils
from world import cprint
import torch
import numpy as np
from tensorboardX import SummaryWriter
import time
import Procedure
from os.path import join
# ==============================
utils.set_seed(world.seed)
print(">>SEED:", world.seed)
# ==============================
import register
from r... | 1,832 | 32.327273 | 115 | py |
GF_CF | GF_CF-main/Table3&4/Procedure.py | '''
Created on Mar 1, 2020
Pytorch Implementation of LightGCN in
Xiangnan He et al. LightGCN: Simplifying and Powering Graph Convolution Network for Recommendation
@author: Jianbai Ye (gusye@mail.ustc.edu.cn)
Design training and test process
'''
import world
import numpy as np
import torch
import utils
import dataload... | 6,517 | 38.26506 | 113 | py |
GF_CF | GF_CF-main/Table3&4/dataloader.py | """
Created on Mar 1, 2020
Pytorch Implementation of LightGCN in
Xiangnan He et al. LightGCN: Simplifying and Powering Graph Convolution Network for Recommendation
@author: Shuxian Bi (stanbi@mail.ustc.edu.cn),Jianbai Ye (gusye@mail.ustc.edu.cn)
Design Dataset here
Every dataset's index has to start at 0
"""
import os... | 13,904 | 32.832117 | 141 | py |
GF_CF | GF_CF-main/Table3&4/utils.py | '''
Created on Mar 1, 2020
Pytorch Implementation of LightGCN in
Xiangnan He et al. LightGCN: Simplifying and Powering Graph Convolution Network for Recommendation
@author: Jianbai Ye (gusye@mail.ustc.edu.cn)
'''
import world
import torch
from torch import nn, optim
import numpy as np
from torch import log
from datalo... | 8,395 | 28.77305 | 114 | py |
GF_CF | GF_CF-main/Table3&4/model.py | """
Created on Mar 1, 2020
Pytorch Implementation of LightGCN in
Xiangnan He et al. LightGCN: Simplifying and Powering Graph Convolution Network for Recommendation
@author: Jianbai Ye (gusye@mail.ustc.edu.cn)
Define models here
"""
import world
import torch
import time
from dataloader import BasicDataset
from torch i... | 10,861 | 36.071672 | 116 | py |
GF_CF | GF_CF-main/Table3&4/world.py | '''
Created on Mar 1, 2020
Pytorch Implementation of LightGCN in
Xiangnan He et al. LightGCN: Simplifying and Powering Graph Convolution Network for Recommendation
@author: Jianbai Ye (gusye@mail.ustc.edu.cn)
'''
import os
from os.path import join
import torch
from enum import Enum
from parse import parse_args
import... | 2,393 | 25.021739 | 98 | py |
GF_CF | GF_CF-main/Table3&4/parse.py | '''
Created on Mar 1, 2020
Pytorch Implementation of LightGCN in
Xiangnan He et al. LightGCN: Simplifying and Powering Graph Convolution Network for Recommendation
@author: Jianbai Ye (gusye@mail.ustc.edu.cn)
'''
import argparse
def parse_args():
parser = argparse.ArgumentParser(description="Go lightGCN")
pa... | 2,680 | 54.854167 | 124 | py |
GraphMask | GraphMask-main/code/abstract/abstract_torch_module.py | import torch
import sys
class AbstractTorchModule(torch.nn.Module):
def __init__(self):
torch.nn.Module.__init__(self)
def save(self, path):
print("Saving to path " + path, file=sys.stderr)
torch.save(self.state_dict(), path)
def load(self, path):
print("Loading from pat... | 511 | 22.272727 | 72 | py |
GraphMask | GraphMask-main/code/abstract/abstract_adj_mat_gnn.py | import torch
import numpy as np
class AbstractAdjMatGNN(torch.nn.Module):
injected_message_scale = None
injected_message_replacement = None
latest_adj_mat = None
def __init__(self):
torch.nn.Module.__init__(self)
def get_initial_layer_input(self, vertex_embeddings):
return vertex... | 2,589 | 34.479452 | 124 | py |
GraphMask | GraphMask-main/code/abstract/abstract_gnn.py | import torch
import numpy as np
class AbstractGNN(torch.nn.Module):
injected_message_scale = None
injected_message_replacement = None
def __init__(self):
torch.nn.Module.__init__(self)
def get_initial_layer_input(self, vertex_embeddings):
return vertex_embeddings
def inject_mess... | 2,796 | 37.847222 | 156 | py |
GraphMask | GraphMask-main/code/analysers/erasure_search_analyser.py | import itertools
import numpy as np
import torch
class ErasureSearchAnalyser:
def __init__(self, configuration):
self.configuration = configuration
def initialise_for_model(self, model):
pass
def analyse(self, batch, model, problem, gpu_number=-1):
_, original_predictions = model... | 1,461 | 33.809524 | 116 | py |
GraphMask | GraphMask-main/code/analysers/information_bottleneck/information_bottleneck_analyser.py | import sys
import numpy as np
import torch
from tqdm import tqdm
from code.analysers.graphmask.graphmask_probe import GraphMaskProbe
from code.analysers.information_bottleneck.information_bottleneck_probe import InformationBottleneckProbe
from code.utils.moving_average import MovingAverage
from code.utils.torch_utils... | 10,701 | 45.12931 | 164 | py |
GraphMask | GraphMask-main/code/analysers/information_bottleneck/information_bottleneck_probe.py | import torch
from torch.nn import ReLU, Linear, Sigmoid
from code.abstract.abstract_torch_module import AbstractTorchModule
from code.utils.torch_utils.multiple_inputs_layernorm_linear import MultipleInputsLayernormLinear
from code.utils.torch_utils.squeezer import Squeezer
class InformationBottleneckProbe(AbstractT... | 2,257 | 33.212121 | 103 | py |
GraphMask | GraphMask-main/code/analysers/integrated_gradients/integrated_gradients_analyser.py | import sys
import numpy as np
import torch
from tqdm import tqdm
from code.analysers.graphmask.graphmask_probe import GraphMaskProbe
from code.analysers.graphmask.graphmask_unamortised_probe import GraphMaskUnamortisedProbe
from code.analysers.integrated_gradients.integrated_gradients_probe import IntegratedGradients... | 2,252 | 30.732394 | 122 | py |
GraphMask | GraphMask-main/code/analysers/integrated_gradients/integrated_gradients_probe.py | import torch
from code.abstract.abstract_torch_module import AbstractTorchModule
class IntegratedGradientsProbe(AbstractTorchModule):
def __init__(self, num_edges, num_layers):
AbstractTorchModule.__init__(self)
pseudo_gates = torch.ones((num_layers, num_edges))
self.pseudo_gates = tor... | 427 | 24.176471 | 80 | py |
GraphMask | GraphMask-main/code/analysers/gnnexplainer/gnnexplainer_analyser.py | import sys
import numpy as np
import torch
from tqdm import tqdm
from code.analysers.gnnexplainer.gnnexplainer_probe import GNNExplainerProbe
from code.analysers.graphmask.graphmask_probe import GraphMaskProbe
from code.analysers.graphmask.graphmask_unamortised_probe import GraphMaskUnamortisedProbe
from code.utils.m... | 5,951 | 35.968944 | 116 | py |
GraphMask | GraphMask-main/code/analysers/gnnexplainer/gnnexplainer_probe.py | import math
import torch
from code.abstract.abstract_torch_module import AbstractTorchModule
class GNNExplainerProbe(AbstractTorchModule):
def __init__(self, num_edges, num_layers, init_strategy="normal", const_val=1.0):
super(GNNExplainerProbe, self).__init__()
mask = torch.empty((num_layers,... | 959 | 27.235294 | 85 | py |
GraphMask | GraphMask-main/code/analysers/graphmask/graphmask_probe.py | import math
import sys
import torch
from torch.nn import ReLU, Linear
from code.abstract.abstract_torch_module import AbstractTorchModule
from code.utils.torch_utils.hard_concrete import HardConcrete
from code.utils.torch_utils.multiple_inputs_layernorm_linear import MultipleInputsLayernormLinear
from code.utils.torc... | 2,463 | 31.421053 | 103 | py |
GraphMask | GraphMask-main/code/analysers/graphmask/graphmask_analyser.py | import sys
import numpy as np
import torch
from tqdm import tqdm
from code.analysers.graphmask.graphmask_adj_mat_probe import GraphMaskAdjMatProbe
from code.analysers.graphmask.graphmask_probe import GraphMaskProbe
from code.utils.moving_average import MovingAverage
from code.utils.torch_utils.lagrangian_optimization... | 9,709 | 46.135922 | 138 | py |
GraphMask | GraphMask-main/code/analysers/graphmask/graphmask_unamortised_probe.py | import math
import torch
from code.abstract.abstract_torch_module import AbstractTorchModule
from code.utils.torch_utils.hard_concrete import HardConcrete
class GraphMaskUnamortisedProbe(AbstractTorchModule):
def __init__(self, num_edges, num_layers, m_dim):
AbstractTorchModule.__init__(self)
... | 1,694 | 28.224138 | 85 | py |
GraphMask | GraphMask-main/code/analysers/graphmask/graphmask_adj_mat_probe.py | import math
import sys
import torch
from torch.nn import ReLU, Linear
from code.abstract.abstract_torch_module import AbstractTorchModule
from code.utils.torch_utils.hard_concrete import HardConcrete
from code.utils.torch_utils.multiple_inputs_layernorm_linear import MultipleInputsLayernormLinear
from code.utils.torc... | 2,925 | 31.511111 | 97 | py |
GraphMask | GraphMask-main/code/analysers/graphmask/graphmask_unamortised_analyser.py | import sys
import numpy as np
import torch
from tqdm import tqdm
from code.analysers.graphmask.graphmask_probe import GraphMaskProbe
from code.analysers.graphmask.graphmask_unamortised_probe import GraphMaskUnamortisedProbe
from code.utils.moving_average import MovingAverage
from code.utils.torch_utils.lagrangian_opt... | 6,306 | 38.41875 | 116 | py |
GraphMask | GraphMask-main/code/problems/srl/srl_model.py | from torch.nn import Embedding, CrossEntropyLoss
import torch
from code.abstract.abstract_torch_module import AbstractTorchModule
from code.gnns.srl_gcn import SrlGcn
from code.problems.srl import srl_utils
from code.problems.srl.srl_utils import parse_word_embeddings, constrained_decoder
from code.problems.srl.voc im... | 13,061 | 49.627907 | 131 | py |
GraphMask | GraphMask-main/code/problems/star_graphs/star_graph_model.py | import torch
from torch.nn import Linear, LayerNorm
from code.gnns.rgcn import RGCN
from code.abstract.abstract_torch_module import AbstractTorchModule
from code.utils.evaluation.binary_classification_model_output import BinaryClassificationModelOutput
import numpy as np
class StarGraphModel(AbstractTorchModule):
... | 4,406 | 35.421488 | 131 | py |
GraphMask | GraphMask-main/code/problems/qa/qa_model.py | import scipy
from torch.nn import Dropout, CrossEntropyLoss
from code.abstract.abstract_torch_module import AbstractTorchModule
import torch
import numpy as np
from code.gnns.qa_gnn import QaGNN
from code.utils.evaluation.choice_model_output import ChoiceModelOutput
from code.utils.torch_utils.xavier_linear import Xa... | 10,385 | 45.573991 | 143 | py |
GraphMask | GraphMask-main/code/utils/experiment_utils.py | import os
import sys
import torch
from code.analysers.erasure_search_analyser import ErasureSearchAnalyser
from code.analysers.gnnexplainer.gnnexplainer_analyser import GNNExplainerAnalyser
from code.analysers.graphmask.graphmask_analyser import GraphMaskAnalyser
from code.analysers.graphmask.graphmask_unamortised_ana... | 3,220 | 37.807229 | 138 | py |
GraphMask | GraphMask-main/code/utils/torch_utils/lagrangian_optimization.py | import torch
class LagrangianOptimization:
min_alpha = None
max_alpha = None
device = None
original_optimizer = None
batch_size_multiplier = None
update_counter = 0
def __init__(self, original_optimizer, device, init_alpha=0.55, min_alpha=-2, max_alpha=30, alpha_optimizer_lr=1e-2, batch_... | 2,054 | 33.25 | 149 | py |
GraphMask | GraphMask-main/code/utils/torch_utils/multiple_inputs_layernorm_linear.py | import math
import torch
from torch.nn import Linear, LayerNorm
from torch.nn import Parameter
from torch.nn import init
class MultipleInputsLayernormLinear(torch.nn.Module):
"""
Properly applies layernorm to a list of inputs, allowing for separate rescaling of potentially unnormalized components.
This ... | 2,411 | 32.041096 | 123 | py |
GraphMask | GraphMask-main/code/utils/torch_utils/squeezer.py | import torch
class Squeezer(torch.nn.Module):
def forward(self, x):
return x.squeeze(dim=-1) | 106 | 16.833333 | 32 | py |
GraphMask | GraphMask-main/code/utils/torch_utils/xavier_linear.py | import math
import torch
from torch.nn import Linear
from torch.nn import init
class XavierLinear(torch.nn.Module):
"""
Linear transform initialized with Xavier uniform
"""
def __init__(self, input_dim, output_dim, bias=True):
super(XavierLinear, self).__init__()
self.input_dim = in... | 832 | 24.242424 | 83 | py |
GraphMask | GraphMask-main/code/utils/torch_utils/hard_concrete.py | import torch
from torch.nn.parameter import Parameter
import numpy as np
from torch import sigmoid
class HardConcrete(torch.nn.Module):
def __init__(self, beta=1 / 3, gamma=-0.2, zeta=1.0, fix_temp=True, loc_bias=3):
super(HardConcrete, self).__init__()
self.temp = beta if fix_temp else Parameter... | 1,441 | 30.347826 | 86 | py |
GraphMask | GraphMask-main/code/utils/torch_utils/gnn_utils.py | import torch
def add_backwards_edges(edges,
edge_types,
edge_embeddings=None,
n_relations=None,
separate_relation_types_for_inverse=None):
backward_edges = torch.stack([edges[1], edges[0]], 0)
direction_cutoff = in... | 844 | 32.8 | 75 | py |
GraphMask | GraphMask-main/code/utils/runners/experiment_runner.py | import torch
from tqdm import tqdm
from code.utils.moving_average import MovingAverage
class ExperimentRunner:
moving_average_window_size = 100
def __init__(self, configuration):
self.configuration = configuration
def evaluate_model(self, model, problem, split, gpu_number=-1):
problem.... | 5,304 | 41.782258 | 133 | py |
GraphMask | GraphMask-main/code/utils/runners/analysis_runner.py | import torch
from tqdm import tqdm
import numpy as np
class AnalysisRunner:
def __init__(self, configuration):
self.configuration = configuration
def disable_all_gradients(self, module):
for param in module.parameters():
param.requires_grad = False
def fit_analyser(self, mode... | 2,136 | 35.220339 | 116 | py |
GraphMask | GraphMask-main/code/gnns/qa_gnn.py | import torch
from torch.nn import Linear, ReLU, Sequential, LayerNorm, Sigmoid, Dropout, Module
from code.abstract.abstract_adj_mat_gnn import AbstractAdjMatGNN
from code.utils.torch_utils.xavier_linear import XavierLinear
class QaGnnMessagePasser(Module):
"""
Edge types are few enough that we can afford a f... | 3,719 | 32.818182 | 123 | py |
GraphMask | GraphMask-main/code/gnns/rgcn.py | from torch_geometric.nn import MessagePassing
from torch_geometric.nn.inits import glorot, uniform
import torch
from torch.nn import Linear, ReLU, Sequential, LayerNorm
from torch.nn import Parameter
import numpy as np
from code.abstract.abstract_gnn import AbstractGNN
class RGCNLayer(MessagePassing):
"""
A... | 4,972 | 33.776224 | 141 | py |
GraphMask | GraphMask-main/code/gnns/srl_gcn.py | import torch
from torch.nn import Linear, ReLU, Sigmoid, Tanh, Dropout, LayerNorm, ELU, Embedding
from torch_geometric.nn import MessagePassing
from code.abstract.abstract_gnn import AbstractGNN
class SrlGcnMessagePasser(MessagePassing):
has_hard_gates = False
def __init__(self,
in_dim,
... | 5,546 | 35.254902 | 129 | py |
ResponseEdit | ResponseEdit-master/onlinePreprocess.py | import logging
import torch
import s2s
try:
import ipdb
except ImportError:
pass
lower = True
seq_length = 100
report_every = 100000
shuffle = 1
logger = logging.getLogger(__name__)
def makeVocabulary(filenames, size):
vocab = s2s.Dict([s2s.Constants.PAD_WORD, s2s.Constants.UNK_WORD,
... | 4,427 | 29.328767 | 94 | py |
ResponseEdit | ResponseEdit-master/preprocess.py | import s2s
import argparse
import torch
import ipdb
parser = argparse.ArgumentParser(description='preprocess.py')
##
## **Preprocess Options**
##
parser.add_argument('-config', help="Read options from this file")
parser.add_argument('-train_src', required=True,
help="Path to the training sourc... | 6,195 | 31.610526 | 99 | py |
ResponseEdit | ResponseEdit-master/edit/console_translate.py | from __future__ import division
import sys
sys.path.append(r'../')
from edit.Translator import Translator
import torch
import argparse
import math
import time
import logging
logging.basicConfig(format='%(asctime)s [%(levelname)s:%(name)s]: %(message)s', level=logging.INFO)
file_handler = logging.FileHandler(time.str... | 5,661 | 34.835443 | 108 | py |
ResponseEdit | ResponseEdit-master/edit/onlinePreprocess.py | import logging
import torch
import s2s
try:
import ipdb
except ImportError:
pass
lower = True
seq_length = 50
report_every = 100000
shuffle = 1
logger = logging.getLogger(__name__)
def makeVocabulary(filenames, size):
vocab = s2s.Dict([s2s.Constants.PAD_WORD, s2s.Constants.UNK_WORD,
... | 9,716 | 33.953237 | 114 | py |
ResponseEdit | ResponseEdit-master/edit/Translator.py | import s2s
import torch.nn as nn
import torch
from torch.autograd import Variable
try:
import ipdb
except ImportError:
pass
class Translator(object):
def __init__(self, opt, model=None, dataset=None):
self.opt = opt
if model is None:
checkpoint = torch.load(opt.model,map_loc... | 10,707 | 43.247934 | 128 | py |
ResponseEdit | ResponseEdit-master/edit/translate.py | from __future__ import division
import s2s
import torch
import argparse
import math
import time
import logging
logging.basicConfig(format='%(asctime)s [%(levelname)s:%(name)s]: %(message)s', level=logging.INFO)
file_handler = logging.FileHandler(time.strftime("%Y%m%d-%H%M%S") + '.log.txt', encoding='utf-8')
file_hand... | 5,284 | 34 | 100 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.