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 |
|---|---|---|---|---|---|---|
integral-human-pose | integral-human-pose-master/pytorch_projects/integral_human_pose/test.py | import os
import pprint
import copy
import time
import logging
import torch
from torch.utils.data import DataLoader
# define project dependency
import _init_paths
# project dependence
from common_pytorch.dataset.all_dataset import *
from core.loader import hm36_Dataset, mpii_hm36_Dataset
from common_pytorch.config_p... | 4,598 | 44.534653 | 144 | py |
integral-human-pose | integral-human-pose-master/pytorch_projects/integral_human_pose/_init_paths.py | import os
import sys
def add_path(path):
if path not in sys.path:
sys.path.insert(0, path)
this_dir = os.path.dirname(__file__)
add_path(os.path.join(this_dir, '..', '..', 'common'))
add_path(os.path.join(this_dir, '..', 'common_pytorch'))
add_path(os.path.join(this_dir, '..', '..'))
add_path(os.path.join... | 516 | 26.210526 | 56 | py |
integral-human-pose | integral-human-pose-master/pytorch_projects/integral_human_pose/train.py | import os
import pprint
import copy
import time
import matplotlib
from torch.utils.data import DataLoader
matplotlib.use('Agg')
# define project dependency
import _init_paths
# common
from common.speedometer import Speedometer
from common.utility.logger import create_logger
from common.utility.visualization import p... | 8,382 | 46.361582 | 118 | py |
integral-human-pose | integral-human-pose-master/pytorch_projects/integral_human_pose/core/loader.py | import numpy as np
import torch.utils.data as data
from common.utility.image_processing_cv import get_single_patch_sample
from common_pytorch.dataset.hm36 import from_mpii_to_hm36
class single_patch_Dataset(data.Dataset):
def __init__(self, db, is_train, patch_width, patch_height, rect_3d_width, rect_3d_height... | 5,046 | 37.526718 | 120 | py |
canary-in-a-coalmine | canary-in-a-coalmine-main/randomaug.py | # code in this file is adpated from rpmcruz/autoaugment
# https://github.com/rpmcruz/autoaugment/blob/master/transformations.py
import random
import PIL, PIL.ImageOps, PIL.ImageEnhance, PIL.ImageDraw
import numpy as np
import torch
from PIL import Image
def ShearX(img, v): # [-0.3, 0.3]
assert -0.3 <= v <= 0.3
... | 6,938 | 25.284091 | 134 | py |
canary-in-a-coalmine | canary-in-a-coalmine-main/utils.py | # -*- coding: utf-8 -*-
'''Some helper functions for PyTorch, including:
- get_mean_and_std: calculate the mean and std value of dataset.
- msr_init: net parameter initialization.
- progress_bar: progress bar mimic xlua.progress.
'''
import os
import sys
import time
import random
import numpy as np
import ... | 24,636 | 31.849333 | 126 | py |
canary-in-a-coalmine | canary-in-a-coalmine-main/train.py | # -*- coding: utf-8 -*-
'''
Train CIFAR10 with PyTorch and Vision Transformers!
written by @kentaroy47, @arutema47
'''
from __future__ import print_function
import torch
import torch.nn as nn
import torch.optim as optim
import numpy as np
import torchvision.transforms as transforms
import os
import argparse
impor... | 8,076 | 30.306202 | 139 | py |
canary-in-a-coalmine | canary-in-a-coalmine-main/gen_canary.py | import torch
import torch.nn as nn
import numpy as np
import torchvision.transforms as transforms
import os
import argparse
import copy
import wandb
import random
from pynvml import *
from utils import *
from models.inferencemodel import *
def generate_class_dict(args):
dataset_class_dict = [[] for _ in range(... | 19,123 | 38.924843 | 177 | py |
canary-in-a-coalmine | canary-in-a-coalmine-main/models/swin.py | # https://github.com/berniwal/swin-transformer-pytorch
import torch
from torch import nn, einsum
import numpy as np
from einops import rearrange, repeat
class CyclicShift(nn.Module):
def __init__(self, displacement):
super().__init__()
self.displacement = displacement
def forward(self, x):
... | 10,294 | 41.366255 | 118 | py |
canary-in-a-coalmine | canary-in-a-coalmine-main/models/cait.py | # https://github.com/lucidrains/vit-pytorch/blob/main/vit_pytorch/cait.py
from random import randrange
import torch
from torch import nn, einsum
import torch.nn.functional as F
from einops import rearrange, repeat
from einops.layers.torch import Rearrange
# helpers
def exists(val):
return val is not None
def d... | 5,763 | 31.022222 | 134 | py |
canary-in-a-coalmine | canary-in-a-coalmine-main/models/resnet.py | # -*- coding: utf-8 -*-
'''ResNet in PyTorch.
For Pre-activation ResNet, see 'preact_resnet.py'.
Reference:
[1] Kaiming He, Xiangyu Zhang, Shaoqing Ren, Jian Sun
Deep Residual Learning for Image Recognition. arXiv:1512.03385
'''
import torch
import torch.nn as nn
import torch.nn.functional as F
class BasicBlock(... | 4,358 | 32.274809 | 102 | py |
canary-in-a-coalmine | canary-in-a-coalmine-main/models/vgg.py | # -*- coding: utf-8 -*-
'''VGG11/13/16/19 in Pytorch.'''
import torch
import torch.nn as nn
cfg = {
'VGG11': [64, 'M', 128, 'M', 256, 256, 'M', 512, 512, 'M', 512, 512, 'M'],
'VGG13': [64, 64, 'M', 128, 128, 'M', 256, 256, 'M', 512, 512, 'M', 512, 512, 'M'],
'VGG16': [64, 64, 'M', 128, 128, 'M', 256, 256... | 1,466 | 28.938776 | 117 | py |
canary-in-a-coalmine | canary-in-a-coalmine-main/models/vit_small.py | # https://github.com/lucidrains/vit-pytorch/blob/main/vit_pytorch/vit_for_small_dataset.py
from math import sqrt
import torch
import torch.nn.functional as F
from torch import nn
from einops import rearrange, repeat
from einops.layers.torch import Rearrange
# helpers
def pair(t):
return t if isinstance(t, tuple... | 5,006 | 33.531034 | 166 | py |
canary-in-a-coalmine | canary-in-a-coalmine-main/models/vit.py | # https://github.com/lucidrains/vit-pytorch/blob/main/vit_pytorch/vit.py
import torch
from torch import nn
from einops import rearrange, repeat
from einops.layers.torch import Rearrange
# helpers
def pair(t):
return t if isinstance(t, tuple) else (t, t)
# classes
class PreNorm(nn.Module):
def __init__(sel... | 4,221 | 32.244094 | 166 | py |
canary-in-a-coalmine | canary-in-a-coalmine-main/models/wide_resnet.py | import torch
import torch.nn as nn
import torch.nn.init as init
import torch.nn.functional as F
from torch.autograd import Variable
import sys
import numpy as np
def conv3x3(in_planes, out_planes, stride=1):
return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride, padding=1, bias=True)
def conv_init... | 2,949 | 34.119048 | 98 | py |
canary-in-a-coalmine | canary-in-a-coalmine-main/models/simplevit.py | # from: https://github.com/lucidrains/vit-pytorch/blob/main/vit_pytorch/simple_vit.py
import torch
from torch import nn
from einops import rearrange
from einops.layers.torch import Rearrange
# helpers
def pair(t):
return t if isinstance(t, tuple) else (t, t)
def posemb_sincos_2d(patches, temperature = 10000, d... | 3,932 | 32.05042 | 139 | py |
canary-in-a-coalmine | canary-in-a-coalmine-main/models/mlpmixer.py | # https://github.com/lucidrains/mlp-mixer-pytorch/blob/main/mlp_mixer_pytorch/mlp_mixer_pytorch.py
from torch import nn
from functools import partial
from einops.layers.torch import Rearrange, Reduce
pair = lambda x: x if isinstance(x, tuple) else (x, x)
class PreNormResidual(nn.Module):
def __init__(self, dim, f... | 1,746 | 38.704545 | 141 | py |
canary-in-a-coalmine | canary-in-a-coalmine-main/models/inferencemodel.py | import torch
import os
import torch
import torch.nn as nn
from models import *
from models.vit import ViT
from models.convmixer import ConvMixer
from models.utils import load_model
class InferenceModel(nn.Module):
def __init__(self, shadow_id, args):
super().__init__()
self.shadow_id = shadow_i... | 1,601 | 28.127273 | 114 | py |
canary-in-a-coalmine | canary-in-a-coalmine-main/models/small_cnn.py | import torch
import torch.nn as nn
import torch.nn.functional as F
class SmallNet(nn.Module):
def __init__(self):
super(SmallNet, self).__init__()
self.conv1 = nn.Conv2d(1, 10, kernel_size=5)
self.conv2 = nn.Conv2d(10, 20, kernel_size=5)
self.conv2_drop = nn.Dropout2d()
self... | 679 | 29.909091 | 67 | py |
canary-in-a-coalmine | canary-in-a-coalmine-main/models/convmixer.py | # https://openreview.net/forum?id=TVHS5Y4dNvM
import torch.nn as nn
class Residual(nn.Module):
def __init__(self, fn):
super().__init__()
self.fn = fn
def forward(self, x):
return self.fn(x) + x
def ConvMixer(dim, depth, kernel_size=9, patch_size=7, n_classes=1000):
retur... | 749 | 22.4375 | 71 | py |
long-range-arena | long-range-arena-main/lra_benchmarks/image/train.py | # Copyright 2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, sof... | 14,787 | 35.51358 | 109 | py |
long-range-arena | long-range-arena-main/lra_benchmarks/models/bigbird/bigbird_attention.py | # Copyright 2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, sof... | 27,042 | 39.974242 | 99 | py |
long-range-arena | long-range-arena-main/lra_benchmarks/models/bigbird/bigbird.py | # Copyright 2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, sof... | 12,456 | 32.04244 | 77 | py |
long-range-arena | long-range-arena-main/lra_benchmarks/models/linformer/linformer.py | # Copyright 2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, sof... | 10,386 | 31.974603 | 76 | py |
long-range-arena | long-range-arena-main/lra_benchmarks/models/linformer/linformer_attention.py | # Copyright 2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, sof... | 6,820 | 36.685083 | 83 | py |
long-range-arena | long-range-arena-main/lra_benchmarks/models/longformer/longformer_attention.py | # Copyright 2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, sof... | 10,325 | 34.484536 | 82 | py |
long-range-arena | long-range-arena-main/lra_benchmarks/models/longformer/longformer.py | # Copyright 2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, sof... | 13,113 | 33.151042 | 79 | py |
long-range-arena | long-range-arena-main/lra_benchmarks/models/sinkhorn_transformer/sinkhorn_transformer.py | # Copyright 2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, sof... | 11,993 | 31.950549 | 77 | py |
long-range-arena | long-range-arena-main/lra_benchmarks/models/sinkhorn_transformer/sinkhorn_attention.py | # Copyright 2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, sof... | 19,928 | 38 | 83 | py |
long-range-arena | long-range-arena-main/lra_benchmarks/models/layers/common_layers.py | # Copyright 2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, sof... | 8,415 | 33.633745 | 79 | py |
long-range-arena | long-range-arena-main/lra_benchmarks/models/reformer/reformer.py | # Copyright 2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, sof... | 11,700 | 31.593315 | 77 | py |
long-range-arena | long-range-arena-main/lra_benchmarks/models/reformer/reformer_attention.py | # Copyright 2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, sof... | 12,017 | 34.140351 | 83 | py |
long-range-arena | long-range-arena-main/lra_benchmarks/models/performer/performer_attention.py | # Copyright 2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, sof... | 27,398 | 37.42777 | 141 | py |
long-range-arena | long-range-arena-main/lra_benchmarks/models/performer/performer.py | # Copyright 2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, sof... | 14,003 | 32.990291 | 77 | py |
long-range-arena | long-range-arena-main/lra_benchmarks/models/local/local.py | # Copyright 2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, sof... | 12,118 | 31.842818 | 77 | py |
long-range-arena | long-range-arena-main/lra_benchmarks/models/local/local_attention.py | # Copyright 2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, sof... | 16,358 | 38.136364 | 83 | py |
long-range-arena | long-range-arena-main/lra_benchmarks/models/sparse_transformer/sparse_attention.py | # Copyright 2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, sof... | 8,717 | 31.651685 | 80 | py |
long-range-arena | long-range-arena-main/lra_benchmarks/models/sparse_transformer/sparse_transformer.py | # Copyright 2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, sof... | 13,002 | 32.774026 | 77 | py |
long-range-arena | long-range-arena-main/lra_benchmarks/models/linear_transformer/linear_attention.py | # Copyright 2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, sof... | 7,053 | 34.447236 | 83 | py |
long-range-arena | long-range-arena-main/lra_benchmarks/models/linear_transformer/linear_transformer.py | # Copyright 2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, sof... | 9,616 | 32.392361 | 76 | py |
long-range-arena | long-range-arena-main/lra_benchmarks/models/transformer_tlb/transformer_tlb.py | # Copyright 2022 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, sof... | 14,876 | 34.676259 | 79 | py |
long-range-arena | long-range-arena-main/lra_benchmarks/models/transformer/transformer.py | # Copyright 2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, sof... | 10,250 | 31.961415 | 76 | py |
long-range-arena | long-range-arena-main/lra_benchmarks/models/synthesizer/synthesizer_attention.py | # Copyright 2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, sof... | 18,718 | 39.782135 | 83 | py |
long-range-arena | long-range-arena-main/lra_benchmarks/models/synthesizer/synthesizer.py | # Copyright 2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, sof... | 13,695 | 32.486553 | 77 | py |
long-range-arena | long-range-arena-main/lra_benchmarks/text_classification/train.py | # Copyright 2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, sof... | 11,059 | 34.677419 | 109 | py |
long-range-arena | long-range-arena-main/lra_benchmarks/listops/train.py | # Copyright 2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, sof... | 10,956 | 34.690554 | 109 | py |
long-range-arena | long-range-arena-main/lra_benchmarks/matching/train.py | # Copyright 2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, sof... | 11,787 | 35.382716 | 109 | py |
long-range-arena | long-range-arena-main/lra_benchmarks/utils/data_utils.py | # Copyright 2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, sof... | 11,408 | 35.92233 | 95 | py |
long-range-arena | long-range-arena-main/lra_benchmarks/utils/train_utils.py | # Copyright 2021 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, sof... | 8,064 | 40.358974 | 79 | py |
ACLM | ACLM-main/src/test-dynamic_multilingual-mixup.py | import argparse
import transformers
import torch
parser = argparse.ArgumentParser(allow_abbrev=False)
parser.add_argument('--model', help='which model to use')
parser.add_argument('--input_file','-i', help='input file to use')
parser.add_argument('--sample_generation_mode', help='static/dynamic generation')
parser.add_... | 13,383 | 44.679181 | 274 | py |
ACLM | ACLM-main/src/generate-bert-attn.py | import torch
from transformers import AutoModel,AutoTokenizer
import numpy as np
import re
from tqdm import tqdm
import sys
import random
import argparse
from stopwordsiso import stopwords
import pandas as pd
import os
stopwords_all = stopwords(["bn","de", "es","en","hi","ko","nl","ru","tr","zh"])
parser = argparse... | 11,968 | 24.144958 | 115 | py |
ACLM | ACLM-main/src/flair_train.py | import flair
import torch
import argparse
import os
parser = argparse.ArgumentParser(description='Train flair model')
parser.add_argument('--input_folder', '-i', help='Name of the input folder containing train, dev and test files')
parser.add_argument('--output_folder', '-o', help='Name of the output folder')
parser.a... | 2,797 | 39.550725 | 153 | py |
ACLM | ACLM-main/src/flair_eval_equal.py | import flair
import torch
import argparse
import os
from tqdm import tqdm
# os.environ['CUDA_VISIBLE-DEVICES']="0"
parser = argparse.ArgumentParser(description='Train flair model')
parser.add_argument('--input_folder', '-i', help='Name of the input folder containing train, dev and test files')
parser.add_argument('--o... | 6,072 | 38.180645 | 141 | py |
ACLM | ACLM-main/src/test-dynamic_multilingual.py | import argparse
import transformers
import torch
parser = argparse.ArgumentParser(allow_abbrev=False)
parser.add_argument('--model', help='which model to use')
parser.add_argument('--input_file','-i', help='input file to use')
parser.add_argument('--sample_generation_mode', help='static/dynamic generation')
parser.add_... | 9,965 | 45.570093 | 274 | py |
ACLM | ACLM-main/src/flair_infer.py | import flair
import torch
import argparse
import os
from tqdm import tqdm
os.environ['CUDA_VISIBLE_DEVICES']="0"
parser = argparse.ArgumentParser(description='Train flair model')
parser.add_argument('--input_folder', '-i', help='Name of the input folder containing train, dev and test files')
parser.add_argument('--out... | 2,087 | 35.631579 | 145 | py |
ACLM | ACLM-main/src/bart_pretrain_dynamic_multilingual.py | import numpy as np
import shutil
import nltk
import copy
nltk.download('stopwords')
nltk.download('punkt')
from nltk.tokenize import sent_tokenize
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
from transformers import Seq2SeqTrainingArguments, Seq2SeqTrainer, PreTrainedTokenizerBase
from datasets import... | 14,880 | 44.368902 | 153 | py |
HGB | HGB-master/TC/HGAT/model/code/base.py | from __future__ import division
from __future__ import print_function
import time
import argparse
from networkx.algorithms.centrality import trophic
from networkx.algorithms.cuts import edge_expansion
import numpy as np
import pickle as pkl
from copy import deepcopy
from random import shuffle
import torch
import torc... | 14,413 | 33.483254 | 106 | py |
HGB | HGB-master/TC/HGAT/model/code/utils.py | import numpy as np
import scipy.sparse as sp
from random import shuffle
import torch
from tqdm import tqdm
import os
def load_data(path="../data/citeseer/", dataset="citeseer"):
print('Loading {} dataset...'.format(dataset))
features_block = False # concatenate the feature spaces or not
MULTI_LABEL ... | 9,806 | 37.916667 | 103 | py |
HGB | HGB-master/TC/HGAT/model/code/layers.py | import math
import torch
from torch.nn.parameter import Parameter
from torch.nn.modules.module import Module
import torch.nn.functional as F
from torch import nn
class MyGraphConvolution(Module):
def __init__(self, in_features, out_features, bias=True):
super(MyGraphConvolution, self).__init__()
s... | 8,207 | 35.48 | 95 | py |
HGB | HGB-master/TC/HGAT/model/code/models.py | import math
import torch
import torch.nn as nn
import torch.nn.functional as F
from layers import *
from torch.nn.parameter import Parameter
from dgl.nn.pytorch import GraphConv, GATConv
from functools import reduce
from utils import dense_tensor_to_sparse
class weighted_GCN(nn.Module):
def __init__(self,
... | 8,431 | 32.593625 | 139 | py |
HGB | HGB-master/TC/HGAT/model/code/train.py | from __future__ import division
from __future__ import print_function
import time
import argparse
from networkx.algorithms.centrality import trophic
from networkx.algorithms.cuts import edge_expansion
import numpy as np
import pickle as pkl
from copy import deepcopy
from random import shuffle
import torch
import torc... | 16,760 | 36.329621 | 106 | py |
HGB | HGB-master/TC/HGAT/model/code/baseline/new_main.py | """
define model
"""
weight_size = eval(args.layer_size)
num_layers = len(weight_size) - 2
heads = [args.heads] * num_layers + [1]
model = myGAT(config['n_users']+config['n_entities'], args.kge_size, config['n_relations']*2+1, args.embed_size, weight_size[-2], weight_size[-1], num_layers, heads, F.elu, 0.1, 0., 0.05, F... | 1,463 | 29.5 | 236 | py |
HGB | HGB-master/TC/HGAT/model/code/baseline/GNN.py | import torch
import torch.nn as nn
import dgl
from dgl.nn.pytorch import GraphConv
import dgl.function as fn
from dgl.nn.pytorch import edge_softmax, GATConv
from .conv import myGATConv
class myGAT(nn.Module):
def __init__(self,
g,
edge_dim,
num_etypes,
... | 8,533 | 38.509259 | 169 | py |
HGB | HGB-master/TC/HGAT/model/code/baseline/run.py | import sys
sys.path.append('../../')
import time
import argparse
import torch
import torch.nn.functional as F
import numpy as np
from utils.pytorchtools import EarlyStopping
from utils.data import load_data
from GNN import GCN, GAT, RGAT
import dgl
def sp_to_spt(mat):
coo = mat.tocoo()
values = coo.data
... | 6,969 | 40.736527 | 158 | py |
HGB | HGB-master/TC/HGAT/model/code/baseline/conv.py | """Torch modules for graph attention networks(GAT)."""
# pylint: disable= no-member, arguments-differ, invalid-name
import torch as th
from torch import nn
from dgl import function as fn
from dgl.nn.pytorch import edge_softmax
from dgl._ffi.base import DGLError
from dgl.nn.pytorch.utils import Identity
from dgl.utils ... | 6,886 | 45.85034 | 140 | py |
HGB | HGB-master/TC/HGAT/model/code/baseline/run_multi.py | import sys
sys.path.append('../../')
import time
import argparse
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
from utils.pytorchtools import EarlyStopping
from utils.data import load_data
#from utils.tools import index_generator, evaluate_results_nc, parse_minibatch
from GNN i... | 7,459 | 40.675978 | 187 | py |
HGB | HGB-master/TC/HGAT/model/code/baseline/run_new.py | import sys
sys.path.append('../../')
import time
import argparse
import torch
import torch.nn.functional as F
import numpy as np
from utils.pytorchtools import EarlyStopping
from utils.data import load_data
#from utils.tools import index_generator, evaluate_results_nc, parse_minibatch
from GNN import myGAT
import dgl... | 7,732 | 41.027174 | 189 | py |
HGB | HGB-master/TC/HGAT/model/code/baseline/utils/pytorchtools.py | import numpy as np
import torch
class EarlyStopping:
"""Early stops the training if validation loss doesn't improve after a given patience."""
def __init__(self, patience, verbose=False, delta=0, save_path='checkpoint.pt'):
"""
Args:
patience (int): How long to wait after last time... | 1,824 | 36.244898 | 111 | py |
HGB | HGB-master/TC/HGAT/model/code/baseline/utils/tools.py | import torch
import dgl
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.metrics import f1_score, normalized_mutual_info_score, adjusted_rand_score
from sklearn.cluster import KMeans
from sklearn.svm import LinearSVC
def idx_to_one_hot(idx_arr):
one_hot = np.zeros((idx_arr.shap... | 11,404 | 46.128099 | 174 | py |
HGB | HGB-master/LP/MAGNN/run_LastFM_GNN.py | import time
import argparse
import torch
import torch.nn.functional as F
import numpy as np
from sklearn.metrics import roc_auc_score, average_precision_score
from utils.pytorchtools import EarlyStopping
from utils.data import load_LastFM_data
from utils.tools import index_generator, parse_minibatch_LastFM
from scipy... | 16,755 | 56.187713 | 175 | py |
HGB | HGB-master/LP/MAGNN/GNN.py | import torch
import torch.nn as nn
import dgl
from dgl.nn.pytorch import GraphConv
import dgl.function as fn
from dgl.nn.pytorch import edge_softmax, GATConv
class GAT(nn.Module):
def __init__(self,
g,
num_layers,
in_dim,
num_hidden,
... | 4,437 | 30.475177 | 115 | py |
HGB | HGB-master/LP/MAGNN/run_LastFM.py | import time
import argparse
import torch
import torch.nn.functional as F
import numpy as np
from sklearn.metrics import roc_auc_score, average_precision_score
from utils.pytorchtools import EarlyStopping
from utils.data import load_LastFM_data
from utils.tools import index_generator, parse_minibatch_LastFM
from model... | 13,623 | 57.724138 | 175 | py |
HGB | HGB-master/LP/MAGNN/utils/pytorchtools.py | import numpy as np
import torch
class EarlyStopping:
"""Early stops the training if validation loss doesn't improve after a given patience."""
def __init__(self, patience, verbose=False, delta=0, save_path='checkpoint.pt'):
"""
Args:
patience (int): How long to wait after last time... | 1,824 | 36.244898 | 111 | py |
HGB | HGB-master/LP/MAGNN/utils/tools.py | import torch
import dgl
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.metrics import f1_score, normalized_mutual_info_score, adjusted_rand_score
from sklearn.cluster import KMeans
from sklearn.svm import LinearSVC
def idx_to_one_hot(idx_arr):
one_hot = np.zeros((idx_arr.shap... | 11,431 | 46.045267 | 174 | py |
HGB | HGB-master/LP/MAGNN/model/MAGNN_lp.py | import torch
import torch.nn as nn
import numpy as np
from model.base_MAGNN import MAGNN_ctr_ntype_specific
# for link prediction task
class MAGNN_lp_layer(nn.Module):
def __init__(self,
num_metapaths_list,
num_edge_type,
etypes_lists,
in_dim,
... | 5,609 | 41.824427 | 115 | py |
HGB | HGB-master/LP/MAGNN/model/MAGNN_nc_mb.py | import torch
import torch.nn as nn
import numpy as np
from model.base_MAGNN import MAGNN_ctr_ntype_specific
# support for mini-batched forward
# only support one layer for one ctr_ntype
class MAGNN_nc_mb_layer(nn.Module):
def __init__(self,
num_metapaths,
num_edge_type,
... | 4,483 | 38.333333 | 119 | py |
HGB | HGB-master/LP/MAGNN/model/MAGNN_nc.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
from model.base_MAGNN import MAGNN_ctr_ntype_specific
fc_switch = False
# multi-layer support
class MAGNN_nc_layer(nn.Module):
def __init__(self,
num_metapaths_list,
num_edge_type,
... | 5,888 | 41.985401 | 148 | py |
HGB | HGB-master/LP/MAGNN/model/base_MAGNN.py | import torch
import torch.nn as nn
import torch.nn.functional as F
import dgl.function as fn
from dgl.nn.pytorch import edge_softmax
class MAGNN_metapath_specific(nn.Module):
def __init__(self,
etypes,
out_dim,
num_heads,
rnn_type='gru',
... | 11,914 | 46.66 | 168 | py |
HGB | HGB-master/LP/RGCN-WN18/code/gnn_link_predict.py | import dgl
from model import GCN, GAT
from utils import load_data
from utils import EarlyStopping
import utils
import numpy as np
import torch.nn as nn
import torch
from collections import defaultdict
import argparse
import time
import sys
sys.path.append('../../')
def sp_to_spt(mat):
coo = mat.tocoo()
value... | 13,790 | 43.201923 | 134 | py |
HGB | HGB-master/LP/RGCN-WN18/code/utils.py | from sklearn.metrics import (
auc, f1_score, precision_recall_curve, roc_auc_score)
import scipy.sparse as sp
from torch.utils.data import Dataset
import torch as th
import numpy as np
class EarlyStopping:
"""Early stops the training if validation loss doesn't improve after a given patience."""
def __ini... | 3,241 | 29.584906 | 111 | py |
HGB | HGB-master/LP/RGCN-WN18/code/model.py | import torch as th
import torch.nn as nn
from dgl.nn.pytorch import GraphConv, GATConv, RelGraphConv
import torch.nn.functional as F
class BaseRGCN(nn.Module):
def __init__(self, in_dims, h_dim, out_dim, num_rels, num_bases,
num_hidden_layers=1, dropout=0,
use_self_loop=False):
... | 7,207 | 33.990291 | 106 | py |
HGB | HGB-master/LP/RGCN-WN18/code/link_predict.py | import dgl
from model import BaseRGCN
from utils import load_data
from utils import EarlyStopping
import utils
import numpy as np
import torch.nn.functional as F
import torch.nn as nn
import torch
from collections import defaultdict
import argparse
import time
import sys
from dgl.nn.pytorch import RelGraphConv
sys.pat... | 15,840 | 42.639118 | 125 | py |
HGB | HGB-master/LP/RGCN/gnn_link_predict.py | """
Modeling Relational Data with Graph Convolutional Networks
Paper: https://arxiv.org/abs/1703.06103
Code: https://github.com/MichSchli/RelationPrediction
Difference compared to MichSchli/RelationPrediction
* Report raw metrics instead of filtered metrics.
* By default, we use uniform edge sampling instead of neighbo... | 9,318 | 40.052863 | 109 | py |
HGB | HGB-master/LP/RGCN/utils.py | """
Utility functions for link prediction
Most code is adapted from authors' implementation of RGCN link prediction:
https://github.com/MichSchli/RelationPrediction
"""
import traceback
from _thread import start_new_thread
from functools import wraps
import numpy as np
import torch
from torch.multiprocessing import Qu... | 14,937 | 36.066998 | 115 | py |
HGB | HGB-master/LP/RGCN/model.py | import torch as th
from torch._C import Graph
import torch.nn as nn
import torch as th
from torch import nn
import torch.nn.functional as F
from dgl.nn.pytorch import GATConv, GraphConv
from torch.nn.modules import activation
class DisMult(th.nn.Module):
def __init__(self, rel_num, dim):
super(DisMult, se... | 7,901 | 33.50655 | 91 | py |
HGB | HGB-master/LP/RGCN/GNN.py | import torch as th
from torch import nn
from torch_geometric.nn import GCNConv, GATConv
import torch.nn.functional as F
class DisMult(th.nn.Module):
def __init__(self, rel_num, dim):
super(DisMult, self).__init__()
self.dim = dim
self.weights = nn.Parameter(th.FloatTensor(size=(rel_num, dim,... | 5,087 | 35.604317 | 108 | py |
HGB | HGB-master/LP/RGCN/HomGNN.py | """
Modeling Relational Data with Graph Convolutional Networks
Paper: https://arxiv.org/abs/1703.06103
Code: https://github.com/MichSchli/RelationPrediction
Difference compared to MichSchli/RelationPrediction
* Report raw metrics instead of filtered metrics.
* By default, we use uniform edge sampling instead of neighbo... | 11,245 | 41.760456 | 139 | py |
HGB | HGB-master/LP/RGCN/link_predict.py | """
Modeling Relational Data with Graph Convolutional Networks
Paper: https://arxiv.org/abs/1703.06103
Code: https://github.com/MichSchli/RelationPrediction
Difference compared to MichSchli/RelationPrediction
* Report raw metrics instead of filtered metrics.
* By default, we use uniform edge sampling instead of neighbo... | 10,651 | 38.895131 | 103 | py |
HGB | HGB-master/LP/HetGNN/code/tools.py | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
from args import read_args
import numpy as np
import string
import re
import math
args = read_args()
class HetAgg(nn.Module):
def __init__(self, args, feature_list, a_neigh_list_train, p_neigh_list_train, v_neigh_l... | 13,023 | 37.877612 | 114 | py |
HGB | HGB-master/LP/HetGNN/code/HetGNN.py | import torch
import torch.optim as optim
import data_generator
import tools
from args import read_args
from torch.autograd import Variable
import numpy as np
import random
torch.set_num_threads(2)
import os
os.environ['CUDA_VISIBLE_DEVICES']='0'
class model_class(object):
def __init__(self, args):
super(model_clas... | 4,017 | 30.147287 | 108 | py |
HGB | HGB-master/LP/HetGNN/code/homoGNN.py | import numpy as np
import torch as th
from torch_geometric.data import Data
from torch import nn
from torch_geometric.nn import GCNConv, SAGEConv, TopKPooling, GATConv
import torch.nn.functional as F
import re
import random
import csv
import argparse
import datetime
from sklearn.metrics import f1_score, roc_auc_score
i... | 23,981 | 39.924915 | 160 | py |
HGB | HGB-master/LP/benchmark/methods/baseline/GNN.py | import torch
import torch.nn as nn
import dgl
from dgl.nn.pytorch import GraphConv
import dgl.function as fn
from dgl.nn.pytorch import edge_softmax, GATConv
from conv import myGATConv
class DistMult(nn.Module):
def __init__(self, num_rel, dim):
super(DistMult, self).__init__()
self.W = nn.Paramet... | 3,946 | 38.47 | 169 | py |
HGB | HGB-master/LP/benchmark/methods/baseline/conv.py | """Torch modules for graph attention networks(GAT)."""
# pylint: disable= no-member, arguments-differ, invalid-name
import torch as th
from torch import nn
from dgl import function as fn
from dgl.nn.pytorch import edge_softmax
from dgl._ffi.base import DGLError
from dgl.nn.pytorch.utils import Identity
from dgl.utils ... | 6,486 | 44.363636 | 92 | py |
HGB | HGB-master/LP/benchmark/methods/baseline/run_dist.py | import sys
sys.path.append('../../')
import time
import argparse
import os
from collections import defaultdict
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
from utils.pytorchtools import EarlyStopping
from utils.data import load_data
from GNN import myGAT
import dgl
import os
... | 13,302 | 47.199275 | 209 | py |
HGB | HGB-master/LP/benchmark/methods/baseline/run_new.py | import sys
sys.path.append('../../')
import time
import argparse
import os
from collections import defaultdict
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
from utils.pytorchtools import EarlyStopping
from utils.data import load_data
from GNN import myGAT
import dgl
import os
... | 12,386 | 45.743396 | 232 | py |
HGB | HGB-master/LP/benchmark/methods/baseline/utils/pytorchtools.py | import numpy as np
import torch
class EarlyStopping:
"""Early stops the training if validation loss doesn't improve after a given patience."""
def __init__(self, patience, verbose=False, delta=0, save_path='checkpoint.pt'):
"""
Args:
patience (int): How long to wait after last time... | 1,824 | 36.244898 | 111 | py |
HGB | HGB-master/LP/benchmark/methods/baseline/utils/tools.py | import torch
import dgl
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.metrics import f1_score, normalized_mutual_info_score, adjusted_rand_score
from sklearn.cluster import KMeans
from sklearn.svm import LinearSVC
def idx_to_one_hot(idx_arr):
one_hot = np.zeros((idx_arr.shap... | 11,404 | 46.128099 | 174 | py |
HGB | HGB-master/LP/benchmark/methods/MAGNN/run_DBLP.py | import time
import argparse
import torch
import torch.nn.functional as F
import numpy as np
from utils.pytorchtools import EarlyStopping
from utils.data import load_DBLP_data
from utils.tools import index_generator, evaluate_results_nc, parse_minibatch
from model import MAGNN_nc_mb
# Params
out_dim = 4
dropout_rate ... | 10,569 | 50.813725 | 139 | py |
HGB | HGB-master/LP/benchmark/methods/MAGNN/run_IMDB.py | import time
import argparse
import torch.nn.functional as F
import torch.sparse
import numpy as np
import dgl
from utils.pytorchtools import EarlyStopping
from utils.data import load_IMDB_data
from utils.tools import evaluate_results_nc
from model import MAGNN_nc
# Params
out_dim = 3
dropout_rate = 0.5
lr = 0.005
we... | 8,734 | 47.259669 | 133 | py |
HGB | HGB-master/LP/benchmark/methods/MAGNN/run_LastFM.py | import sys
sys.path.append('../../')
import time
import argparse
import torch
import torch.nn.functional as F
import numpy as np
from sklearn.metrics import roc_auc_score, average_precision_score
from utils.pytorchtools import EarlyStopping
from utils.data import load_LastFM_data
from utils.tools import index_generat... | 13,941 | 56.374486 | 140 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.