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
DB
DB-master/training/optimizer_scheduler.py
import torch from concern.config import Configurable, State class OptimizerScheduler(Configurable): optimizer = State() optimizer_args = State(default={}) learning_rate = State(autoload=False) def __init__(self, cmd={}, **kwargs): self.load_all(**kwargs) self.load('learning_rate', cm...
691
29.086957
57
py
DB
DB-master/training/model_saver.py
import os import torch from concern.config import Configurable, State from concern.signal_monitor import SignalMonitor class ModelSaver(Configurable): dir_path = State() save_interval = State(default=1000) signal_path = State() def __init__(self, **kwargs): self.load_all(**kwargs) ...
1,525
32.911111
83
py
DB
DB-master/training/learning_rate.py
from bisect import bisect_right import numpy as np import torch.optim.lr_scheduler as lr_scheduler from concern.config import Configurable, State from concern.signal_monitor import SignalMonitor class ConstantLearningRate(Configurable): lr = State(default=0.0001) def __init__(self, **kwargs): self.l...
3,561
27.496
75
py
DB
DB-master/structure/model.py
import os import torch import torch.nn as nn import torch.nn.functional as F import backbones import decoders class BasicModel(nn.Module): def __init__(self, args): nn.Module.__init__(self) self.backbone = getattr(backbones, args['backbone'])(**args.get('backbone_args', {})) self.decode...
2,251
33.121212
98
py
DB
DB-master/structure/builder.py
from collections import OrderedDict import torch import structure.model from concern.config import Configurable, State class Builder(Configurable): model = State() model_args = State() def __init__(self, cmd={}, **kwargs): self.load_all(**kwargs) if 'backbone' in cmd: self.m...
761
26.214286
98
py
DB
DB-master/structure/visualizers/seg_detector_visualizer.py
import cv2 import concern.webcv2 as webcv2 import numpy as np import torch from concern.config import Configurable, State from data.processes.make_icdar_data import MakeICDARData class SegDetectorVisualizer(Configurable): vis_num = State(default=4) eager_show = State(default=False) def __init__(self, **...
4,177
38.790476
99
py
DB
DB-master/concern/visualizer.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # File : visualizer.py # Author : Zhaoyi Wan <wanzhaoyi@megvii.com> # Date : 08.01.2019 # Last Modified Date: 02.12.2019 # Last Modified By : Minghui Liao import torch import numpy as np import cv2 class Visualize: @classmethod ...
3,623
35.606061
153
py
DB
DB-master/decoders/dice_loss.py
import torch import torch.nn as nn import numpy as np import cv2 from scipy import ndimage class DiceLoss(nn.Module): ''' Loss function from https://arxiv.org/abs/1707.03237, where iou computation is introduced heatmap manner to measure the diversity bwtween tow heatmaps. ''' def __init__(self...
6,965
36.251337
114
py
DB
DB-master/decoders/seg_detector_loss.py
import sys import torch import torch.nn as nn class SegDetectorLossBuilder(): ''' Build loss functions for SegDetector. Details about the built functions: Input: pred: A dict which contains predictions. thresh: The threshold prediction binary: The text ...
9,529
34.962264
104
py
DB
DB-master/decoders/l1_loss.py
import torch import torch.nn as nn class MaskL1Loss(nn.Module): def __init__(self): super(MaskL1Loss, self).__init__() def forward(self, pred: torch.Tensor, gt, mask): mask_sum = mask.sum() if mask_sum.item() == 0: return mask_sum, dict(l1_loss=mask_sum) else: ...
1,363
31.47619
72
py
DB
DB-master/decoders/balance_cross_entropy_loss.py
import torch import torch.nn as nn class BalanceCrossEntropyLoss(nn.Module): ''' Balanced cross entropy loss. Shape: - Input: :math:`(N, 1, H, W)` - GT: :math:`(N, 1, H, W)`, same shape as the input - Mask: :math:`(N, H, W)`, same spatial shape as the input - Output: scalar...
1,954
33.298246
78
py
DB
DB-master/decoders/simple_detection.py
import torch import torch.nn as nn import torch.nn.functional as F from backbones.upsample_head import SimpleUpsampleHead class SimpleDetectionDecoder(nn.Module): def __init__(self, feature_channel=256): nn.Module.__init__(self) self.feature_channel = feature_channel self.head_layer = s...
6,383
32.25
107
py
DB
DB-master/decoders/feature_attention.py
import torch import torch.nn as nn import torch.nn.functional as F class ScaleChannelAttention(nn.Module): def __init__(self, in_planes, out_planes, num_features, init_weight=True): super(ScaleChannelAttention, self).__init__() self.avgpool = nn.AdaptiveAvgPool2d(1) print(self.avgpool) ...
5,925
39.868966
121
py
DB
DB-master/decoders/seg_detector.py
from collections import OrderedDict import torch import torch.nn as nn BatchNorm2d = nn.BatchNorm2d class SegDetector(nn.Module): def __init__(self, in_channels=[64, 128, 256, 512], inner_channels=256, k=10, bias=False, adaptive=False, smooth=False, serial=False,...
6,112
38.954248
98
py
DB
DB-master/decoders/pss_loss.py
import torch import torch.nn as nn import torch.nn.functional as F class PSS_Loss(nn.Module): def __init__(self, cls_loss): super(PSS_Loss, self).__init__() self.eps = 1e-6 self.criterion = eval('self.' + cls_loss + '_loss') def dice_loss(self, pred, gt, m): intersection = tor...
4,467
37.517241
84
py
DB
DB-master/decoders/seg_detector_asf.py
from collections import OrderedDict import pdb import torch import torch.nn as nn from .feature_attention import ScaleFeatureSelection BatchNorm2d = nn.BatchNorm2d class SegSpatialScaleDetector(nn.Module): def __init__(self, in_channels=[64, 128, 256, 512], inner_channels=256, k=...
7,048
42.245399
123
py
DB
DB-master/data/quad.py
import torch import numpy as np class Quad: def __init__(self, points, format='NP2'): self._rect = None self.tensorized = False self._points = None self.set_points(points, format) @property def points(self): return self._points def set_points(self, new_points,...
2,539
28.195402
73
py
DB
DB-master/data/data_loader.py
import math import bisect import imgaug import numpy as np import torch import torch.distributed as dist from torch.utils.data import Sampler, ConcatDataset, BatchSampler from concern.config import Configurable, State def default_worker_init_fn(worker_id): np.random.seed(worker_id) imgaug.seed(worker_id) ...
8,321
32.155378
98
py
DB
DB-master/data/simple_detection.py
import pickle import cv2 import skimage import numpy as np from shapely.geometry import Polygon from concern.config import Configurable, State def binary_search_smallest_width(poly): if len(poly) < 3: return 0 poly = Polygon(poly) low = 0 high = 65536 while high - low > 0.1: mid ...
9,427
34.443609
120
py
DB
DB-master/data/image_dataset.py
import functools import logging import bisect import torch.utils.data as data import cv2 import numpy as np import glob from concern.config import Configurable, State import math class ImageDataset(data.Dataset, Configurable): r'''Dataset reading from images. Args: Processes: A series of Callable obje...
3,935
37.970297
122
py
DB
DB-master/data/dataset.py
from torch.utils.data import Dataset as TorchDataset from concern.config import Configurable, State class SliceDataset(TorchDataset, Configurable): dataset = State() start = State() end = State() def __init__(self, **kwargs): self.load_all(**kwargs) if self.start is None: ...
547
21.833333
52
py
DB
DB-master/data/transform_data.py
import numpy as np import torch from concern.config import Configurable class TransformData(Configurable): ''' this transformation is inplcae, which means that the input will be modified. ''' mean = np.array([0.485, 0.456, 0.406]) std = np.array([0.229, 0.224, 0.225]) def __init__(se...
641
25.75
76
py
DB
DB-master/data/processes/normalize_image.py
import numpy as np import torch from .data_process import DataProcess class NormalizeImage(DataProcess): RGB_MEAN = np.array([122.67891434, 116.66876762, 104.00698793]) def process(self, data): assert 'image' in data, '`image` in data is required by this process' image = data['image'] ...
707
26.230769
77
py
DB
DB-master/data/processes/make_icdar_data.py
from collections import OrderedDict import torch import numpy as np from concern.config import Configurable, State from .data_process import DataProcess import cv2 class MakeICDARData(DataProcess): shrink_ratio = State(default=0.4) def __init__(self, debug=False, cmd={}, **kwargs): self.load_all(**...
2,284
31.642857
72
py
DB
DB-master/backbones/resnet.py
import torch.nn as nn import math import torch.utils.model_zoo as model_zoo BatchNorm2d = nn.BatchNorm2d __all__ = ['ResNet', 'resnet18', 'resnet34', 'resnet50', 'resnet101', 'resnet152'] model_urls = { 'resnet18': 'https://download.pytorch.org/models/resnet18-5c106cde.pth', 'resnet34': 'https://d...
11,842
34.142433
82
py
DB
DB-master/backbones/mobilenetv3.py
# https://github.com/kuan-wang/pytorch-mobilenet-v3 import torch import torch.nn as nn import torch.nn.functional as F __all__ = ['MobileNetV3', 'mobilenetv3'] def conv_bn(inp, oup, stride, conv_layer=nn.Conv2d, norm_layer=nn.BatchNorm2d, nlin_layer=nn.ReLU): return nn.Sequential( conv_layer(inp, oup, 3...
8,930
34.300395
198
py
MultiScanner_SCC
MultiScanner_SCC-main/inference.py
from slide.slide_helper import * from slide.process_slides import * import hydra from omegaconf import DictConfig from torchvision import models from torchvision import transforms from einops import rearrange from torchmetrics import ConfusionMatrix import os from fastai.vision import * def stitch_output_mask(filenam...
4,863
48.131313
177
py
MultiScanner_SCC
MultiScanner_SCC-main/training.py
from slide.process_slides import * import hydra from omegaconf import DictConfig from torchvision import models from utils.combo_loss import ComboLoss from utils.callbacks import ResetDataloaders, IoU, LossComponents from slide.slide_helper import * def random_seed(seed_value, use_cuda): ''' Sets the random seed ...
2,681
40.90625
206
py
MultiScanner_SCC
MultiScanner_SCC-main/slide/slide_helper.py
from fastai.vision.all import * from matplotlib import cm from matplotlib.colors import ListedColormap from einops import rearrange, reduce, repeat from collections import defaultdict COLORS = np.array([[128, 128, 128], # Excluded [255, 255, 255], # BG [0, 0, 255], # Normal [255, 128, ...
2,972
48.55
161
py
MultiScanner_SCC
MultiScanner_SCC-main/utils/callbacks.py
import torch from fastai.metrics import Metric, AvgMetric from fastai.callback.core import Callback from slide.slide_helper import generate_dataloaders from torchmetrics import JaccardIndex class IoU(AvgMetric): def __init__(self): super().__init__(func=JaccardIndex(num_classes=4, ignore_index=0)) ...
1,725
34.22449
129
py
MultiScanner_SCC
MultiScanner_SCC-main/utils/combo_loss.py
import torch from torch import nn import torch.nn.functional as F class CELoss(nn.modules.loss._WeightedLoss): def __init__(self, weight=None, gamma=2,reduction='mean', ignore_index=-1): super(CELoss, self).__init__(weight,reduction=reduction) self.gamma = gamma self.ignore_index = ignore_...
3,008
36.6125
118
py
ELLE
ELLE-main/fairseq-0.9.0/setup.py
#!/usr/bin/env python3 # 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 from setuptools import setup, find_packages, Extension import sys if sys.version_info < (3, 5): sys.exi...
4,357
25.736196
92
py
ELLE
ELLE-main/fairseq-0.9.0/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 torch from fairseq import bleu, checkpoint_utils,...
8,179
39.098039
110
py
ELLE
ELLE-main/fairseq-0.9.0/hubconf.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 functools from fairseq.hub_utils import BPEHubInterface as bpe # noqa from fairseq.hub_utils import TokenizerHubInterface as tokenize...
1,432
28.244898
78
py
ELLE
ELLE-main/fairseq-0.9.0/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 torch from fairseq import checkpoint_utils, options, progress_bar, utils def mai...
3,163
30.64
88
py
ELLE
ELLE-main/fairseq-0.9.0/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 numpy as np import torch from fairseq import c...
8,132
34.671053
118
py
ELLE
ELLE-main/fairseq-0.9.0/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 ...
6,445
32.05641
103
py
ELLE
ELLE-main/fairseq-0.9.0/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 collections import math import random import numpy...
12,771
36.786982
92
py
ELLE
ELLE-main/fairseq-0.9.0/examples/roberta/double_height_width_stack_addnoise.py
import collections import sys import torch.nn as nn import torch import math def main(): ckpt = torch.load(sys.argv[1]) whether_stack = False enlarge_n_times = 2 emb_num = ckpt['model']['decoder.sentence_encoder.embed_tokens.weight'].size()[0] height = 6 width = ckpt['model']['decoder.sentence...
10,292
52.056701
147
py
ELLE
ELLE-main/fairseq-0.9.0/examples/roberta/bert2BERT_FPI_new.py
""" preprocessing script before training distillBert specific to bert->distillbert """ import argparse import os import math from typing import NewType, NoReturn import torch import numpy as np from transformer.modeling import BertForPreTraining def wider3d(w,dim,new_width,choices,div=False): old_width = w.size(dim)...
11,647
37.190164
136
py
ELLE
ELLE-main/fairseq-0.9.0/examples/roberta/double_enlarge_general.py
import collections import sys import torch.nn as nn import torch import math def main(): print(sys.argv[1]) ckpt = torch.load(sys.argv[1]) width_enlarge = True layer_enlarge = True enlarge_layer_num = 6 enlarge_dim = 384 attention_head = 12 emb_num = ckpt['model']['decoder.sentence_enco...
10,371
55.369565
272
py
ELLE
ELLE-main/fairseq-0.9.0/examples/roberta/bert2BERT_AKI_new.py
""" preprocessing script before training distillBert specific to bert->distillbert """ ''' sm path: dir contain pytorch_model.bin, config.json, vocab.txt of small model bm path: config.json, vocab.txt of big model -'is_always_left': Taking the parameters of all the left neurons is also a way of randomly selecting neur...
14,500
38.620219
219
py
ELLE
ELLE-main/fairseq-0.9.0/examples/roberta/commonsense_qa/commonsense_qa_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 json import os import numpy as np import torch from fairseq.data import ( data_utils, Dictionary, encoders, IdDataset...
5,921
32.84
103
py
ELLE
ELLE-main/fairseq-0.9.0/examples/roberta/wsc/wsc_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 json import os import tempfile import numpy as np import torch import torch.nn.functional as F from fairseq import utils from fairseq...
13,149
33.973404
103
py
ELLE
ELLE-main/fairseq-0.9.0/examples/roberta/wsc/wsc_criterion.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 torch import torch.nn.functional as F from fairseq import utils from fairseq.data import encoders from fairseq.criterions...
6,022
35.065868
88
py
ELLE
ELLE-main/fairseq-0.9.0/scripts/average_checkpoints.py
#!/usr/bin/env python3 # 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 argparse import collections import torch import os import re def average_checkpoints(inputs): """Loads che...
5,292
36.539007
134
py
ELLE
ELLE-main/fairseq-0.9.0/scripts/wav2vec_featurize.py
#!/usr/bin/env python3 # 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. """ Helper script to pre-compute embeddings for a wav2letter++ dataset """ import argparse import glob import os from ...
7,102
28.970464
135
py
ELLE
ELLE-main/fairseq-0.9.0/tests/test_train.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 contextlib from io import StringIO import unittest from unittest.mock import MagicMock, patch import torch from fairseq import data, ...
4,691
35.092308
94
py
ELLE
ELLE-main/fairseq-0.9.0/tests/test_average_checkpoints.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 collections import os import tempfile import unittest import shutil import numpy as np import torch from torch import nn from script...
4,494
30.215278
80
py
ELLE
ELLE-main/fairseq-0.9.0/tests/test_sequence_scorer.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 argparse import unittest import torch from fairseq.sequence_scorer import SequenceScorer import tests.utils as test_utils class Te...
3,949
33.051724
75
py
ELLE
ELLE-main/fairseq-0.9.0/tests/test_memory_efficient_fp16.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 argparse import unittest import torch from fairseq.optim.adam import FairseqAdam from fairseq.optim.fp16_optimizer import MemoryEffic...
1,787
28.311475
69
py
ELLE
ELLE-main/fairseq-0.9.0/tests/test_multihead_attention.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 unittest from fairseq.modules.multihead_attention import MultiheadAttention class TestMultiheadAttention(unittest.TestCa...
1,904
30.229508
80
py
ELLE
ELLE-main/fairseq-0.9.0/tests/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 argparse import torch from fairseq import utils from fairseq.data import Dictionary from fairseq.data.language_pair_dataset import col...
7,442
30.67234
101
py
ELLE
ELLE-main/fairseq-0.9.0/tests/test_binaries.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 contextlib from io import StringIO import os import random import sys import tempfile import unittest import torch from fairseq impor...
31,257
40.183136
115
py
ELLE
ELLE-main/fairseq-0.9.0/tests/test_concat_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 unittest import torch from fairseq.data import LanguagePairDataset, TokenBlockDataset from fairseq.data.concat_dataset import ConcatDa...
1,943
28.907692
66
py
ELLE
ELLE-main/fairseq-0.9.0/tests/test_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 unittest from typing import Dict, List import tests.utils as test_utils import torch from fairseq import utils from fairseq.data impor...
19,779
36.533207
87
py
ELLE
ELLE-main/fairseq-0.9.0/tests/test_sparse_multihead_attention.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 unittest from fairseq.modules.sparse_multihead_attention import SparseMultiheadAttention class TestSparseMultiheadAttent...
2,545
50.959184
114
py
ELLE
ELLE-main/fairseq-0.9.0/tests/test_backtranslation_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 unittest import torch from fairseq.data import ( BacktranslationDataset, LanguagePairDataset, TransformEosDataset, ) from...
4,032
33.470085
90
py
ELLE
ELLE-main/fairseq-0.9.0/tests/test_sequence_generator.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 argparse import unittest import torch from fairseq.sequence_generator import SequenceGenerator import tests.utils as test_utils cl...
14,876
38.884718
96
py
ELLE
ELLE-main/fairseq-0.9.0/tests/test_label_smoothing.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 argparse import copy import unittest import torch from fairseq.criterions.cross_entropy import CrossEntropyCriterion from fairseq.cri...
4,139
40.4
101
py
ELLE
ELLE-main/fairseq-0.9.0/tests/test_convtbc.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 unittest from fairseq.modules import ConvTBC import torch.nn as nn class TestConvTBC(unittest.TestCase): def test_c...
1,679
33.285714
102
py
ELLE
ELLE-main/fairseq-0.9.0/tests/test_token_block_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 unittest import torch from fairseq.data import TokenBlockDataset import tests.utils as test_utils class TestTokenBlockDataset(unit...
2,970
36.607595
89
py
ELLE
ELLE-main/fairseq-0.9.0/tests/test_multi_corpus_sampled_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 unittest from collections import OrderedDict import numpy as np import torch from fairseq.data import LanguagePairDataset, TokenBlockD...
3,105
31.354167
79
py
ELLE
ELLE-main/fairseq-0.9.0/tests/test_bmuf.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 argparse from multiprocessing import Manager import random import unittest import torch import torch.nn as nn from fairseq import dis...
4,554
28.198718
88
py
ELLE
ELLE-main/fairseq-0.9.0/tests/test_dictionary.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 tempfile import unittest import torch from fairseq.data import Dictionary class TestDictionary(unittest.TestCase): def test_fi...
1,863
25.253521
80
py
ELLE
ELLE-main/fairseq-0.9.0/tests/test_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 unittest import torch from fairseq import utils class TestUtils(unittest.TestCase): def test_convert_padding_direction(self): ...
2,131
24.380952
65
py
ELLE
ELLE-main/fairseq-0.9.0/tests/test_character_token_embedder.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 unittest from fairseq.data import Dictionary from fairseq.modules import CharacterTokenEmbedder class TestCharacterToke...
1,656
34.255319
96
py
ELLE
ELLE-main/fairseq-0.9.0/tests/speech_recognition/asr_test_base.py
#!/usr/bin/env python3 import argparse import os import unittest from inspect import currentframe, getframeinfo import numpy as np import torch from fairseq.data import data_utils as fairseq_data_utils from fairseq.data.dictionary import Dictionary from fairseq.models import ( BaseFairseqModel, FairseqDecoder...
19,247
33.80651
87
py
ELLE
ELLE-main/fairseq-0.9.0/tests/speech_recognition/test_collaters.py
#!/usr/bin/env python3 # 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 unittest import numpy as np import torch from examples.speech_recognition.data.collaters import Seq2SeqCollater...
2,048
33.728814
87
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/checkpoint_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 collections import logging import os import re import shutil import traceback from collections import OrderedDict from typing import Un...
17,850
35.655031
116
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/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. from collections import defaultdict import contextlib import copy import importlib.util import math import os import sys from typing import Ca...
13,882
31.665882
111
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/hub_utils.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. import argparse import copy import os import torch from torch import nn from fairseq import utils from fairseq.dat...
8,171
33.627119
117
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/sequence_scorer.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 sys from fairseq import utils class SequenceScorer(object): """Scores the target for a given source sentence.""" ...
4,508
36.575
107
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/distributed_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 os import pickle import socket import subprocess import warnings import torch import torch.distributed as dist from fairseq import ut...
6,952
35.984043
97
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/sequence_generator.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 torch from fairseq import search, utils from fairseq.data import data_utils from fairseq.models import FairseqIncremental...
30,353
41.512605
118
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/legacy_distributed_data_parallel.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. """ A modified version of the legacy DistributedDataParallel module that uses c10d communication primitives. This version is simpler than the ...
6,724
36.154696
88
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/options.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 argparse import torch import sys from fairseq import utils from fairseq.data.indexed_dataset import get_available_dataset_impl def ...
28,856
51.755027
120
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/bleu.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 ctypes import math import torch try: from fairseq import libbleu except ImportError as e: import sys sys.stderr.write('ERR...
3,955
29.430769
83
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/file_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. """ Utilities for working with the local dataset cache. This file is adapted from `AllenNLP <https://github.com/allenai/allennlp>`_. and `hugg...
10,466
31.811912
98
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/search.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 torch class Search(object): def __init__(self, tgt_dict): self.pad = tgt_dict.pad() self.unk = tgt_...
11,223
36.918919
104
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/iterative_refinement_generator.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 namedtuple import torch from fairseq import utils DecoderOut = namedtuple('IterativeRefinementDecoderOut', [ '...
9,288
36.007968
117
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/trainer.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. """ Train a network across multiple GPUs. """ import contextlib import math import os import sys from collections import OrderedDict from ite...
25,419
37.225564
93
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/modules/transformer_sentence_encoder_layer.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 torch.nn as nn import torch.nn.functional as F from fairseq import utils from fairseq.modules import ( LayerNorm, ...
2,952
30.414894
80
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/modules/learned_positional_embedding.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.nn as nn from fairseq import utils class LearnedPositionalEmbedding(nn.Embedding): """ This module learns positional e...
1,881
35.901961
94
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/modules/sparse_multihead_attention.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 torch from .multihead_attention import MultiheadAttention class SparseMultiheadAttention(MultiheadAttention): """ Spa...
4,525
42.104762
100
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/modules/multihead_attention.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 torch from torch import nn from torch.nn import Parameter import torch.nn.functional as F from fairseq import utils clas...
15,904
42.220109
116
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/modules/highway.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 torch import nn class Highway(torch.nn.Module): """ A `Highway layer <https://arxiv.org/abs/1505.00387>`_. Ad...
1,745
31.943396
97
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/modules/linearized_convolution.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 torch.nn.functional as F from fairseq import utils from .conv_tbc import ConvTBC class LinearizedConvolution(ConvTBC):...
3,598
39.897727
95
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/modules/downsampled_multihead_attention.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 torch import torch.nn as nn import torch.nn.functional as F from fairseq.modules.scalar_bias import scalar_bias class ...
9,815
37.194553
106
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/modules/gelu.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. """ See "Gaussian Error Linear Units (GELUs)" by Dan Hendrycks and Kevin Gimpel with the corresponding GitHub repo: https://github.com/hendryck...
790
29.423077
90
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/modules/positional_embedding.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.nn as nn from .learned_positional_embedding import LearnedPositionalEmbedding from .sinusoidal_positional_embedding import Sinus...
1,287
36.882353
83
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/modules/adaptive_input.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 torch import nn from typing import List class AdaptiveInput(nn.Module): def __init__( self, vocab_s...
2,283
30.287671
80
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/modules/vggblock.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 __future__ import absolute_import, division, print_function, unicode_literals from collections.abc import Iterable from itertools import...
4,057
33.683761
88
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/modules/character_token_embedder.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 torch.nn.functional as F from torch import nn from typing import List, Tuple from .highway import Highway from fairseq....
5,298
32.327044
106
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/modules/unfold.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.nn.functional as F def unfold1d(x, kernel_size, padding_l, pad_value=0): '''unfold T x B x C to T x B x C x K''' if ker...
570
30.722222
91
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/modules/adaptive_softmax.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 operator import functools import torch import torch.nn.functional as F from torch import nn class TiedLinear(nn.Module): def __i...
7,207
33.821256
112
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/modules/conv_tbc.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 torch.nn.modules.utils import _single class ConvTBC(torch.nn.Module): """1D convolution over an input of shape (time x...
1,356
35.675676
90
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/modules/transformer_layer.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 torch.nn as nn import torch.nn.functional as F from fairseq import utils from fairseq.modules import LayerNorm, MultiheadA...
13,496
42.259615
147
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/modules/mean_pool_gating_network.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 torch.nn.functional as F class MeanPoolGatingNetwork(torch.nn.Module): """A simple mean-pooling gating network for s...
2,007
38.372549
84
py
ELLE
ELLE-main/fairseq-0.9.0/fairseq/modules/logsumexp_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 class LogSumExpMoE(torch.autograd.Function): """Standard LogSumExp forward pass, but use *posterior* for the backward. ...
835
29.962963
78
py