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
unbalanced-ot-functionals
unbalanced-ot-functionals-master/examples/plan_marginal_impact_reach.py
import os import torch import numpy as np import matplotlib.pyplot as plt from unbalancedot.utils import euclidean_cost from unbalancedot.sinkhorn import BatchVanillaSinkhorn from unbalancedot.entropy import KullbackLeibler, TotalVariation path = os.getcwd() + "/output" if not os.path.isdir(path): os.mkdir(path)...
2,653
26.936842
78
py
unbalanced-ot-functionals
unbalanced-ot-functionals-master/examples/plan_marginal_v2.py
import os import torch import numpy as np import matplotlib.pyplot as plt from unbalancedot.utils import euclidean_cost from unbalancedot.sinkhorn import BatchVanillaSinkhorn from unbalancedot.entropy import ( KullbackLeibler, Balanced, TotalVariation, Range, PowerEntropy, ) path = os.getcwd() + ...
3,020
25.973214
90
py
unbalanced-ot-functionals
unbalanced-ot-functionals-master/examples/plot_unb_gradient_flows_2D_waffle.py
import os import time import numpy as np from random import choices import imageio from matplotlib import pyplot as plt from functools import partial import torch from unbalancedot.functional import regularized_ot, hausdorff_divergence, \ sinkhorn_divergence from unbalancedot.sinkhorn import BatchVanillaSinkhorn ...
8,117
38.028846
79
py
unbalanced-ot-functionals
unbalanced-ot-functionals-master/examples/plot_unb_gradient_flows_2D_frame_v2.py
import os import numpy as np from random import choices import imageio from matplotlib import pyplot as plt, use from functools import partial from sympy import EX import torch from unbalancedot.functional import regularized_ot, hausdorff_divergence, \ sinkhorn_divergence from unbalancedot.sinkhorn import BatchVa...
6,514
35.396648
79
py
unbalanced-ot-functionals
unbalanced-ot-functionals-master/unbalancedot/sinkhorn.py
import torch import numpy as np from .utils import softmin, exp_softmin class SinkhornSolver(object): def sinkhorn_asym( self, a_i, x_i, b_j, y_j, p, entropy, f_i=None, g_j=None ): """Computes the Sinkhorn algorithm for two different measures""" raise NotImplementedError def sinkh...
8,837
34.211155
76
py
unbalanced-ot-functionals
unbalanced-ot-functionals-master/unbalancedot/functional.py
import torch from .entropy import TotalVariation, Range from .sinkhorn import BatchVanillaSinkhorn from .utils import dist_matrix def regularized_ot( a, x, b, y, cost, entropy, solver=BatchVanillaSinkhorn( nits=100, nits_grad=5, tol=1e-3, assume_convergence=True ), ): f_x, ...
2,846
29.287234
78
py
unbalanced-ot-functionals
unbalanced-ot-functionals-master/unbalancedot/utils.py
import torch def scal(a, f): return torch.sum(a * f, dim=1) def check_cost_consistency(x, y, C): mask = ( (x.size()[0] == C.size()[0]) & (x.size()[1] == C.size()[1]) & (y.size()[2] == C.size()[2]) ) if not mask: raise Exception( "Dimension of cost C incons...
3,021
25.743363
79
py
unbalanced-ot-functionals
unbalanced-ot-functionals-master/unbalancedot/entropy.py
import torch from .torch_lambertw import log_lambertw from .utils import scal, convolution # TODO: Add multiscale exponential version of the KL projections class Entropy(object): """ Object that defines the required modules for entropy functions. """ def entropy(self, x): """Pointwise entrop...
17,940
28.556837
79
py
unbalanced-ot-functionals
unbalanced-ot-functionals-master/unbalancedot/torch_lambertw.py
import torch def log_lambertw(x): """ Computes the Lambert function via Halley algorithm which converges cubically. The initialization is performed with a local approximation. """ z = init_lambertw(x) eps = torch.finfo(x.dtype).eps def a(w): return (w * ((w + eps).log() + w - ...
928
22.820513
78
py
unbalanced-ot-functionals
unbalanced-ot-functionals-master/unbalancedot/tests/test_lambertw.py
# import torch # import numpy as np # import scipy.special.lambertw as lambertw # from unbalancedot.torch_lambertw import log_lambertw # # torch.manual_seed(0) # # # def test_log_lambertw(): # input = np.array( # [-10000, -500.0, -100.0, -5.0, -2.0, 0.0, 1.0, 5.0, 500.0] # ) # control = np.real(lamb...
468
28.3125
73
py
unbalanced-ot-functionals
unbalanced-ot-functionals-master/unbalancedot/tests/test_functional.py
import pytest import torch from unbalancedot.functional import ( regularized_ot, hausdorff_divergence, sinkhorn_divergence, energyDistance, ) from unbalancedot.sinkhorn import BatchVanillaSinkhorn from unbalancedot.entropy import ( KullbackLeibler, Balanced, TotalVariation, Range, ...
5,326
29.267045
76
py
unbalanced-ot-functionals
unbalanced-ot-functionals-master/unbalancedot/tests/test_cuda.py
# import pytest # # import torch # from unbalancedot.functional import sinkhorn_divergence # from unbalancedot.sinkhorn import BatchVanillaSinkhorn # from unbalancedot.entropy import ( # KullbackLeibler, # Balanced, # TotalVariation, # Range, # PowerEntropy, # ) # from unbalancedot.utils import gene...
1,144
27.625
76
py
unbalanced-ot-functionals
unbalanced-ot-functionals-master/unbalancedot/tests/test_gradient.py
import pytest import torch from unbalancedot.functional import regularized_ot, sinkhorn_divergence from unbalancedot.sinkhorn import BatchVanillaSinkhorn, BatchExpSinkhorn from unbalancedot.entropy import ( KullbackLeibler, Balanced, TotalVariation, Range, PowerEntropy, ) from unbalancedot.utils i...
9,423
29.697068
78
py
unbalanced-ot-functionals
unbalanced-ot-functionals-master/unbalancedot/tests/test_sinkhorn.py
import pytest import torch from unbalancedot.sinkhorn import ( BatchVanillaSinkhorn, BatchScalingSinkhorn, BatchExpSinkhorn, ) from unbalancedot.entropy import ( KullbackLeibler, Balanced, TotalVariation, Range, PowerEntropy, ) from unbalancedot.utils import generate_measure, euclidean...
10,131
30.271605
79
py
torch-cam
torch-cam-main/setup.py
# Copyright (C) 2020-2023, François-Guillaume Fernandez. # This program is licensed under the Apache License 2.0. # See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0> for full license details. import os from pathlib import Path from setuptools import setup PKG_NAME = "torchcam" VERSION = os.getenv(...
696
26.88
94
py
torch-cam
torch-cam-main/.github/verify_labels.py
# Copyright (C) 2020-2023, François-Guillaume Fernandez. # This program is licensed under the Apache License 2.0. # See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0> for full license details. """ Borrowed & adapted from https://github.com/pytorch/vision/blob/main/.github/process_commit.py This script...
2,529
28.418605
114
py
torch-cam
torch-cam-main/.github/collect_env.py
# Copyright (C) 2020-2023, François-Guillaume Fernandez. # This program is licensed under the Apache License 2.0. # See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0> for full license details. """ Based on https://github.com/pytorch/pytorch/blob/master/torch/utils/collect_env.py This script outputs re...
9,883
29.2263
103
py
torch-cam
torch-cam-main/scripts/eval_perf.py
# Copyright (C) 2022-2023, François-Guillaume Fernandez. # This program is licensed under the Apache License 2.0. # See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0> for full license details. """ CAM performance evaluation """ import argparse import math import os from functools import partial impo...
3,349
33.536082
118
py
torch-cam
torch-cam-main/scripts/eval_latency.py
# Copyright (C) 2021-2023, François-Guillaume Fernandez. # This program is licensed under the Apache License 2.0. # See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0> for full license details. """ CAM latency benchmark """ import argparse import time import numpy as np import torch from torchvision ...
2,482
32.554054
108
py
torch-cam
torch-cam-main/scripts/cam_example.py
# Copyright (C) 2020-2023, François-Guillaume Fernandez. # This program is licensed under the Apache License 2.0. # See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0> for full license details. """ CAM visualization """ import argparse import math from io import BytesIO import matplotlib.pyplot as pl...
4,911
33.591549
116
py
torch-cam
torch-cam-main/tests/test_methods_activation.py
import pytest import torch from torchvision.models import mobilenet_v2 from torchcam.methods import activation def test_base_cam_constructor(mock_img_model): model = mobilenet_v2(pretrained=False).eval() for p in model.parameters(): p.requires_grad_(False) # Check that multiple target layers is d...
3,806
39.5
107
py
torch-cam
torch-cam-main/tests/test_methods_utils.py
from torchvision.models import mobilenet_v3_large, resnet18 from torchcam.methods import _utils def test_locate_candidate_layer(mock_img_model): # ResNet-18 mod = resnet18().eval() for p in mod.parameters(): p.requires_grad_(False) assert _utils.locate_candidate_layer(mod) == "layer4" # ...
1,008
26.27027
73
py
torch-cam
torch-cam-main/tests/conftest.py
from io import BytesIO import pytest import requests import torch from PIL import Image from torch import nn from torchvision.transforms.functional import normalize, resize, to_tensor @pytest.fixture(scope="session") def mock_img_tensor(): try: # Get a dog image URL = "https://www.woopets.fr/asse...
2,201
24.310345
96
py
torch-cam
torch-cam-main/tests/test_methods_gradient.py
import pytest import torch from torch import nn from torchvision.models import mobilenet_v2 from torchcam.methods import gradient def _verify_cam(activation_map, output_size): # Simple verifications assert isinstance(activation_map, torch.Tensor) assert activation_map.shape == output_size assert not ...
4,044
35.116071
115
py
torch-cam
torch-cam-main/tests/test_methods_core.py
import pytest import torch from torchcam.methods import core def test_cam_constructor(mock_img_model): model = mock_img_model.eval() # Check that wrong target_layer raises an error with pytest.raises(ValueError): core._CAM(model, "3") # Wrong types with pytest.raises(TypeError): ...
3,787
28.826772
82
py
torch-cam
torch-cam-main/tests/test_metrics.py
from functools import partial import torch from torchvision.models import mobilenet_v3_small from torchcam import metrics from torchcam.methods import LayerCAM def test_classification_metric(): model = mobilenet_v3_small(pretrained=False) with LayerCAM(model, "features.12") as extractor: metric = me...
707
29.782609
88
py
torch-cam
torch-cam-main/tests/test_utils.py
import numpy as np from PIL import Image from torchcam import utils def test_overlay_mask(): img = Image.fromarray(np.zeros((4, 4, 3)).astype(np.uint8)) mask = Image.fromarray(255 * np.ones((4, 4)).astype(np.uint8)) overlayed = utils.overlay_mask(img, mask, alpha=0.7) # Check object type assert...
538
27.368421
66
py
torch-cam
torch-cam-main/demo/app.py
# Copyright (C) 2021-2023, François-Guillaume Fernandez. # This program is licensed under the Apache License 2.0. # See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0> for full license details. from io import BytesIO import matplotlib.pyplot as plt import requests import streamlit as st import torch f...
4,741
33.362319
120
py
torch-cam
torch-cam-main/torchcam/utils.py
# Copyright (C) 2020-2023, François-Guillaume Fernandez. # This program is licensed under the Apache License 2.0. # See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0> for full license details. import numpy as np from matplotlib import cm from PIL import Image def overlay_mask(img: Image.Image, mask:...
1,706
34.5625
112
py
torch-cam
torch-cam-main/torchcam/metrics.py
# Copyright (C) 2022-2023, François-Guillaume Fernandez. # This program is licensed under the Apache License 2.0. # See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0> for full license details. from typing import Callable, Dict, Union, cast import torch from .methods.core import _CAM class Classifi...
4,824
35.007463
115
py
torch-cam
torch-cam-main/torchcam/__init__.py
from torchcam import methods, metrics, utils try: from .version import __version__ except ImportError: pass
117
15.857143
44
py
torch-cam
torch-cam-main/torchcam/methods/activation.py
# Copyright (C) 2020-2023, François-Guillaume Fernandez. # This program is licensed under the Apache License 2.0. # See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0> for full license details. import logging import math from typing import Any, List, Optional, Tuple, Union import torch import torch.nn...
17,439
40.722488
118
py
torch-cam
torch-cam-main/torchcam/methods/core.py
# Copyright (C) 2020-2023, François-Guillaume Fernandez. # This program is licensed under the Apache License 2.0. # See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0> for full license details. import logging from abc import abstractmethod from functools import partial from types import TracebackType f...
10,591
39.738462
119
py
torch-cam
torch-cam-main/torchcam/methods/_utils.py
# Copyright (C) 2020-2023, François-Guillaume Fernandez. # This program is licensed under the Apache License 2.0. # See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0> for full license details. from functools import partial from typing import List, Optional, Tuple import torch from torch import Tensor...
2,422
30.064103
115
py
torch-cam
torch-cam-main/torchcam/methods/gradient.py
# Copyright (C) 2020-2023, François-Guillaume Fernandez. # This program is licensed under the Apache License 2.0. # See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0> for full license details. from functools import partial from typing import Any, List, Optional, Tuple, Union import torch from torch i...
16,864
41.804569
119
py
torch-cam
torch-cam-main/docs/source/conf.py
# Copyright (C) 2020-2023, François-Guillaume Fernandez. # This program is licensed under the Apache License 2.0. # See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0> for full license details. # Configuration file for the Sphinx documentation builder. # # This file only contains a selection of the mos...
5,056
36.459259
628
py
VecConstNMT
VecConstNMT-master/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, 6): sys.exi...
4,434
25.716867
101
py
VecConstNMT
VecConstNMT-master/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
VecConstNMT
VecConstNMT-master/examples/wav2vec/vq-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 pprint import glob, os, argparse im...
7,714
29.737052
111
py
VecConstNMT
VecConstNMT-master/examples/wav2vec/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,110
29.004219
135
py
VecConstNMT
VecConstNMT-master/examples/translation_moe/src/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
VecConstNMT
VecConstNMT-master/examples/translation_moe/src/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
VecConstNMT
VecConstNMT-master/examples/translation_moe/src/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, utils from fairseq.tasks import register_task from fairseq.tasks.translation import TranslationTask...
9,143
40.375566
107
py
VecConstNMT
VecConstNMT-master/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,933
32.908571
103
py
VecConstNMT
VecConstNMT-master/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,160
34.00266
103
py
VecConstNMT
VecConstNMT-master/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,034
35.137725
88
py
VecConstNMT
VecConstNMT-master/examples/speech_recognition/infer.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. """ Run inference for pre-processed data with a trained model. """ import editdistance import logging import math i...
14,716
33.225581
147
py
VecConstNMT
VecConstNMT-master/examples/speech_recognition/w2l_decoder.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. """ Wav2letter decoders. """ from collections import namedtuple, deque import gc import itertools as it import numpy ...
14,872
33.269585
164
py
VecConstNMT
VecConstNMT-master/examples/speech_recognition/criterions/cross_entropy_acc.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 import logging import math import torch import torch.nn.f...
5,372
40.015267
85
py
VecConstNMT
VecConstNMT-master/examples/speech_recognition/criterions/ASG_loss.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 torch from fairseq import utils from fairseq.criterions import FairseqCriterion, register_criterion from exampl...
5,857
33.25731
85
py
VecConstNMT
VecConstNMT-master/examples/speech_recognition/models/vggtransformer.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 math from collections.abc import Iterable import torch import torch.nn as nn from fairseq import utils from fairseq.mo...
37,043
35.786495
88
py
VecConstNMT
VecConstNMT-master/examples/speech_recognition/models/w2l_conv_glu_enc.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 math import torch import torch.nn as nn import torch.nn.functional as F from fairseq.models import ( Fair...
6,079
32.96648
87
py
VecConstNMT
VecConstNMT-master/examples/speech_recognition/datasets/asr_prep_json.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. from __future__ import absolute_import, division, print_function, unicode_literals from collections import namedtuple ...
3,670
36.845361
134
py
VecConstNMT
VecConstNMT-master/examples/speech_recognition/data/collaters.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. """ This module contains collection of classes which implement collate functionalities for various tasks. Collaters should know wh...
4,812
35.462121
84
py
VecConstNMT
VecConstNMT-master/examples/speech_recognition/data/data_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 def calc_mean_invstddev(feature): if len(feature.size()) != 2: raise ValueError("We expect the input feature to be ...
3,429
32.960396
84
py
VecConstNMT
VecConstNMT-master/examples/speech_recognition/data/asr_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 from fairseq.data import FairseqDataset from . import data_utils from .collaters import Seq2SeqCollater class ...
3,870
33.5625
82
py
VecConstNMT
VecConstNMT-master/examples/speech_recognition/tasks/speech_recognition.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 re import sys import torch from fairseq.data import Dictionary from fairseq.tasks import register_task, LegacyFa...
5,106
34.465278
97
py
VecConstNMT
VecConstNMT-master/examples/byte_level_bpe/gru_transformer.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. # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the r...
5,028
46.895238
87
py
VecConstNMT
VecConstNMT-master/examples/simultaneous_translation/modules/monotonic_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.functional as F import torch.nn as nn from fairseq import utils from fairseq.modules import Multihe...
21,349
35.125212
119
py
VecConstNMT
VecConstNMT-master/examples/simultaneous_translation/eval/eval_latency.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 examples.simultaneous_translation.utils.latency import LatencyInference import argparse import torch import json LATENCY_METRICS = [ ...
2,432
29.037037
85
py
VecConstNMT
VecConstNMT-master/examples/simultaneous_translation/models/transformer_monotonic_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 torch.nn as nn import torch.nn.functional as F from fairseq.models import ( register_model, register_model_archit...
11,249
30.163435
95
py
VecConstNMT
VecConstNMT-master/examples/simultaneous_translation/utils/functions.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 def exclusive_cumprod(tensor, dim: int, eps: float = 1e-10): """ Implementing exclusive cumprod. There is cumprod i...
3,908
25.773973
95
py
VecConstNMT
VecConstNMT-master/examples/simultaneous_translation/utils/latency.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 LatencyMetric(object): @staticmethod def length_from_padding_mask(padding_mask, batch_first: bool = False): ...
14,598
32.407323
110
py
VecConstNMT
VecConstNMT-master/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 from fairseq.file_io import PathManager def aver...
5,957
38.456954
175
py
VecConstNMT
VecConstNMT-master/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 import logging import unittest from io import StringIO from unittest.mock import MagicMock, patch import torch from fairse...
8,428
40.318627
110
py
VecConstNMT
VecConstNMT-master/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
VecConstNMT
VecConstNMT-master/tests/test_reproducibility.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 json import os import tempfile import unittest import torch from . import test_binaries c...
3,864
36.163462
97
py
VecConstNMT
VecConstNMT-master/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
VecConstNMT
VecConstNMT-master/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 logging import unittest import torch from fairseq.optim.adam import FairseqAdam from fairseq.optim.fp16_optimizer imp...
2,002
28.028986
70
py
VecConstNMT
VecConstNMT-master/tests/test_lstm_jitable.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 tempfile import unittest import torch from fairseq.data.dictionary import Dictionary from fairseq.models.lstm import L...
4,007
34.157895
99
py
VecConstNMT
VecConstNMT-master/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
VecConstNMT
VecConstNMT-master/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 os import random import sys import torch import torch.nn.functional as F from io import StringIO from fairseq import o...
16,432
32.131048
107
py
VecConstNMT
VecConstNMT-master/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 logging import os import random import tempfile import unittest import torch from fairseq i...
40,147
40.951933
122
py
VecConstNMT
VecConstNMT-master/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
VecConstNMT
VecConstNMT-master/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
VecConstNMT
VecConstNMT-master/tests/test_constraints.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 sys import torch import unittest from fairseq.token_generation_constraints import * def tensorize(constraints: List[List[int]]) -> t...
10,242
39.168627
204
py
VecConstNMT
VecConstNMT-master/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
VecConstNMT
VecConstNMT-master/tests/test_export.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 tempfile import unittest import torch from fairseq.data.dictionary import Dictionary from fairs...
3,511
31.220183
86
py
VecConstNMT
VecConstNMT-master/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,030
33.452991
90
py
VecConstNMT
VecConstNMT-master/tests/test_fp16_optimizer.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.optim.fp16_optimizer import FP16Optimizer, MemoryEfficientFP16Optimize...
2,720
33.884615
129
py
VecConstNMT
VecConstNMT-master/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 tempfile import unittest import tests.utils as test_utils import torch from fairseq import search from fairseq.data.di...
23,561
38.800676
102
py
VecConstNMT
VecConstNMT-master/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,235
41.36
101
py
VecConstNMT
VecConstNMT-master/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
VecConstNMT
VecConstNMT-master/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
VecConstNMT
VecConstNMT-master/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
VecConstNMT
VecConstNMT-master/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...
5,351
29.758621
88
py
VecConstNMT
VecConstNMT-master/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 io import tempfile import unittest import torch from fairseq.data import Dictionary class TestDictionary(unittest.TestCase): d...
3,336
27.521368
80
py
VecConstNMT
VecConstNMT-master/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): ...
3,067
28.219048
78
py
VecConstNMT
VecConstNMT-master/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
VecConstNMT
VecConstNMT-master/tests/gpu/test_binaries_gpu.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 import logging import os import tempfile import unittest from io import StringIO import torch from fairseq import options f...
9,920
31.421569
92
py
VecConstNMT
VecConstNMT-master/tests/speech_recognition/test_data_utils.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 torch from examples.speech_recognition.data import data_utils class DataUtilsTest(unittest.Te...
1,039
42.333333
108
py
VecConstNMT
VecConstNMT-master/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,503
33.953405
92
py
VecConstNMT
VecConstNMT-master/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
VecConstNMT
VecConstNMT-master/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 traceback from collections import OrderedDict from typing import Union import to...
30,399
42.930636
115
py
VecConstNMT
VecConstNMT-master/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. import contextlib import copy import importlib.util import logging import math import os import sys import warnings from collections import de...
20,829
31.395023
111
py
VecConstNMT
VecConstNMT-master/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 logging import os from typing import List, Dict, Iterator, Tuple, Any import tor...
10,083
36.210332
114
py
VecConstNMT
VecConstNMT-master/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.""" ...
5,071
36.850746
107
py
VecConstNMT
VecConstNMT-master/fairseq/binarizer.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 from collections import Counter from fairseq.tokenizer import tokenize_line import torch from fairseq.file_io import PathManager d...
3,975
31.590164
84
py
VecConstNMT
VecConstNMT-master/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 logging import os import pickle import random import socket import struct import subprocess import warnings from collections import Ord...
15,816
39.765464
107
py
VecConstNMT
VecConstNMT-master/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 from typing import Dict, List, Optional import torch import torch.nn as nn from fairseq import search, utils from fairseq.data im...
40,912
39.913
118
py