repo stringlengths 2 99 | file stringlengths 13 225 | code stringlengths 0 18.3M | file_length int64 0 18.3M | avg_line_length float64 0 1.36M | max_line_length int64 0 4.26M | extension_type stringclasses 1
value |
|---|---|---|---|---|---|---|
sign-topic | sign-topic-main/examples/simultaneous_translation/utils/p_choose_strategy.py | from typing import Optional, Dict
from torch import Tensor
import torch
def waitk_p_choose(
tgt_len: int,
src_len: int,
bsz: int,
waitk_lagging: int,
key_padding_mask: Optional[Tensor] = None,
incremental_state: Optional[Dict[str, Dict[str, Optional[Tensor]]]] = None
):
max_src_len = src_... | 3,445 | 26.133858 | 78 | py |
sign-topic | sign-topic-main/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 prob_check(tensor, eps=1e-10):
assert not torch.isnan(tensor).any(), (
"Nan in a probability tensor."
)
... | 3,535 | 27.063492 | 84 | py |
sign-topic | sign-topic-main/examples/simultaneous_translation/utils/__init__.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 importlib
import os
# automatically import any Python files in the criterions/ directory
for file in sorted(os.listdir(os.path.dirnam... | 520 | 33.733333 | 84 | py |
sign-topic | sign-topic-main/examples/SL_topic_detection/analysis_outputs.py | # Script for analizing outputs produced by the models.
import math
from typing import Tuple
from typing import Union
from typing import List
from copy import deepcopy
import argparse
import ast
import pandas as pd
from sympy import ShapeError
import numpy as np
from sklearn import manifold
from sklearn.metrics impor... | 27,538 | 35.235526 | 167 | py |
sign-topic | sign-topic-main/examples/SL_topic_detection/utils.py | import re
from typing import Dict
from typing import List
from typing import Union
from typing import Optional
from pathlib import Path
import csv
from multiprocessing import cpu_count
import pdb
import h5py
import numpy as np
import pandas as pd
from tqdm import tqdm
import sentencepiece as sp
def save_df_to_tsv(da... | 4,554 | 30.413793 | 96 | py |
sign-topic | sign-topic-main/examples/SL_topic_detection/infer.py | import ast
import os
import sys
from dataclasses import dataclass, field, is_dataclass
import logging
from pathlib import Path
from typing import Any, Dict, List, Optional, Tuple, Union, Callable
from operator import attrgetter
import torch
import torch.distributed as dist
import hydra
from hydra.core.config_store im... | 17,569 | 37.030303 | 148 | py |
sign-topic | sign-topic-main/examples/SL_topic_detection/prep_how2sign.py | #!/usr/bin/env python3
import errno
import os
import json
import h5py
import argparse
import logging
import pandas as pd
from typing import Tuple
from typing import List
from pathlib import Path
from tempfile import NamedTemporaryFile
import cv2
import torchvision
import torch
from torch.utils.data import Dataset
fro... | 8,850 | 35.57438 | 163 | py |
sign-topic | sign-topic-main/examples/sign2vec/utils.py | import h5py
import numpy as np
import pandas as pd
from tqdm import tqdm
from pathlib import Path
import pdb
def h5_video2sentence(input_tsv: Path, input_h5: Path, output_h5: Path, overwrite=False):
if not input_tsv.is_file():
raise FileNotFoundError(f"{input_tsv} not found")
if not input_h5.is_file():... | 1,147 | 32.764706 | 89 | py |
sign-topic | sign-topic-main/examples/sign2vec/prep_how2sign.py | #!/usr/bin/env python3
# This code is based on the speech_to_text implementation (commit: d974c70)
#
# 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 h5py
import argparse
import loggi... | 5,013 | 34.062937 | 101 | py |
sign-topic | sign-topic-main/examples/fast_noisy_channel/noisy_channel_translation.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from fairseq.tasks.translation import TranslationTask
from fairseq.tasks.language_modeling import LanguageModelingTask
from fairseq import che... | 6,709 | 51.421875 | 160 | py |
sign-topic | sign-topic-main/examples/fast_noisy_channel/noisy_channel_beam_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 torch
from fairseq.search import Search
class NoisyChannelBeamSearch(Search):
def __init__(self, tgt_dict):
super().__in... | 2,895 | 39.222222 | 104 | py |
sign-topic | sign-topic-main/examples/fast_noisy_channel/noisy_channel_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.
from typing import Dict, List, Optional
import math
import numpy as np
import torch
import torch.nn.functional as F
from torch import Tensor... | 41,200 | 47.874259 | 187 | py |
sign-topic | sign-topic-main/examples/fast_noisy_channel/__init__.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 . import noisy_channel_translation # noqa
from . import noisy_channel_sequence_generator # noqa
from . import noisy_channel_beam_search... | 329 | 35.666667 | 65 | py |
sign-topic | sign-topic-main/examples/noisychannel/rerank_score_bw.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 contextlib import redirect_stdout
from fairseq import options
from fairseq_cli import generate
from examples.noisychannel imp... | 4,212 | 28.256944 | 88 | py |
sign-topic | sign-topic-main/examples/noisychannel/rerank_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.
"""
Generate n-best translations using a trained model.
"""
import os
import subprocess
from contextlib import redi... | 14,157 | 34.572864 | 105 | py |
sign-topic | sign-topic-main/examples/noisychannel/rerank_score_lm.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import os
from fairseq import options
from examples.noisychannel import rerank_options, rerank_utils
def score_lm(args):
using_nbest =... | 2,253 | 26.487805 | 77 | py |
sign-topic | sign-topic-main/examples/noisychannel/__init__.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 .rerank_options import * # noqa
| 216 | 30 | 65 | py |
sign-topic | sign-topic-main/examples/noisychannel/rerank.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 multiprocessing import Pool
import numpy as np
from fairseq import options
from fairseq.data import dictionary
from fairseq.... | 14,097 | 31.862471 | 107 | py |
sign-topic | sign-topic-main/examples/noisychannel/rerank_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.
from fairseq import options
def get_reranking_parser(default_task="translation"):
parser = options.get_parser("Generation and reranking"... | 7,537 | 49.253333 | 117 | py |
sign-topic | sign-topic-main/examples/noisychannel/rerank_tune.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 random
import numpy as np
from fairseq import options
from examples.noisychannel import rerank, rerank_options
def ... | 3,166 | 29.747573 | 86 | py |
sign-topic | sign-topic-main/examples/noisychannel/rerank_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 math
import os
import re
import subprocess
from contextlib import redirect_stdout
from fairseq import options
from fairseq_cli import ... | 28,678 | 32.700353 | 112 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/ulm/sample.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.
"""
Sample from a trained LM; hacked fairseq-interactive
"""
from collections import namedtuple
import os
import ast
... | 5,623 | 31.137143 | 103 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/tools/resynthesize_speech.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 gc
import logging
import os
import joblib
import soundfile as sf
import torch
from examples.textless_nlp.gslm.speech2u... | 4,183 | 30.458647 | 86 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/unit2speech/tts_data.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch
import numpy as np
from examples.textless_nlp.gslm.unit2speech.tacotron2.text import (
EOS_TOK,
SOS_TOK,
code_to_seq... | 1,733 | 30.527273 | 77 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/unit2speech/multiproc.py | import os
import time
import torch
import sys
import subprocess
argslist = list(sys.argv)[1:]
log_dir = argslist[-1]
num_gpus = torch.cuda.device_count()
argslist.append('--n_gpus={}'.format(num_gpus))
workers = []
job_id = time.strftime("%Y_%m_%d-%H%M%S")
argslist.append("--group_name=group_{}".format(job_id))
print... | 772 | 26.607143 | 84 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/unit2speech/utils.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch
from examples.textless_nlp.gslm.unit2speech.tacotron2.model import Tacotron2
from examples.textless_nlp.gslm.unit2speech.tacotro... | 1,904 | 33.017857 | 80 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/unit2speech/glow.py | # *****************************************************************************
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions... | 12,653 | 39.557692 | 105 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/unit2speech/synthesize_audio_from_units.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 os
import soundfile as sf
from examples.textless_nlp.gslm.unit2speech.tts_data import (
TacotronInp... | 3,178 | 28.990566 | 78 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/unit2speech/convert_to_16k.py | import os
import shlex
import subprocess
import progressbar
from time import time
from pathlib import Path
def find_all_files(path_dir, extension):
out = []
for root, dirs, filenames in os.walk(path_dir):
for f in filenames:
if f.endswith(extension):
out.append(((str(Path(f)... | 2,177 | 37.892857 | 96 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/unit2speech/tacotron2/stft.py | """
BSD 3-Clause License
Copyright (c) 2017, Prem Seetharaman
All rights reserved.
* Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of... | 5,893 | 40.507042 | 97 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/unit2speech/tacotron2/cleaners.py | """ from https://github.com/keithito/tacotron """
'''
Cleaners are transformations that run over the input text at both training and eval time.
Cleaners can be selected by passing a comma-delimited list of cleaner names as the "cleaners"
hyperparameter. Some cleaners are English-specific. You'll typically want to use... | 2,439 | 25.813187 | 95 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/unit2speech/tacotron2/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 io
import json
import librosa
import numpy as np
import soundfile as sf
import time
import torch
from scipy.io.wavfi... | 4,918 | 27.598837 | 79 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/unit2speech/tacotron2/model.py | from math import sqrt
import torch
import torch.distributions as distr
from torch.autograd import Variable
from torch import nn
from torch.nn import functional as F
from .layers import ConvNorm, LinearNorm, GlobalAvgPool
from .utils import to_gpu, get_mask_from_lengths
class LocationLayer(nn.Module):
def __init__... | 25,989 | 37.791045 | 82 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/unit2speech/tacotron2/layers.py | import torch
from librosa.filters import mel as librosa_mel_fn
from .audio_processing import dynamic_range_compression
from .audio_processing import dynamic_range_decompression
from .stft import STFT
from .utils import get_mask_from_lengths
class LinearNorm(torch.nn.Module):
def __init__(self, in_dim, out_dim, bi... | 3,859 | 36.115385 | 81 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/unit2speech/tacotron2/waveglow_denoiser.py | # import sys
# sys.path.append('tacotron2')
import torch
from .layers import STFT
class Denoiser(torch.nn.Module):
""" Removes model bias from audio produced with waveglow """
def __init__(self, waveglow, filter_length=1024, n_overlap=4,
win_length=1024, mode='zeros'):
super(Denoiser... | 1,610 | 38.292683 | 77 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/unit2speech/tacotron2/audio_processing.py | import torch
import numpy as np
from scipy.signal import get_window
import librosa.util as librosa_util
def window_sumsquare(window, n_frames, hop_length=200, win_length=800,
n_fft=800, dtype=np.float32, norm=None):
"""
# from librosa 0.6
Compute the sum-square envelope of a window fu... | 2,610 | 26.776596 | 83 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/unit2speech/tacotron2/text.py | """ from https://github.com/keithito/tacotron """
import numpy as np
import re
from . import cleaners
from .symbols import symbols
# Mappings from symbol to numeric ID and vice versa:
_symbol_to_id = {s: i for i, s in enumerate(symbols)}
_id_to_symbol = {i: s for i, s in enumerate(symbols)}
# Regular expression matc... | 3,075 | 27.481481 | 93 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/unit2speech/tacotron2/cmudict.py | """ from https://github.com/keithito/tacotron """
import re
valid_symbols = [
'AA', 'AA0', 'AA1', 'AA2', 'AE', 'AE0', 'AE1', 'AE2', 'AH', 'AH0', 'AH1', 'AH2',
'AO', 'AO0', 'AO1', 'AO2', 'AW', 'AW0', 'AW1', 'AW2', 'AY', 'AY0', 'AY1', 'AY2',
'B', 'CH', 'D', 'DH', 'EH', 'EH0', 'EH1', 'EH2', 'ER', 'ER0', 'ER1', 'E... | 1,979 | 29 | 86 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/unit2speech/tacotron2/numbers.py | """ from https://github.com/keithito/tacotron """
import inflect
import re
_inflect = inflect.engine()
_comma_number_re = re.compile(r'([0-9][0-9\,]+[0-9])')
_decimal_number_re = re.compile(r'([0-9]+\.[0-9]+)')
_pounds_re = re.compile(r'£([0-9\,]*[0-9]+)')
_dollars_re = re.compile(r'\$([0-9\.\,]*[0-9]+)')
_ordinal_r... | 2,167 | 29.111111 | 93 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/unit2speech/tacotron2/symbols.py | """ from https://github.com/keithito/tacotron """
'''
Defines the set of symbols used in text input to the model.
The default is a set of ASCII characters that works well for English or text that has been run through Unidecode. For other data, you can modify _characters. See TRAINING_DATA.md for details. '''
from . i... | 718 | 36.842105 | 195 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/unit2speech/tacotron2/__init__.py | 0 | 0 | 0 | py | |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/metrics/asr_metrics/ppx.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch
import numpy as np
import warnings
def get_target_sequences(manifest, ground_truth, to_take=1000):
import json
import ... | 3,692 | 29.02439 | 90 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/metrics/asr_metrics/self_auto_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 numpy as np
import nltk
from misc.bleu_utils import sentence_bleu
import warnings
def get_target_sequences(manifest, ground_truth, to... | 6,101 | 29.207921 | 86 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/metrics/asr_metrics/continuation_eval.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 numpy as np
from misc.bleu_utils import sentence_bleu
import json
import warnings
def get_args()... | 2,869 | 27.7 | 109 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/metrics/asr_metrics/misc/bleu_utils.py | """
TODO: the code is take from Apache-2 Licensed NLTK: make sure we do this properly!
Copied over from nltk.tranlate.bleu_score. This code has two major changes:
- allows to turn off length/brevity penalty --- it has no sense for self-bleu,
- allows to use arithmetic instead of geometric mean
"""
import math
imp... | 6,679 | 39.240964 | 112 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/metrics/asr_metrics/misc/cut_as.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 torchaudio
import argparse
import json
import pathlib
def get_args():
parser = argparse.ArgumentParser(
"Assuring genera... | 1,832 | 25.185714 | 78 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/metrics/abx_metrics/dump_abx_feats.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 os
import joblib
import numpy as np
from examples.textless_nlp.gslm.speech2unit.clustering.utils impor... | 3,329 | 29.833333 | 83 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/speech2unit/__init__.py | 0 | 0 | 0 | py | |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/speech2unit/clustering/quantize_with_kmeans.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 os
import numpy as np
import joblib
from examples.textless_nlp.gslm.speech2unit.clustering.utils impor... | 3,821 | 29.333333 | 110 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/speech2unit/clustering/cluster_kmeans.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 os
import time
import numpy as np
from sklearn.cluster import MiniBatchKMeans
import joblib
from examp... | 6,182 | 28.028169 | 79 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/speech2unit/clustering/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 typing import List, Tuple
def get_audio_files(manifest_path: str) -> Tuple[str, List[str], List[int]]:
fnames, sizes = [], []
w... | 701 | 32.428571 | 76 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/speech2unit/clustering/dump_feats.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
from examples.textless_nlp.gslm.speech2unit.pretrained.utils import (
get_and_dump_features,
)
def get_p... | 2,615 | 27.434783 | 109 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/speech2unit/clustering/__init__.py | 0 | 0 | 0 | py | |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/speech2unit/pretrained/hubert_feature_reader.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 fairseq
import soundfile as sf
import torch.nn.functional as F
class HubertFeatureReader:
"""
Wrapper class to r... | 1,912 | 30.883333 | 66 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/speech2unit/pretrained/w2v2_feature_reader.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 fairseq
import soundfile as sf
class Wav2VecFeatureReader:
"""
Wrapper class to run inference on Wav2Vec 2.0 mod... | 1,424 | 29.319149 | 79 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/speech2unit/pretrained/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 gc
import os
import random
import shutil
import numpy as np
import torch
import tqdm
from examples.textless_nlp.gslm.speech2unit.pretr... | 3,407 | 25.834646 | 85 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/speech2unit/pretrained/logmel_feature_reader.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 soundfile as sf
import torch
import torchaudio.compliance.kaldi as kaldi
class LogMelFeatureReader:
"""
Wrapper class to run ... | 905 | 28.225806 | 65 | py |
sign-topic | sign-topic-main/examples/textless_nlp/gslm/speech2unit/pretrained/cpc_feature_reader.py | import soundfile as sf
import torch
import torch.nn as nn
import torch.nn.functional as F
class CpcFeatureReader:
"""
Wrapper class to run inference on CPC model.
Helps extract features for a given audio file.
"""
def __init__(
self,
checkpoint_path,
layer,
use_enc... | 6,525 | 32.813472 | 82 | py |
sign-topic | sign-topic-main/examples/paraphraser/paraphrase.py | #!/usr/bin/env python3 -u
import argparse
import fileinput
import logging
import os
import sys
from fairseq.models.transformer import TransformerModel
logging.getLogger().setLevel(logging.INFO)
def main():
parser = argparse.ArgumentParser(description="")
parser.add_argument("--en2fr", required=True, help=... | 2,408 | 27.011628 | 85 | py |
sign-topic | sign-topic-main/examples/discriminative_reranking_nmt/drnmt_rerank.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.
"""
Score raw text with a trained model.
"""
from collections import namedtuple
import logging
from multiprocessing ... | 11,312 | 29.994521 | 144 | py |
sign-topic | sign-topic-main/examples/discriminative_reranking_nmt/__init__.py | from . import criterions, models, tasks # noqa
| 48 | 23.5 | 47 | py |
sign-topic | sign-topic-main/examples/discriminative_reranking_nmt/criterions/discriminative_reranking_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
from dataclasses import dataclass, field
import torch
import torch.nn.functional as F
from fairseq import metrics, utils
from fa... | 4,997 | 34.956835 | 157 | py |
sign-topic | sign-topic-main/examples/discriminative_reranking_nmt/criterions/__init__.py | from .discriminative_reranking_criterion import KLDivergenceRerankingCriterion
__all__ = [
"KLDivergenceRerankingCriterion",
]
| 133 | 18.142857 | 78 | py |
sign-topic | sign-topic-main/examples/discriminative_reranking_nmt/models/discriminative_reranking_model.py | from dataclasses import dataclass, field
import os
import torch
import torch.nn as nn
from fairseq import utils
from fairseq.dataclass import ChoiceEnum, FairseqDataclass
from fairseq.models import (
BaseFairseqModel,
register_model,
)
from fairseq.models.roberta.model import RobertaClassificationHead
from ... | 13,714 | 36.472678 | 112 | py |
sign-topic | sign-topic-main/examples/discriminative_reranking_nmt/models/__init__.py | from .discriminative_reranking_model import DiscriminativeNMTReranker
__all__ = [
"DiscriminativeNMTReranker",
]
| 119 | 16.142857 | 69 | py |
sign-topic | sign-topic-main/examples/discriminative_reranking_nmt/scripts/prep_data.py | #!/usr/bin/env python
import argparse
from multiprocessing import Pool
from pathlib import Path
import sacrebleu
import sentencepiece as spm
def read_text_file(filename):
with open(filename, "r") as f:
output = [line.strip() for line in f]
return output
def get_bleu(in_sent, target_sent):
ble... | 4,872 | 34.569343 | 142 | py |
sign-topic | sign-topic-main/examples/discriminative_reranking_nmt/tasks/discriminative_reranking_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.
from dataclasses import dataclass, field
import itertools
import logging
import os
import numpy as np
import torch
from fairseq import metr... | 17,491 | 35.747899 | 96 | py |
sign-topic | sign-topic-main/examples/discriminative_reranking_nmt/tasks/__init__.py | from .discriminative_reranking_task import DiscriminativeRerankingNMTTask
__all__ = [
"DiscriminativeRerankingNMTTask",
]
| 128 | 17.428571 | 73 | py |
sign-topic | sign-topic-main/examples/pointer_generator/preprocess.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
from itertools import zip_longest
def replace_oovs(source_in, target_in, vocabulary, source_out, targ... | 3,337 | 31.407767 | 85 | py |
sign-topic | sign-topic-main/examples/pointer_generator/postprocess.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 re
import sys
class OOVIndexError(IndexError):
def __init__(self, pos, source_seq, target_... | 3,266 | 32.680412 | 85 | py |
sign-topic | sign-topic-main/examples/pointer_generator/pointer_generator_src/__init__.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 . import transformer_pg # noqa
| 215 | 29.857143 | 65 | py |
sign-topic | sign-topic-main/examples/pointer_generator/pointer_generator_src/transformer_pg.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
from typing import Any, Dict, Optional, List, Tuple
import torch
import torch.nn as nn
from fairseq import utils
from fairseq.... | 23,439 | 44.163776 | 102 | py |
sign-topic | sign-topic-main/examples/speech_text_joint_to_text/__init__.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 . import tasks, criterions, models # noqa
| 226 | 31.428571 | 65 | py |
sign-topic | sign-topic-main/examples/speech_text_joint_to_text/criterions/text_guide_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.
import math
import torch
import torch.nn.functional as F
from fairseq.criterions import FairseqCriterion, register_criterion
from fairseq.crit... | 11,004 | 48.129464 | 139 | py |
sign-topic | sign-topic-main/examples/speech_text_joint_to_text/criterions/__init__.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 importlib
import os
for file in os.listdir(os.path.dirname(__file__)):
if file.endswith(".py") and not file.startswith("_"):
... | 487 | 29.5 | 77 | py |
sign-topic | sign-topic-main/examples/speech_text_joint_to_text/models/s2t_dualinputtransformer.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
from collections import namedtuple
import torch
import torch.nn as nn
from fairseq import checkpoint_utils
from fairseq import... | 45,047 | 40.177331 | 128 | py |
sign-topic | sign-topic-main/examples/speech_text_joint_to_text/models/s2t_dualinputxmtransformer.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 copy
import torch.nn as nn
from fairseq import checkpoint_utils
from fairseq import utils
from fairseq.data.data_utils import lengths_... | 21,461 | 35.687179 | 88 | py |
sign-topic | sign-topic-main/examples/speech_text_joint_to_text/models/__init__.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 importlib
import os
| 206 | 22 | 65 | py |
sign-topic | sign-topic-main/examples/speech_text_joint_to_text/scripts/g2p_encode.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 itertools
import logging
import re
import time
from g2p_en import G2p
logger = logging.getLogger(__name__)
FAIL_SENT... | 5,840 | 29.421875 | 88 | py |
sign-topic | sign-topic-main/examples/speech_text_joint_to_text/tasks/speech_text_joint.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
from argparse import Namespace
from pathlib import Path
import torch
from fairseq.data import (
encoders,
Dic... | 13,654 | 35.124339 | 88 | py |
sign-topic | sign-topic-main/examples/speech_text_joint_to_text/tasks/__init__.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 importlib
import os
| 206 | 22 | 65 | py |
sign-topic | sign-topic-main/examples/constrained_decoding/tok.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 sys
import sacremoses
def main(args):
"""Tokenizes, preserving tabs"""
mt = sacremoses.MosesTokeniz... | 844 | 23.142857 | 68 | py |
sign-topic | sign-topic-main/examples/constrained_decoding/normalize.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 sys
from sacremoses.normalize import MosesPunctNormalizer
def main(args):
normalizer = MosesPunctNormal... | 698 | 23.964286 | 69 | py |
sign-topic | sign-topic-main/examples/rxf/__init__.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 . import rxf_src # noqa
| 208 | 28.857143 | 65 | py |
sign-topic | sign-topic-main/examples/rxf/rxf_src/label_smoothed_cross_entropy_r3f.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 metrics, utils
from fairseq.criterions import FairseqCriterion, ... | 6,109 | 37.670886 | 91 | py |
sign-topic | sign-topic-main/examples/rxf/rxf_src/__init__.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 . import label_smoothed_cross_entropy_r3f, sentence_prediction_r3f # noqa
| 258 | 36 | 79 | py |
sign-topic | sign-topic-main/examples/rxf/rxf_src/sentence_prediction_r3f.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.criterions import FairseqCriterion, register_... | 6,587 | 37.302326 | 96 | py |
sign-topic | sign-topic-main/examples/megatron_11b/detok.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 fileinput
import sacremoses
def main():
parser = argparse.ArgumentParser(description="... | 821 | 23.909091 | 80 | py |
sign-topic | sign-topic-main/scripts/count_docs.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.
"""
Count the number of documents and average number of lines and tokens per
document in a large file. Documents should ... | 1,784 | 29.254237 | 79 | py |
sign-topic | sign-topic-main/scripts/read_binarized.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
from fairseq.data import Dictionary, data_utils, indexed_dataset
def get_parser():
parser = argp... | 1,370 | 26.979592 | 103 | py |
sign-topic | sign-topic-main/scripts/compare_namespaces.py | #!/usr/bin/env python
"""Helper script to compare two argparse.Namespace objects."""
from argparse import Namespace # noqa
def main():
ns1 = eval(input("Namespace 1: "))
ns2 = eval(input("Namespace 2: "))
def keys(ns):
ks = set()
for k in dir(ns):
if not k.startswith("_"):
... | 1,090 | 22.212766 | 88 | py |
sign-topic | sign-topic-main/scripts/split_train_valid_docs.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.
"""
Split a large file into a train and valid set while respecting document
boundaries. Documents should be separated by... | 2,551 | 28.333333 | 74 | py |
sign-topic | sign-topic-main/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 os
import re
import torch
from fairseq.file_io import PathManager
def aver... | 6,075 | 36.73913 | 126 | py |
sign-topic | sign-topic-main/scripts/build_sym_alignment.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.
"""
Use this script in order to build symmetric alignments for your translation
dataset.
This script depends on fast_align and mosesdecoder too... | 3,796 | 37.744898 | 88 | py |
sign-topic | sign-topic-main/scripts/spm_decode.py | #!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the 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 argparse
... | 1,520 | 27.166667 | 83 | py |
sign-topic | sign-topic-main/scripts/rm_pt.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 os
import re
import shutil
import sys
pt_regexp = re.compile(r"checkpoint(\d+|_\d+_\d+|_[a-z]+... | 4,740 | 32.387324 | 96 | py |
sign-topic | sign-topic-main/scripts/__init__.py | 0 | 0 | 0 | py | |
sign-topic | sign-topic-main/scripts/spm_train.py | #!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the 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 sys
impor... | 431 | 24.411765 | 82 | py |
sign-topic | sign-topic-main/scripts/shard_docs.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.
"""
Split a large file into shards while respecting document boundaries. Documents
should be separated by a single empty... | 1,616 | 28.4 | 79 | py |
sign-topic | sign-topic-main/scripts/spm_encode.py | #!/usr/bin/env python
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the 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 argparse
i... | 3,432 | 27.608333 | 84 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.