python_code stringlengths 0 992k | repo_name stringlengths 8 46 | file_path stringlengths 5 162 |
|---|---|---|
#!/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... | KosmosX-API-main | kosmosX/fairseq/examples/speech_to_text/prep_mustc_data.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... | KosmosX-API-main | kosmosX/fairseq/examples/speech_to_text/prep_mtedx_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 csv
from pathlib import Path
import zipfile
from functools import reduce
from multiprocessing import cpu_count
from typing import Any, ... | KosmosX-API-main | kosmosX/fairseq/examples/speech_to_text/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 argparse
import logging
from pathlib import Path
import shutil
from tempfile import NamedTemporaryFile
import p... | KosmosX-API-main | kosmosX/fairseq/examples/speech_to_text/prep_librispeech_data.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... | KosmosX-API-main | kosmosX/fairseq/examples/speech_to_text/simultaneous_translation/agents/fairseq_simul_st_agent.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.
# Use: echo {text} | python tokenize_indic.py {language}
import sys
from indicnlp.normalize.indic_normalize import In... | KosmosX-API-main | kosmosX/fairseq/examples/m2m_100/tokenizers/tokenize_indic.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 pythainlp import word_tokenize
for line in sys.stdin:
print(" ".join(word_tokenize(line.strip())... | KosmosX-API-main | kosmosX/fairseq/examples/m2m_100/tokenizers/tokenize_thai.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 fileinput
import sacrebleu
for line in fileinput.input():
print(sacrebleu.tokenize_zh(line))
| KosmosX-API-main | kosmosX/fairseq/examples/m2m_100/tokenizers/tokenize_zh.py |
import argparse
from collections import namedtuple
import os
DATADIR = "/path/to/train_data"
DEDUP_FROM_DIR = "/path/to/eval/data"
OUTPUT_DIR = "/path/to/output/data"
def main(args):
languages = set()
for language_directory in os.listdir(DATADIR):
if "_" in language_directory:
src, tgt = ... | KosmosX-API-main | kosmosX/fairseq/examples/m2m_100/process_data/dedup_data.py |
import gzip
import argparse
from string import punctuation
def len_no_punc(s, punc):
return len([ch for ch in s if ch in punc])
def filter_overpunc(len_npunc, len_sen):
return len_npunc < 0.5*len_sen
def main(args):
punc = punctuation + "—|–"
print('Processing file {}'.format(args.input))
with gz... | KosmosX-API-main | kosmosX/fairseq/examples/m2m_100/process_data/remove_too_much_punc.py |
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--src', type=str, help='Source language')
parser.add_argument('--tgt', type=str, help='Target language')
parser.add_argument('--src-file', type=str, help='Input source file')
parser.add_argument('--tgt-file', type=str, help='Input target file')
pa... | KosmosX-API-main | kosmosX/fairseq/examples/m2m_100/process_data/clean_histogram.py |
#!/usr/bin/env python3 -u
import argparse
import fileinput
import logging
import os
from fairseq.models.transformer import TransformerModel
logging.getLogger().setLevel(logging.INFO)
def main():
parser = argparse.ArgumentParser(description="")
parser.add_argument("--en2fr", required=True, help="path to en... | KosmosX-API-main | kosmosX/fairseq/examples/paraphraser/paraphrase.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 sys
import numpy as np
aggregate_funcs = {
"std": np.std,
"var": np.var,
"median": np.median,
"mean"... | KosmosX-API-main | kosmosX/fairseq/examples/unsupervised_quality_estimation/aggregate_scores.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 sys
def _normalize_spaces(line):
return " ".join(line.split())
def main():
parser = argparse.ArgumentParser... | KosmosX-API-main | kosmosX/fairseq/examples/unsupervised_quality_estimation/repeat_lines.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
import os
import subprocess
import sys
import tempfile
from collections import defaultdict
from itertools import c... | KosmosX-API-main | kosmosX/fairseq/examples/unsupervised_quality_estimation/meteor.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 models # noqa
| KosmosX-API-main | kosmosX/fairseq/examples/simultaneous_translation/__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 torch
def prob_check(tensor, eps=1e-10):
assert not torch.isnan(tensor).any(), (
"Nan in a probability tensor."
)
... | KosmosX-API-main | kosmosX/fairseq/examples/simultaneous_translation/utils/functions.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_... | KosmosX-API-main | kosmosX/fairseq/examples/simultaneous_translation/utils/p_choose_strategy.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... | KosmosX-API-main | kosmosX/fairseq/examples/simultaneous_translation/utils/__init__.py |
from typing import Optional
import torch
from torch import Tensor
from examples.simultaneous_translation.utils.functions import (
prob_check,
moving_sum,
)
def expected_alignment_from_p_choose(
p_choose: Tensor,
padding_mask: Optional[Tensor] = None,
eps: float = 1e-6
):
"""
Calculating e... | KosmosX-API-main | kosmosX/fairseq/examples/simultaneous_translation/utils/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.
from typing import Dict, List, NamedTuple, Optional
import torch
import torch.nn as nn
from examples.simultaneous_translation.modules.monoton... | KosmosX-API-main | kosmosX/fairseq/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 importlib
import os
for file in sorted(os.listdir(os.path.dirname(__file__))):
if file.endswith(".py") and not file.startswith("_... | KosmosX-API-main | kosmosX/fairseq/examples/simultaneous_translation/models/__init__.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... | KosmosX-API-main | kosmosX/fairseq/examples/simultaneous_translation/models/convtransformer_simul_trans.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... | KosmosX-API-main | kosmosX/fairseq/examples/simultaneous_translation/eval/agents/simul_t2t_enja.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... | KosmosX-API-main | kosmosX/fairseq/examples/simultaneous_translation/modules/monotonic_transformer_layer.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import math
import torch
from torch import Tensor
import torch.nn as nn
from examples.simultaneous_translation.utils.p_choose_strategy impor... | KosmosX-API-main | kosmosX/fairseq/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 os
import importlib
from fairseq import registry
(
build_monotonic_attention,
register_monotonic_attention,
MONOTONIC_ATT... | KosmosX-API-main | kosmosX/fairseq/examples/simultaneous_translation/modules/__init__.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... | KosmosX-API-main | kosmosX/fairseq/examples/simultaneous_translation/modules/fixed_pre_decision.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 .models import linformer_roberta # noqa
| KosmosX-API-main | kosmosX/fairseq/examples/linformer/linformer_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.
"""
Linformer: Self-Attention with Linear Complexity
"""
import logging
import torch
from fairseq import utils
from fairseq.models import reg... | KosmosX-API-main | kosmosX/fairseq/examples/linformer/linformer_src/models/linformer_roberta.py |
KosmosX-API-main | kosmosX/fairseq/examples/linformer/linformer_src/models/__init__.py | |
KosmosX-API-main | kosmosX/fairseq/examples/linformer/linformer_src/modules/__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 math
from typing import Dict, Optional, Tuple
import torch
import torch.nn.functional as F
from fairseq import utils
from fairseq.incr... | KosmosX-API-main | kosmosX/fairseq/examples/linformer/linformer_src/modules/multihead_linear_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.nn as nn
from fairseq.models.transformer import TransformerEncoder
from .linformer_sentence_encoder_layer import Li... | KosmosX-API-main | kosmosX/fairseq/examples/linformer/linformer_src/modules/linformer_sentence_encoder.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... | KosmosX-API-main | kosmosX/fairseq/examples/linformer/linformer_src/modules/linformer_sentence_encoder_layer.py |
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import torch
src_ckpt = "/checkpoint/wnhsu/w2v/archived/hubert_base_ls960_it2.pt"
ref_ckpt = "/checkpoint/wnhsu/w2v/hubert_icassp_oss_v3/iter... | KosmosX-API-main | kosmosX/fairseq/examples/hubert/update_ckpt.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):... | KosmosX-API-main | kosmosX/fairseq/examples/hubert/measure_teacher_quality.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 ... | KosmosX-API-main | kosmosX/fairseq/examples/hubert/simple_kmeans/dump_km_label.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... | KosmosX-API-main | kosmosX/fairseq/examples/hubert/simple_kmeans/dump_hubert_feature.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... | KosmosX-API-main | kosmosX/fairseq/examples/hubert/simple_kmeans/dump_hubert_feature_s2t.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 | ... | KosmosX-API-main | kosmosX/fairseq/examples/hubert/simple_kmeans/feature_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 sys
import numpy as np
from sklearn.cluster import MiniBatchKMeans
import joblib
logging.basicConfig(
f... | KosmosX-API-main | kosmosX/fairseq/examples/hubert/simple_kmeans/learn_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 logging
import os
import sys
import soundfile as sf
import torch
import torchaudio
from feature_utils import get_path_iterator, dump_... | KosmosX-API-main | kosmosX/fairseq/examples/hubert/simple_kmeans/dump_mfcc_feature.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... | KosmosX-API-main | kosmosX/fairseq/examples/hubert/simple_kmeans/dump_w2v2_feature.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... | KosmosX-API-main | kosmosX/fairseq/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 numpy as np
import nltk
from misc.bleu_utils import sentence_bleu
import warnings
def get_target_sequences(manifest, ground_truth, to... | KosmosX-API-main | kosmosX/fairseq/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.
from collections import defaultdict
import numpy as np
from misc.bleu_utils import sentence_bleu
import json
import warnings
def get_args()... | KosmosX-API-main | kosmosX/fairseq/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.
import torch
import numpy as np
import warnings
def get_target_sequences(manifest, ground_truth, to_take=1000):
import json
import ... | KosmosX-API-main | kosmosX/fairseq/examples/textless_nlp/gslm/metrics/asr_metrics/ppx.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
fro... | KosmosX-API-main | kosmosX/fairseq/examples/textless_nlp/gslm/metrics/asr_metrics/misc/bleu_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 torchaudio
import argparse
import json
import pathlib
def get_args():
parser = argparse.ArgumentParser(
"Assuring genera... | KosmosX-API-main | kosmosX/fairseq/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 argparse
import gc
import logging
import os
import joblib
import soundfile as sf
import torch
from examples.textless_nlp.gslm.speech2u... | KosmosX-API-main | kosmosX/fairseq/examples/textless_nlp/gslm/tools/resynthesize_speech.py |
KosmosX-API-main | kosmosX/fairseq/examples/textless_nlp/gslm/speech2unit/__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 argparse
import logging
from examples.textless_nlp.gslm.speech2unit.pretrained.utils import (
get_and_dump_features,
)
def get_p... | KosmosX-API-main | kosmosX/fairseq/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
import os
import time
import numpy as np
from sklearn.cluster import MiniBatchKMeans
import joblib
from examp... | KosmosX-API-main | kosmosX/fairseq/examples/textless_nlp/gslm/speech2unit/clustering/cluster_kmeans.py |
KosmosX-API-main | kosmosX/fairseq/examples/textless_nlp/gslm/speech2unit/clustering/__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 typing import List, Tuple
def get_audio_files(manifest_path: str) -> Tuple[str, List[str], List[int]]:
fnames, sizes = [], []
w... | KosmosX-API-main | kosmosX/fairseq/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.
import argparse
import logging
import os
import numpy as np
import joblib
from examples.textless_nlp.gslm.speech2unit.clustering.utils impor... | KosmosX-API-main | kosmosX/fairseq/examples/textless_nlp/gslm/speech2unit/clustering/quantize_with_kmeans.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... | KosmosX-API-main | kosmosX/fairseq/examples/textless_nlp/gslm/speech2unit/pretrained/cpc_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... | KosmosX-API-main | kosmosX/fairseq/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 gc
import os
import random
import shutil
import numpy as np
import torch
import tqdm
from examples.textless_nlp.gslm.speech2unit.pretr... | KosmosX-API-main | kosmosX/fairseq/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 torch
import fairseq
import soundfile as sf
class Wav2VecFeatureReader:
"""
Wrapper class to run inference on Wav2Vec 2.0 mod... | KosmosX-API-main | kosmosX/fairseq/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 soundfile as sf
import torch
import torchaudio.compliance.kaldi as kaldi
class LogMelFeatureReader:
"""
Wrapper class to run ... | KosmosX-API-main | kosmosX/fairseq/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 argparse
import logging
import os
import soundfile as sf
from examples.textless_nlp.gslm.unit2speech.tts_data import (
TacotronInp... | KosmosX-API-main | kosmosX/fairseq/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 torch
import numpy as np
from examples.textless_nlp.gslm.unit2speech.tacotron2.text import (
EOS_TOK,
SOS_TOK,
code_to_seq... | KosmosX-API-main | kosmosX/fairseq/examples/textless_nlp/gslm/unit2speech/tts_data.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... | KosmosX-API-main | kosmosX/fairseq/examples/textless_nlp/gslm/unit2speech/glow.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)... | KosmosX-API-main | kosmosX/fairseq/examples/textless_nlp/gslm/unit2speech/convert_to_16k.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... | KosmosX-API-main | kosmosX/fairseq/examples/textless_nlp/gslm/unit2speech/utils.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... | KosmosX-API-main | kosmosX/fairseq/examples/textless_nlp/gslm/unit2speech/multiproc.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... | KosmosX-API-main | kosmosX/fairseq/examples/textless_nlp/gslm/unit2speech/tacotron2/cmudict.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... | KosmosX-API-main | kosmosX/fairseq/examples/textless_nlp/gslm/unit2speech/tacotron2/waveglow_denoiser.py |
KosmosX-API-main | kosmosX/fairseq/examples/textless_nlp/gslm/unit2speech/tacotron2/__init__.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... | KosmosX-API-main | kosmosX/fairseq/examples/textless_nlp/gslm/unit2speech/tacotron2/audio_processing.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... | KosmosX-API-main | kosmosX/fairseq/examples/textless_nlp/gslm/unit2speech/tacotron2/numbers.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__... | KosmosX-API-main | kosmosX/fairseq/examples/textless_nlp/gslm/unit2speech/tacotron2/model.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... | KosmosX-API-main | kosmosX/fairseq/examples/textless_nlp/gslm/unit2speech/tacotron2/stft.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... | KosmosX-API-main | kosmosX/fairseq/examples/textless_nlp/gslm/unit2speech/tacotron2/symbols.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 .text import S... | KosmosX-API-main | kosmosX/fairseq/examples/textless_nlp/gslm/unit2speech/tacotron2/utils.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... | KosmosX-API-main | kosmosX/fairseq/examples/textless_nlp/gslm/unit2speech/tacotron2/text.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... | KosmosX-API-main | kosmosX/fairseq/examples/textless_nlp/gslm/unit2speech/tacotron2/cleaners.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... | KosmosX-API-main | kosmosX/fairseq/examples/textless_nlp/gslm/unit2speech/tacotron2/layers.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
... | KosmosX-API-main | kosmosX/fairseq/examples/textless_nlp/gslm/ulm/sample.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 import register_task
from fairseq.tasks.multilingual_translation import MultilingualTranslationTask
from fairseq.utils impo... | KosmosX-API-main | kosmosX/fairseq/examples/latent_depth/latent_depth_src/multilingual_translation_latent_depth.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 multilingual_translation_latent_depth # noqa
from .loss import latent_depth # noqa
from .models import latent_multilingual_tra... | KosmosX-API-main | kosmosX/fairseq/examples/latent_depth/latent_depth_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.
import math
import torch
from torch.nn.modules.loss import _Loss
class LatentLayersKLLoss(_Loss):
def __init__(self, args):
sup... | KosmosX-API-main | kosmosX/fairseq/examples/latent_depth/latent_depth_src/loss/latent_depth.py |
KosmosX-API-main | kosmosX/fairseq/examples/latent_depth/latent_depth_src/loss/__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 fairseq.models import register_model, register_model_architecture
from fairseq.models.multilingual_transformer import MultilingualTransfo... | KosmosX-API-main | kosmosX/fairseq/examples/latent_depth/latent_depth_src/models/latent_multilingual_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.
from typing import Any, Dict, Optional
import torch.nn as nn
from fairseq.models.fairseq_encoder import EncoderOut
from fairseq.models.transf... | KosmosX-API-main | kosmosX/fairseq/examples/latent_depth/latent_depth_src/models/latent_transformer.py |
KosmosX-API-main | kosmosX/fairseq/examples/latent_depth/latent_depth_src/models/__init__.py | |
KosmosX-API-main | kosmosX/fairseq/examples/latent_depth/latent_depth_src/modules/__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 torch
import torch.nn as nn
class LayerSelect(nn.Module):
"""Compute samples (from a Gumbel-Sigmoid distribution) which is used a... | KosmosX-API-main | kosmosX/fairseq/examples/latent_depth/latent_depth_src/modules/latent_layers.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.
"""
Scoring script for computing pairwise BLEU and multi-ref BLEU over a set of
candidate hypotheses.
See `"Mixture Mod... | KosmosX-API-main | kosmosX/fairseq/examples/translation_moe/score.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... | KosmosX-API-main | kosmosX/fairseq/examples/translation_moe/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.
from . import translation_moe # noqa
| KosmosX-API-main | kosmosX/fairseq/examples/translation_moe/translation_moe_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.
import torch
class LogSumExpMoE(torch.autograd.Function):
"""Standard LogSumExp forward pass, but use *posterior* for the backward.
... | KosmosX-API-main | kosmosX/fairseq/examples/translation_moe/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.
from dataclasses import dataclass, field
import torch
from omegaconf import II
from fairseq import metrics, utils
from fairseq.dataclass impo... | KosmosX-API-main | kosmosX/fairseq/examples/translation_moe/translation_moe_src/translation_moe.py |
from . import criterions, models, tasks # noqa
| KosmosX-API-main | kosmosX/fairseq/examples/speech_recognition/__init__.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.
"""
Flashlight decoders.
"""
import gc
import itertools as it
import os.path as osp
from typing import List
import wa... | KosmosX-API-main | kosmosX/fairseq/examples/speech_recognition/w2l_decoder.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 ast
import logging
import math
import os
... | KosmosX-API-main | kosmosX/fairseq/examples/speech_recognition/infer.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
from examples.speech_recognition.data import AsrDataset
from examples.speech_recognition.data.repl... | KosmosX-API-main | kosmosX/fairseq/examples/speech_recognition/tasks/speech_recognition.py |
import importlib
import os
for file in sorted(os.listdir(os.path.dirname(__file__))):
if file.endswith(".py") and not file.startswith("_"):
task_name = file[: file.find(".py")]
importlib.import_module("examples.speech_recognition.tasks." + task_name)
| KosmosX-API-main | kosmosX/fairseq/examples/speech_recognition/tasks/__init__.py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.