repo
stringclasses
454 values
file_path
stringlengths
5
201
extension
stringclasses
1 value
content
stringlengths
8
509k
num_lines
int64
3
16.9k
size_bytes
int64
8
511k
fairseq
examples/data2vec/models/modalities/base.py
.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 math import numpy as np import torch import torch.nn as nn import torch.nn.functional as F from collections import named...
685
22,253
fairseq
examples/paraphraser/paraphrase.py
.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=...
86
2,408
fairseq
examples/speech_to_speech/generate_waveform_from_code.py
.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 json import logging from pathlib import Path import random import soundfile as sf import torch from tqdm import tqdm ...
117
3,285
fairseq
examples/speech_to_speech/preprocessing/prep_s2ut_data.py
.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 logging from pathlib import Path import soundfile as sf from tqdm import tqdm import pandas as ...
115
3,554
fairseq
examples/speech_to_speech/preprocessing/prep_sn_output_data.py
.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 pathlib import Path from tqdm import tqdm def process(args): args.output_root.mkdir(exist_o...
59
1,455
fairseq
examples/speech_to_speech/preprocessing/prep_s2spect_data.py
.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 logging import os from pathlib import Path import shutil import torchaudio import soundfile as ...
170
5,844
fairseq
examples/speech_to_speech/preprocessing/prep_sn_data.py
.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. # # Adapted from examples/wav2vec/wav2vec_manifest.py """ Data preparation for the speech normalizer """ import argpars...
89
2,735
fairseq
examples/speech_to_speech/preprocessing/data_utils.py
.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 pathlib import Path from typing import List, Optional from examples.speech_to_text.data_utils import S2TDataConfigWriter def gen_confi...
89
2,592
fairseq
examples/speech_to_speech/benchmarking/get_metrics.py
.py
import copy import torch import logging from argparse import Namespace import yaml from fairseq import options from examples.speech_to_speech.benchmarking.core import ( Processing, SpeechGeneration, Cascaded2StageS2ST, Cascaded3StageS2ST, S2UT, ) from examples.speech_to_speech.benchmarking.data_util...
163
5,053
fairseq
examples/speech_to_speech/benchmarking/data_utils.py
.py
from fairseq import tasks import numpy as np import logging import random from fairseq import options import torch import os import soundfile as sf from fairseq.data.audio.audio_utils import ( get_waveform, parse_path, ) logging.basicConfig() logging.root.setLevel(logging.INFO) logging.basicConfig(level=loggi...
265
7,893
fairseq
examples/speech_to_speech/benchmarking/core.py
.py
import timeit import logging import torch from pypapi import events, papi_high as high from memory_profiler import memory_usage from torch import nn from argparse import Namespace from fairseq.dataclass.utils import convert_namespace_to_omegaconf from fairseq.data import data_utils as fairseq_data_utils from fairseq im...
488
17,782
fairseq
examples/speech_to_speech/unity/sequence_generator_multi_decoder.py
.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 torch import torch.nn as nn from torch import Tensor from fairseq import search class Multi...
268
10,097
fairseq
examples/speech_to_speech/unity/sequence_generator.py
.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 sys from typing import Dict, List, Optional import torch from torch import Tensor from fairseq.sequence_generator import ...
627
25,480
fairseq
examples/speech_to_speech/asr_bleu/utils.py
.py
import json import re import urllib.request from pathlib import Path import fairseq import torch from fairseq.data.data_utils import lengths_to_padding_mask from tqdm import tqdm try: import torchaudio from torchaudio.models.decoder import ctc_decoder except ImportError: raise ImportError("Upgrade torchau...
307
10,133
fairseq
examples/speech_to_speech/asr_bleu/compute_asr_bleu.py
.py
import os from typing import Dict, List import sacrebleu import pandas as pd from glob import glob from pathlib import Path from utils import retrieve_asr_config, ASRGenerator from tqdm import tqdm from argparse import ArgumentParser def merge_tailo_init_final(text): """ Hokkien ASR hypothesis post-processing...
245
8,273
fairseq
examples/adaptive_span/adaptive_span_loss.py
.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 import torch.nn.functional as F from fairseq import utils from fairseq.logging import metrics f...
108
4,260
fairseq
examples/adaptive_span/adaptive_span_attention.py
.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 class AdaptiveMask(nn.Module): """Soft masking function f...
161
5,881
fairseq
examples/adaptive_span/__init__.py
.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 current directory cur_dir = os.path.dirname(__file__) for file in o...
20
669
fairseq
examples/adaptive_span/adaptive_span_model_wrapper.py
.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 dataclasses import dataclass from typing import Dict, List, Optional import torch from fairseq.dataclass import FairseqDa...
146
4,692
fairseq
examples/adaptive_span/adagrad_with_grad_clip.py
.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 torch.optim import Adagrad from fairseq.optim import LegacyFairseqOptimizer, register_optimizer @register_optimizer("adagrad_with_grad...
129
4,374
fairseq
examples/adaptive_span/adaptive_span_model.py
.py
# 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. import math import torch import torch.nn as nn import torch.nn.functional as F from fairseq.modules.layer_norm import Lay...
264
8,540
fairseq
examples/simultaneous_translation/eval/agents/simul_t2t_enja.py
.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 checkpoint_utils, tasks import sentencepiece as spm import torch try: from simuleval import READ_ACTION, W...
227
7,099
fairseq
examples/simultaneous_translation/tests/test_alignment_train.py
.py
import unittest import numpy as np import torch import hypothesis.strategies as st from hypothesis import assume, given, settings from torch.testing._internal.common_utils import TestCase from examples.simultaneous_translation.utils.functions import exclusive_cumprod TEST_CUDA = torch.cuda.is_available() class Al...
89
2,989
fairseq
examples/simultaneous_translation/tests/test_text_models.py
.py
import argparse import unittest from typing import Any, Dict import torch from examples.simultaneous_translation.models import ( transformer_monotonic_attention ) from tests.test_roberta import FakeTask DEFAULT_CONFIG = { "attention_eps": 1e-6, "mass_preservation": True, "noise_type": "flat", "...
408
13,537
fairseq
examples/simultaneous_translation/utils/p_choose_strategy.py
.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_...
127
3,445
fairseq
examples/simultaneous_translation/utils/monotonic_attention.py
.py
from typing import Optional import torch from torch import Tensor from examples.simultaneous_translation.utils.functions import ( exclusive_cumprod, prob_check, moving_sum, ) def expected_alignment_from_p_choose( p_choose: Tensor, padding_mask: Optional[Tensor] = None, eps: float = 1e-6 ): ...
181
4,987
fairseq
examples/simultaneous_translation/utils/__init__.py
.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...
15
520
fairseq
examples/simultaneous_translation/utils/functions.py
.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." ) ...
126
3,539
fairseq
examples/simultaneous_translation/modules/monotonic_transformer_layer.py
.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.modules import TransformerDecoderLayer, TransformerEncoderLayer from . import build_monotonic_attention from typing import Dict...
183
7,265
fairseq
examples/simultaneous_translation/modules/__init__.py
.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 importlib from fairseq import registry ( build_monotonic_attention, register_monotonic_attention, MONOTONIC_ATT...
24
665
fairseq
examples/simultaneous_translation/modules/monotonic_multihead_attention.py
.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 Tensor import torch.nn as nn from examples.simultaneous_translation.utils.p_choose_strategy impor...
521
16,898
fairseq
examples/simultaneous_translation/modules/fixed_pre_decision.py
.py
from functools import partial import torch from torch import Tensor import math import torch.nn.functional as F from . import register_monotonic_attention from .monotonic_multihead_attention import ( MonotonicAttention, MonotonicInfiniteLookbackAttention, WaitKAttention ) from typing import Dict, Optional...
191
7,370
fairseq
examples/simultaneous_translation/models/transformer_monotonic_attention.py
.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, NamedTuple, Optional import torch import torch.nn as nn from examples.simultaneous_translation.modules.monoton...
303
10,185
fairseq
examples/simultaneous_translation/models/__init__.py
.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 sorted(os.listdir(os.path.dirname(__file__))): if file.endswith(".py") and not file.startswith("_...
16
482
fairseq
examples/simultaneous_translation/models/convtransformer_simul_trans.py
.py
# Copyright (c) 2017-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the LICENSE file in # the root directory of this source tree. An additional grant of patent rights # can be found in the PATENTS file in the same directory. from fairseq import checkpoint_uti...
205
7,162
fairseq
examples/constrained_decoding/normalize.py
.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...
28
698
fairseq
examples/constrained_decoding/tok.py
.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...
35
844
fairseq
examples/criss/save_encoder.py
.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 numpy as np import torch from fairseq import check...
215
7,473
fairseq
examples/criss/sentence_retrieval/encoder_analysis.py
.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 glob import numpy as np DIM = 1024 def compute_dist(source_embs, target_embs, k=5, return...
93
3,278
fairseq
examples/criss/mining/mine.py
.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 glob from subprocess import check_call try: import faiss has_faiss = True except Imp...
241
8,138
fairseq
examples/speech_to_text/prep_mtedx_data.py
.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 logging import os from pathlib import Path import shutil from itertools import groupby from temp...
272
10,168
fairseq
examples/speech_to_text/seg_mustc_data.py
.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 logging from pathlib import Path import soundfile as sf from examples.speech_to_text.prep_mustc_...
55
1,645
fairseq
examples/speech_to_text/prep_covost_data.py
.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 logging from pathlib import Path import shutil from tempfile import NamedTemporaryFile from typi...
280
8,909
fairseq
examples/speech_to_text/prep_mustc_data.py
.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 logging import os from pathlib import Path import shutil from itertools import groupby from temp...
295
11,080
fairseq
examples/speech_to_text/prep_librispeech_data.py
.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 logging from pathlib import Path import shutil from tempfile import NamedTemporaryFile import p...
120
3,623
fairseq
examples/speech_to_text/data_utils.py
.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 csv from pathlib import Path import zipfile from functools import reduce from multiprocessing import cpu_count from typing import Any, ...
384
12,272
fairseq
examples/speech_to_text/simultaneous_translation/agents/fairseq_simul_st_agent.py
.py
import math import os import json import numpy as np import torch import torchaudio.compliance.kaldi as kaldi import yaml from fairseq import checkpoint_utils, tasks from fairseq.file_io import PathManager try: from simuleval import READ_ACTION, WRITE_ACTION, DEFAULT_EOS from simuleval.agents import SpeechAgen...
364
12,193
fairseq
examples/noisychannel/rerank_score_bw.py
.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...
144
4,212
fairseq
examples/noisychannel/rerank_generate.py
.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...
398
14,157
fairseq
examples/noisychannel/rerank.py
.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....
429
14,097
fairseq
examples/noisychannel/rerank_utils.py
.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 ...
851
28,678
fairseq
examples/noisychannel/rerank_score_lm.py
.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 =...
82
2,253
fairseq
examples/noisychannel/rerank_options.py
.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"...
150
7,537
fairseq
examples/noisychannel/rerank_tune.py
.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 ...
103
3,166
fairseq
examples/mms/lid/infer.py
.py
import torch from fairseq.data.text_compressor import TextCompressionLevel, TextCompressor from fairseq import checkpoint_utils, distributed_utils, options, utils from fairseq import checkpoint_utils, data, options, tasks from fairseq.data import FileAudioDataset, AddTargetDataset, Dictionary from fairseq.tasks.audio_c...
198
7,071
fairseq
examples/mms/data_prep/align_and_segment.py
.py
import os import torch import torchaudio import sox import json import argparse from examples.mms.data_prep.text_normalization import text_normalize from examples.mms.data_prep.align_utils import ( get_uroman_tokens, time_to_frame, load_model_dict, merge_repeats, get_spans, ) import torchaudio.fun...
193
6,168
fairseq
examples/mms/data_prep/norm_config.py
.py
import os import re colon = ":" comma = "," exclamation_mark = "!" period = re.escape(".") question_mark = re.escape("?") semicolon = ";" left_curly_bracket = "{" right_curly_bracket = "}" quotation_mark = '"' basic_punc = ( period + question_mark + comma + colon + exclamation_mark + left_cu...
278
6,532
fairseq
examples/mms/data_prep/align_utils.py
.py
import re import os import torch import tempfile import math from dataclasses import dataclass from torchaudio.models import wav2vec2_model # iso codes with specialized rules in uroman special_isos_uroman = "ara, bel, bul, deu, ell, eng, fas, grc, ell, eng, heb, kaz, kir, lav, lit, mkd, mkd2, oss, pnt, pus, rus, srp,...
177
5,656
fairseq
examples/mms/data_prep/text_normalization.py
.py
import json import re import unicodedata from examples.mms.data_prep.norm_config import norm_config def text_normalize(text, iso_code, lower_case=True, remove_numbers=True, remove_brackets=False): """Given a text, normalize it by changing to lower case, removing punctuations, removing words that only contain di...
93
2,779
fairseq
examples/mms/lid_rerank/mms-zs/falign.py
.py
import os import tempfile import re import librosa import torch import json import numpy as np import argparse from tqdm import tqdm import math from transformers import Wav2Vec2ForCTC, AutoProcessor from lib import falign_ext parser = argparse.ArgumentParser() parser.add_argument("--uroman_txt", type=str) parser.ad...
87
2,515
fairseq
examples/mms/lid_rerank/mms-zs/lib.py
.py
import os from dataclasses import dataclass import torch import torch.utils.cpp_extension cuda_source = """ #include <ATen/core/TensorAccessor.h> #include <ATen/cuda/CUDAContext.h> #include <torch/extension.h> #include <vector> #include <limits.h> #include <cub/cub.cuh> #include <iostream> using namespace torch::ind...
239
7,559
fairseq
examples/mms/lid_rerank/mms-zs/uromanize.py
.py
import os import tempfile import re import argparse from tqdm import tqdm parser = argparse.ArgumentParser() parser.add_argument("--txt", type=str) parser.add_argument("--lid", type=str) parser.add_argument("--dst", type=str) parser.add_argument("--model", type=str) args = parser.parse_args() UROMAN_PL = args.model +...
70
2,106
fairseq
examples/mms/lid_rerank/nllb/infer.py
.py
#!/usr/bin/env python3 # -*- encoding: utf8 -*- import fasttext from tqdm import tqdm import argparse import os import math parser = argparse.ArgumentParser() parser.add_argument("--txt", type=str) parser.add_argument("--dst", type=str) parser.add_argument("--model", type=str) parser.add_argument('--lid', type=str) ar...
46
1,478
fairseq
examples/mms/lid_rerank/rerank/tune_coefficients.py
.py
import argparse import os from tqdm import tqdm import numpy as np import editdistance from multiprocessing import Pool from functools import partial cer_langs = [x.strip() for x in open("cer_langs.txt", "r").readlines()] def compute(w, feats, ref_lid, nbest_lid, ref_asr, nbest_asr, n=10, exclude=None): assert le...
138
5,337
fairseq
examples/mms/lid_rerank/rerank/rerank.py
.py
import argparse import json from collections import defaultdict import os from tqdm import tqdm import sys import subprocess import re import math import numpy as np import editdistance from sklearn.preprocessing import StandardScaler from multiprocessing import Pool from functools import partial import random cer_lan...
133
4,709
fairseq
examples/mms/lid_rerank/mms/prep_wav_list.py
.py
import soundfile as sf import argparse if __name__ == "__main__": parser = argparse.ArgumentParser(description='Example argument parser') parser.add_argument('--src', type=str) parser.add_argument('--dst', type=str) args = parser.parse_args() wavs = [x.strip() for x in open(args.src, "r").readline...
24
674
fairseq
examples/mms/lid_rerank/mms/run_single_lang.py
.py
import argparse import json from collections import defaultdict import os from tqdm import tqdm import sys import subprocess import re mapping = {"cmn":"cmn-script_simplified", "srp":"srp-script_latin", "urd":"urd-script_arabic", "uzb":"uzb-script_latin", "yue":"yue-script_traditional", "aze":"azj-script_latin", "kmr"...
65
2,922
fairseq
examples/mms/lid_rerank/mms/make_parallel_single_runs.py
.py
import argparse import json from collections import defaultdict import os from tqdm import tqdm import sys import subprocess import re if __name__ == "__main__": parser = argparse.ArgumentParser(description='Example argument parser') parser.add_argument('--dump', type=str) parser.add_argument('--model', ty...
22
794
fairseq
examples/mms/lid_rerank/mms/merge_by_lang.py
.py
import argparse import json from collections import defaultdict import os import soundfile as sf from tqdm import tqdm if __name__ == "__main__": parser = argparse.ArgumentParser(description='Example argument parser') parser.add_argument('--exp', type=str) parser.add_argument('--dump', type=str) args =...
33
1,294
fairseq
examples/mms/lid_rerank/mms/split_by_lang.py
.py
import argparse import json from collections import defaultdict import os import soundfile as sf from tqdm import tqdm if __name__ == "__main__": parser = argparse.ArgumentParser(description='Example argument parser') parser.add_argument('--wavs_tsv', type=str) parser.add_argument('--lid_preds', type=str) ...
90
3,284
fairseq
examples/mms/lid_rerank/mala/infer.py
.py
from transformers import AutoTokenizer, AutoModelForCausalLM from peft import PeftModel from tqdm import tqdm import argparse import os import torch parser = argparse.ArgumentParser() parser.add_argument("--txt", type=str) parser.add_argument("--dst", type=str) parser.add_argument("--gpu", type=int, default=1) args = ...
55
2,055
fairseq
examples/mms/lid_rerank/whisper/infer_lid.py
.py
#!/usr/bin/env python3 # -*- encoding: utf8 -*- import argparse import itertools import os import re import sys from pathlib import Path import math import whisper from tqdm import tqdm parser = argparse.ArgumentParser() parser.add_argument("--wavs", type=str) parser.add_argument("--dst", type=str) parser.add_argum...
65
2,072
fairseq
examples/mms/lid_rerank/whisper/infer_asr.py
.py
#!/usr/bin/env python3 # -*- encoding: utf8 -*- import argparse import itertools import os import re import sys from pathlib import Path import whisper from tqdm import tqdm parser = argparse.ArgumentParser() parser.add_argument("--wavs", type=str) parser.add_argument("--lids", type=str) parser.add_argument("--dst"...
71
2,260
fairseq
examples/mms/tts/infer.py
.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 re import glob import json import tempfile import math import torch from torch import nn from torch.nn import functional as F...
156
5,802
fairseq
examples/mms/asr/infer/mms_infer.py
.py
#!/usr/bin/env python -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 soundfile as sf import tempfile from pathlib import Path import os import subprocess import sy...
64
2,835
fairseq
examples/mms/misc/get_sample_size.py
.py
#!/usr/bin/env python -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. """ Usage: $ python misc/get_sample_size.py <input_file> > <output_file> <input_file> contains list of w...
30
808
fairseq
examples/hubert/measure_teacher_quality.py
.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 os.path as op import re from tabulate import tabulate from collections import Counter def comp_purity(p_xy, axis):...
242
6,826
fairseq
examples/hubert/update_ckpt.py
.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 src_ckpt = "/checkpoint/wnhsu/w2v/archived/hubert_base_ls960_it2.pt" ref_ckpt = "/checkpoint/wnhsu/w2v/hubert_icassp_oss_v3/iter...
23
873
fairseq
examples/hubert/simple_kmeans/dump_w2v2_feature.py
.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 sys import fairseq import soundfile as sf import torch import torch.nn.functional as F from feature_utils im...
96
3,129
fairseq
examples/hubert/simple_kmeans/dump_hubert_feature_s2t.py
.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 csv import io import logging import os import os.path as op import sys from dump_hubert_feature import HubertFeatureReader from featur...
96
2,775
fairseq
examples/hubert/simple_kmeans/learn_kmeans.py
.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 sys import numpy as np from sklearn.cluster import MiniBatchKMeans import joblib logging.basicConfig( f...
147
4,000
fairseq
examples/hubert/simple_kmeans/feature_utils.py
.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 sys import tqdm from npy_append_array import NpyAppendArray logging.basicConfig( format="%(asctime)s | ...
67
2,008
fairseq
examples/hubert/simple_kmeans/dump_hubert_feature.py
.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 sys import fairseq import soundfile as sf import torch import torch.nn.functional as F from feature_utils im...
94
3,120
fairseq
examples/hubert/simple_kmeans/dump_mfcc_feature.py
.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 sys import soundfile as sf import torch import torchaudio from feature_utils import get_path_iterator, dump_...
75
2,495
fairseq
examples/hubert/simple_kmeans/dump_km_label.py
.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 sys import numpy as np import joblib import torch import tqdm logging.basicConfig( format="%(asctime)s ...
99
3,008
fairseq
examples/fast_noisy_channel/noisy_channel_sequence_generator.py
.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...
843
41,200
fairseq
examples/fast_noisy_channel/noisy_channel_beam_search.py
.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...
72
2,895
fairseq
examples/fast_noisy_channel/noisy_channel_translation.py
.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...
128
6,709
fairseq
examples/backtranslation/extract_bt_data.py
.py
#!/usr/bin/env python # 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 from tqdm import tqdm def main(): parser = argparse.ArgumentParser( desc...
73
2,509
fairseq
examples/backtranslation/deduplicate_lines.py
.py
#!/usr/bin/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 fileinput import hashlib import sys from multiprocessing import Pool def get_hashes_and_lines(raw_...
42
1,221
fairseq
examples/linformer/linformer_src/modules/multihead_linear_attention.py
.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, Optional, Tuple import torch import torch.nn.functional as F from fairseq import utils from fairseq.incr...
482
19,151
fairseq
examples/linformer/linformer_src/modules/linformer_sentence_encoder_layer.py
.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 utils from fairseq.modules import TransformerEncoderLayer from .multihead_linear_attention import MultiheadL...
66
2,743
fairseq
examples/linformer/linformer_src/modules/linformer_sentence_encoder.py
.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.nn as nn from fairseq.models.transformer import TransformerEncoder from .linformer_sentence_encoder_layer import Li...
55
2,151
fairseq
examples/linformer/linformer_src/models/linformer_roberta.py
.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. """ Linformer: Self-Attention with Linear Complexity """ import logging import torch from fairseq import utils from fairseq.models import reg...
121
4,143
fairseq
examples/audio_nlp/nlu/generate_manifests.py
.py
import argparse from pathlib import Path import soundfile def get_insl_frame(parse): out = [] def is_ont_token(tok): return tok[0] in ["[", "]"]; res = [] x = [] for tok in parse.split(): if is_ont_token(tok): res.extend('_'.join(x)) x = [] res.a...
84
2,574
fairseq
examples/speech_text_joint_to_text/tasks/speech_text_denoise_pretrain.py
.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 re from argparse import Namespace from pathlib import Path from fairseq.data import ConcatDataset, Dictionary,...
655
25,554
fairseq
examples/speech_text_joint_to_text/tasks/speech_text_joint.py
.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...
378
13,654
fairseq
examples/speech_text_joint_to_text/tasks/pair_denoising.py
.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 itertools import logging import os import re import numpy as np import torch from examples.speech_text_joint_to_text.data.pair_denois...
448
15,550
fairseq
examples/speech_text_joint_to_text/criterions/__init__.py
.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("_"): ...
16
487
fairseq
examples/speech_text_joint_to_text/criterions/multi_modality_compound.py
.py
# # 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 math from dataclasses import dataclass, field from fairseq import utils from fairseq.logging import metrics from fairseq.criterions import FairseqCriterion, register_crite...
182
6,513