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/textless_nlp/pgslm/eval/cont_metrics.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 numpy as np
import scipy
import torch
import torch.multiprocessing as mp
from fairseq import checkpoint_utils, options
from ... | 731 | 23,650 |
fairseq | examples/textless_nlp/pgslm/scripts/join_units_manifest.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 json
import argparse
import pathlib
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--manifest", required=... | 49 | 1,430 |
fairseq | examples/textless_nlp/pgslm/sample/sample.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 torch.multiprocessing as mp
import numpy as np
import json
import torch
from torch.distributions.categorical import Categori... | 613 | 20,977 |
fairseq | examples/textless_nlp/gslm/tools/resynthesize_speech.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 gc
import logging
import os
import joblib
import soundfile as sf
import torch
from examples.textless_nlp.gslm.speech2u... | 133 | 4,183 |
fairseq | examples/textless_nlp/gslm/speech2unit/pretrained/hubert_feature_reader.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
import fairseq
import soundfile as sf
import torch.nn.functional as F
class HubertFeatureReader:
"""
Wrapper class to r... | 71 | 2,392 |
fairseq | examples/textless_nlp/gslm/speech2unit/pretrained/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 gc
import os
import random
import shutil
import numpy as np
import torch
import tqdm
from examples.textless_nlp.gslm.speech2unit.pretr... | 128 | 3,484 |
fairseq | examples/textless_nlp/gslm/speech2unit/pretrained/w2v2_feature_reader.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
import fairseq
import soundfile as sf
class Wav2VecFeatureReader:
"""
Wrapper class to run inference on Wav2Vec 2.0 mod... | 57 | 1,901 |
fairseq | examples/textless_nlp/gslm/speech2unit/pretrained/logmel_feature_reader.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 soundfile as sf
import torch
import torchaudio.compliance.kaldi as kaldi
class LogMelFeatureReader:
"""
Wrapper class to run ... | 35 | 1,108 |
fairseq | examples/textless_nlp/gslm/speech2unit/pretrained/cpc_feature_reader.py | .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... | 205 | 7,013 |
fairseq | examples/textless_nlp/gslm/speech2unit/clustering/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 typing import List, Tuple
def get_audio_files(manifest_path: str) -> Tuple[str, List[str], List[int]]:
fnames, sizes = [], []
w... | 21 | 701 |
fairseq | examples/textless_nlp/gslm/speech2unit/clustering/quantize_with_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 argparse
import logging
import os
import numpy as np
import joblib
from examples.textless_nlp.gslm.speech2unit.clustering.utils impor... | 142 | 4,437 |
fairseq | examples/textless_nlp/gslm/speech2unit/clustering/cluster_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 argparse
import logging
import os
import time
import numpy as np
from sklearn.cluster import MiniBatchKMeans
import joblib
from examp... | 213 | 6,182 |
fairseq | examples/textless_nlp/gslm/speech2unit/clustering/dump_feats.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 logging
from examples.textless_nlp.gslm.speech2unit.pretrained.utils import (
get_and_dump_features,
)
def get_p... | 92 | 2,615 |
fairseq | examples/textless_nlp/gslm/ulm/sample.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.
"""
Sample from a trained LM; hacked fairseq-interactive
"""
from collections import namedtuple
import os
import ast
... | 175 | 5,623 |
fairseq | examples/textless_nlp/gslm/unit2speech/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 torch
from examples.textless_nlp.gslm.unit2speech.tacotron2.model import Tacotron2
from examples.textless_nlp.gslm.unit2speech.tacotro... | 56 | 1,904 |
fairseq | examples/textless_nlp/gslm/unit2speech/convert_to_16k.py | .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)... | 56 | 2,177 |
fairseq | examples/textless_nlp/gslm/unit2speech/tts_data.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
import numpy as np
from examples.textless_nlp.gslm.unit2speech.tacotron2.text import (
EOS_TOK,
SOS_TOK,
code_to_seq... | 55 | 1,733 |
fairseq | examples/textless_nlp/gslm/unit2speech/synthesize_audio_from_units.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 logging
import os
import soundfile as sf
from examples.textless_nlp.gslm.unit2speech.tts_data import (
TacotronInp... | 106 | 3,178 |
fairseq | examples/textless_nlp/gslm/unit2speech/multiproc.py | .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... | 28 | 772 |
fairseq | examples/textless_nlp/gslm/unit2speech/glow.py | .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... | 313 | 12,722 |
fairseq | examples/textless_nlp/gslm/unit2speech/tacotron2/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 collections
import io
import json
import librosa
import numpy as np
import soundfile as sf
import time
import torch
from scipy.io.wavfi... | 172 | 4,918 |
fairseq | examples/textless_nlp/gslm/unit2speech/tacotron2/cleaners.py | .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... | 91 | 2,439 |
fairseq | examples/textless_nlp/gslm/unit2speech/tacotron2/symbols.py | .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... | 19 | 718 |
fairseq | examples/textless_nlp/gslm/unit2speech/tacotron2/model.py | .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__... | 670 | 25,989 |
fairseq | examples/textless_nlp/gslm/unit2speech/tacotron2/cmudict.py | .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... | 66 | 1,979 |
fairseq | examples/textless_nlp/gslm/unit2speech/tacotron2/stft.py | .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... | 142 | 5,893 |
fairseq | examples/textless_nlp/gslm/unit2speech/tacotron2/text.py | .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... | 108 | 3,075 |
fairseq | examples/textless_nlp/gslm/unit2speech/tacotron2/layers.py | .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... | 104 | 3,859 |
fairseq | examples/textless_nlp/gslm/unit2speech/tacotron2/audio_processing.py | .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... | 94 | 2,610 |
fairseq | examples/textless_nlp/gslm/unit2speech/tacotron2/numbers.py | .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... | 72 | 2,168 |
fairseq | examples/textless_nlp/gslm/unit2speech/tacotron2/waveglow_denoiser.py | .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... | 41 | 1,610 |
fairseq | examples/textless_nlp/gslm/metrics/abx_metrics/dump_abx_feats.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 logging
import os
import joblib
import numpy as np
from examples.textless_nlp.gslm.speech2unit.clustering.utils impor... | 108 | 3,329 |
fairseq | examples/textless_nlp/gslm/metrics/asr_metrics/self_auto_bleu.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 nltk
from misc.bleu_utils import sentence_bleu
import warnings
def get_target_sequences(manifest, ground_truth, to... | 202 | 6,101 |
fairseq | examples/textless_nlp/gslm/metrics/asr_metrics/continuation_eval.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 collections import defaultdict
import numpy as np
from misc.bleu_utils import sentence_bleu
import json
import warnings
def get_args()... | 100 | 2,869 |
fairseq | examples/textless_nlp/gslm/metrics/asr_metrics/ppx.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
import numpy as np
import warnings
def get_target_sequences(manifest, ground_truth, to_take=1000):
import json
import ... | 123 | 3,692 |
fairseq | examples/textless_nlp/gslm/metrics/asr_metrics/misc/bleu_utils.py | .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... | 166 | 6,679 |
fairseq | examples/textless_nlp/gslm/metrics/asr_metrics/misc/cut_as.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 torchaudio
import argparse
import json
import pathlib
def get_args():
parser = argparse.ArgumentParser(
"Assuring genera... | 70 | 1,832 |
fairseq | examples/emotion_conversion/synthesize.py | .py | import logging
import argparse
import random
import sys
import os
import numpy as np
import torch
import soundfile as sf
import shutil
import librosa
import json
from pathlib import Path
from tqdm import tqdm
import amfm_decompy.basic_tools as basic
import amfm_decompy.pYAAPT as pYAAPT
dir_path = os.path.dirname(__fil... | 323 | 12,908 |
fairseq | examples/emotion_conversion/emotion_models/utils.py | .py | import torch
class Stat:
def __init__(self, keep_raw=False):
self.x = 0.0
self.x2 = 0.0
self.z = 0.0 # z = logx
self.z2 = 0.0
self.n = 0.0
self.u = 0.0
self.keep_raw = keep_raw
self.raw = []
def update(self, new_x):
new_z = new_x.log()
... | 79 | 1,701 |
fairseq | examples/emotion_conversion/emotion_models/duration_predictor.py | .py | import logging
import os
import hydra
import torch
import torch.nn as nn
import torch.nn.functional as F
from einops.layers.torch import Rearrange
from torch.utils.data import DataLoader, Dataset
from .utils import Accuracy
logger = logging.getLogger(__name__)
def save_ckpt(model, path, model_class):
ckpt = {
... | 244 | 8,553 |
fairseq | examples/emotion_conversion/emotion_models/pitch_predictor.py | .py | import logging
import os
import random
import sys
from collections import defaultdict
import hydra
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from einops import rearrange
from einops.layers.torch import Rearrange
from scipy.io.wavfile import read
from scipy.ndimage import gau... | 560 | 17,849 |
fairseq | examples/emotion_conversion/preprocess/build_hifigan_manifest.py | .py | import torchaudio
import argparse
import json
def main():
parser = argparse.ArgumentParser(description="example: python create_hifigan_manifest.py --tsv /checkpoint/felixkreuk/datasets/vctk/splits/vctk_16khz/train.tsv --km /checkpoint/felixkreuk/experiments/hubert/hubert_feats/vctk_16khz_km_100/train.km --km_type ... | 39 | 1,970 |
fairseq | examples/emotion_conversion/preprocess/split_km.py | .py | from pathlib import Path
import os
import argparse
import random
import numpy as np
from sklearn.utils import shuffle
if __name__ == "__main__":
"""
this is a standalone script to process a km file
specifically, to dedup or remove tokens that repeat less
than k times in a row
"""
parser = argp... | 51 | 1,643 |
fairseq | examples/emotion_conversion/preprocess/process_km.py | .py | import sys
import argparse
from tqdm import tqdm
from build_emov_translation_manifests import dedup, remove_under_k
if __name__ == "__main__":
"""
this is a standalone script to process a km file
specifically, to dedup or remove tokens that repeat less
than k times in a row
"""
parser = argpar... | 41 | 1,290 |
fairseq | examples/emotion_conversion/preprocess/split_emov_km_tsv_by_uttid.py | .py | from pathlib import Path
import os
import sys
import argparse
import random
import numpy as np
from tqdm import tqdm
from sklearn.model_selection import train_test_split
from build_translation_manifests import get_utt_id
def train_val_test_split(tsv_lines, km_lines, valid_percent, test_percent, seed=42):
utt_ids ... | 71 | 3,173 |
fairseq | examples/emotion_conversion/preprocess/extract_f0.py | .py | import argparse
from tqdm import tqdm
from multiprocessing import Manager, Pool
from scipy.io.wavfile import read
from librosa.util import normalize
import numpy as np
import amfm_decompy.pYAAPT as pYAAPT
import amfm_decompy.basic_tools as basic
MAX_WAV_VALUE = 32768.0
parser = argparse.ArgumentParser(description=""... | 58 | 1,849 |
fairseq | examples/emotion_conversion/preprocess/create_core_manifest.py | .py | from pathlib import Path
import os
import sys
import subprocess
import argparse
from datetime import datetime
import logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s [%(levelname)s] %(message)s',
handlers=[logging.FileHandler('debug.log'), logging.StreamHandler()]
)
logger = logging.get... | 92 | 4,034 |
fairseq | examples/emotion_conversion/preprocess/build_translation_manifests.py | .py | from glob import glob
import argparse
from collections import defaultdict, Counter
from itertools import combinations, product, groupby
from pathlib import Path
import os
from sklearn.utils import shuffle
import numpy as np
import random
from shutil import copy
from subprocess import check_call
np.random.seed(42)
rand... | 259 | 12,132 |
fairseq | examples/emotion_conversion/preprocess/split_km_tsv.py | .py | from pathlib import Path
import os
import argparse
import random
import numpy as np
from sklearn.utils import shuffle
if __name__ == "__main__":
"""
this is a standalone script to process a km file
specifically, to dedup or remove tokens that repeat less
than k times in a row
"""
parser = argp... | 66 | 2,367 |
fairseq | examples/emotion_conversion/fairseq_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.
from fairseq import utils
from fairseq.models import (
FairseqMultiModel,
register_model,
register_model_architecture,
)
from fair... | 227 | 10,256 |
fairseq | examples/MMPT/setup.py | .py | import setuptools
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="mmpt",
version="0.0.1",
author="Hu Xu, Po-yao Huang",
author_email="huxu@fb.com",
description="A package for multimodal pretraining.",
long_description=long_description,
long_descr... | 25 | 668 |
fairseq | examples/MMPT/locallaunch.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 os
from omegaconf import OmegaConf
from mmpt.utils import recursive_config, overwrite_dir
from mmpt_cli.localjob impor... | 149 | 5,336 |
fairseq | examples/MMPT/mmpt_cli/predict.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 glob
import argparse
import pprint
import omegaconf
from omegaconf import OmegaConf
from torch.utils.data import DataLoader
... | 114 | 3,937 |
fairseq | examples/MMPT/mmpt_cli/localjob.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 mmpt.utils import recursive_config
class BaseJob(object):
def __init__(self, yaml_file, dryrun=False):
self.yaml_... | 118 | 3,794 |
fairseq | examples/MMPT/mmpt/tasks/vlmtask.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 .task import Task
class VLMTask(Task):
"""A VLM task for reproducibility.
the collator split subsamples into two s... | 28 | 856 |
fairseq | examples/MMPT/mmpt/tasks/milncetask.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 .task import Task
class MILNCETask(Task):
def reshape_subsample(self, sample):
if (
hasattr(self.... | 28 | 954 |
fairseq | examples/MMPT/mmpt/tasks/fairseqmmtask.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.
"""
make a general fairseq task for MM pretraining.
"""
import random
from fairseq.tasks import LegacyFairseqTask, register_task
from .task ... | 105 | 3,045 |
fairseq | examples/MMPT/mmpt/tasks/__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.
from .task import *
from .vlmtask import *
from .retritask import *
try:
from .fairseqmmtask import *
except ImportError:
pass
try:
... | 23 | 445 |
fairseq | examples/MMPT/mmpt/tasks/retritask.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 torch
import pickle
import random
from tqdm import tqdm
from torch.utils.data import DataLoader
from torch.utils.data.distrib... | 254 | 8,413 |
fairseq | examples/MMPT/mmpt/tasks/task.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 .. import tasks
from .. import models
from .. import losses
from ..datasets import MMDataset
from .. import processors
cla... | 185 | 6,780 |
fairseq | examples/MMPT/mmpt/processors/dsprocessor.py | .py | # Copyright (c) Facebook, Inc. All Rights Reserved
"""
Processors for all downstream (ds) tasks.
"""
import json
import os
import pickle
import random
import math
import numpy as np
import torch
from collections import defaultdict
from .processor import (
MetaProcessor,
VideoProcessor,
TextProcessor,
... | 849 | 29,891 |
fairseq | examples/MMPT/mmpt/processors/dedupprocessor.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 random
import json
import pickle
from tqdm import tqdm
import os
import numpy as np
class CaptionDedupProcessor(object):
"""remov... | 243 | 8,834 |
fairseq | examples/MMPT/mmpt/processors/how2retriprocessor.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 .how2processor import (
ShardedHow2MetaProcessor,
ShardedVideoProcessor,
ShardedTextProcessor,
VariedLenAligner,
Over... | 101 | 3,742 |
fairseq | examples/MMPT/mmpt/processors/how2processor.py | .py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a cop... | 888 | 32,302 |
fairseq | examples/MMPT/mmpt/processors/processor.py | .py | # Copyright (c) Facebook, Inc. All Rights Reserved
import numpy as np
import os
import torch
class Processor(object):
"""
A generic processor for video (codec, feature etc.) and text.
"""
def __call__(self, **kwargs):
raise NotImplementedError
class MetaProcessor(Processor):
"""
A ... | 275 | 9,358 |
fairseq | examples/MMPT/mmpt/processors/models/s3dg.py | .py | # This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
"""Contains a PyTorch definition for Gated Separable 3D network (S3D-G)
with a text module for computing joint text-video embedding from raw text
and video input. The following code will enable y... | 337 | 12,416 |
fairseq | examples/MMPT/mmpt/losses/nce.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.
"""
softmax-based NCE loss, used by this project.
"""
import torch
from torch import nn
from .loss import Loss
class NCE(Loss):
def _... | 157 | 4,586 |
fairseq | examples/MMPT/mmpt/losses/fairseqmmloss.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.
"""
TODO (huxu): a general fairseq criterion for all your pre-defined losses.
"""
from fairseq.criterions import FairseqCriterion, register_c... | 64 | 2,241 |
fairseq | examples/MMPT/mmpt/losses/loss.py | .py | # Copyright (c) Facebook, Inc. All Rights Reserved
import torch
from torch import nn
class Loss(object):
def __call__(self, *args, **kwargs):
raise NotImplementedError
# Dummy Loss for testing.
class DummyLoss(Loss):
def __init__(self):
self.loss = nn.CrossEntropyLoss()
def __call__(s... | 88 | 2,095 |
fairseq | examples/MMPT/mmpt/datasets/fairseqmmdataset.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.
"""
TODO (huxu): fairseq wrapper class for all dataset you defined: mostly MMDataset.
"""
from collections import OrderedDict
from torch.util... | 58 | 1,785 |
fairseq | examples/MMPT/mmpt/datasets/mmdataset.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 collections import OrderedDict
from torch.utils.data import Dataset
from torch.utils.data.dataloader import default_collat... | 112 | 3,873 |
fairseq | examples/MMPT/mmpt/evaluators/evaluator.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 glob
import numpy as np
from . import metric as metric_path
from . import predictor as predictor_path
class Evaluator(objec... | 55 | 2,026 |
fairseq | examples/MMPT/mmpt/evaluators/metric.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 json
class Metric(object):
def __init__(self, config, metric_names):
self.metric_names = metric_names
... | 314 | 10,898 |
fairseq | examples/MMPT/mmpt/evaluators/predictor.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 random
import json
import numpy as np
import torch
import pickle
import math
from tqdm import tqdm
class Predictor(object):... | 596 | 23,125 |
fairseq | examples/MMPT/mmpt/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 random
import numpy as np
import torch
from .shardedtensor import *
from .load_config import *
def set_seed(seed=43211):
random.s... | 69 | 1,886 |
fairseq | examples/MMPT/mmpt/utils/load_config.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 omegaconf
from omegaconf import OmegaConf
def load_config(args=None, config_file=None, overwrite_fairseq=False):
"""TODO... | 82 | 3,155 |
fairseq | examples/MMPT/mmpt/utils/shardedtensor.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 pickle
import numpy as np
class ShardedTensor(object):
def __init__(self, data, starts):
self.data = data
... | 47 | 1,410 |
fairseq | examples/MMPT/mmpt/modules/retri.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 numpy as np
import pickle
import time
try:
import faiss
except ImportError:
pass
from collections import defaultdict... | 430 | 15,471 |
fairseq | examples/MMPT/mmpt/modules/vectorpool.py | .py | # Copyright (c) Facebook, Inc. All Rights Reserved
import torch
import os
import numpy as np
import pickle
from . import retri
from ..utils import get_local_rank
class VectorPool(object):
"""
Base class of retrieval space.
"""
def __init__(self, config):
from transformers import AutoConfig
... | 247 | 8,278 |
fairseq | examples/MMPT/mmpt/modules/mm.py | .py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a cop... | 146 | 5,537 |
fairseq | examples/MMPT/mmpt/models/mmfusion.py | .py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a cop... | 927 | 30,634 |
fairseq | examples/MMPT/mmpt/models/fairseqmmmodel.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.models import (
BaseFairseqModel,
register_model,
register_model_architecture
)
@register_model("mmmodel")
class Fa... | 52 | 1,417 |
fairseq | examples/MMPT/mmpt/models/mmfusionnlg.py | .py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors, Facebook AI Research authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the L... | 1,000 | 48,394 |
fairseq | examples/MMPT/mmpt/models/transformermodel.py | .py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a cop... | 735 | 26,064 |
fairseq | examples/MMPT/scripts/video_feature_extractor/videoreader.py | .py | # Copyright Howto100M authors.
# Copyright (c) Facebook, Inc. All Rights Reserved
import torch as th
import pandas as pd
import os
import numpy as np
import ffmpeg
import random
from torch.utils.data import Dataset
class VideoLoader(Dataset):
"""modified from how2's video_feature_extractor."""
def __init__(... | 243 | 8,322 |
fairseq | examples/MMPT/scripts/video_feature_extractor/extract.py | .py | # Copyright Howto100M authors.
# Copyright (c) Facebook, Inc. All Rights Reserved
import torch as th
import torch.nn.functional as F
import math
import numpy as np
import argparse
from torch.utils.data import DataLoader
from model import get_model
from preprocessing import Preprocessing
from random_sequence_shuffler ... | 158 | 5,529 |
fairseq | examples/MMPT/scripts/video_feature_extractor/model.py | .py | # Copyright (c) Howto100M authors and Facebook, Inc. All Rights Reserved
import torch as th
from torch import nn
class GlobalAvgPool(nn.Module):
def __init__(self):
super(GlobalAvgPool, self).__init__()
def forward(self, x):
return th.mean(x, dim=[-2, -1])
def get_model(args):
assert ... | 59 | 1,921 |
fairseq | examples/MMPT/scripts/video_feature_extractor/pathbuilder.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 urllib.parse
import json
import pandas as pd
from tqdm import tqdm
# TODO: extending to other datasets.
supported_formats =... | 90 | 3,410 |
fairseq | examples/MMPT/scripts/video_feature_extractor/shard_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 numpy as np
import os
import pickle
from mmpt.utils import ShardedTensor
class Shard(object):
def __init__(
self,
... | 65 | 2,166 |
fairseq | examples/MMPT/scripts/video_feature_extractor/random_sequence_shuffler.py | .py | # Copyright (c) Facebook, Inc. All Rights Reserved
import numpy as np
from torch.utils.data.sampler import Sampler
class RandomSequenceSampler(Sampler):
def __init__(self, n_sample, seq_len):
self.n_sample = n_sample
self.seq_len = seq_len
def _pad_ind(self, ind):
zeros = np.zeros(... | 30 | 829 |
fairseq | examples/MMPT/scripts/video_feature_extractor/preprocessing.py | .py | # Copyright Howto100m authors.
# Copyright (c) Facebook, Inc. All Rights Reserved
import torch as th
class Normalize(object):
def __init__(self, mean, std):
self.mean = th.FloatTensor(mean).view(1, 3, 1, 1)
self.std = th.FloatTensor(std).view(1, 3, 1, 1)
def __call__(self, tensor):
t... | 58 | 2,071 |
fairseq | examples/MMPT/scripts/text_token_extractor/pretokenization.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 pickle
import os
import argparse
import numpy as np
from torch.utils.data import Dataset, DataLoader
from mmpt.processors import PKLJS... | 107 | 3,408 |
fairseq | examples/xmod/preprocess_nli.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 json
import collections
import argparse
import shutil
import subprocess
import sys
import tempfile
from multiprocessing impor... | 169 | 6,168 |
fairseq | examples/speech_recognition/w2l_decoder.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.
"""
Flashlight decoders.
"""
import gc
import itertools as it
import os.path as osp
from typing import List
import wa... | 487 | 17,396 |
fairseq | examples/speech_recognition/infer.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.
"""
Run inference for pre-processed data with a trained model.
"""
import ast
import logging
import math
import os
... | 437 | 14,677 |
fairseq | examples/speech_recognition/new/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 ast
import hashlib
import logging
import os
import shutil
import sys
import re
from dataclasses import datacla... | 503 | 18,069 |
fairseq | examples/speech_recognition/new/decoders/flashlight_decoder.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 gc
import os.path as osp
import warnings
from collections import deque, namedtuple
from typing import Any, Dict... | 434 | 14,870 |
fairseq | examples/speech_recognition/new/decoders/base_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.
import itertools as it
from typing import Any, Dict, List
import torch
from fairseq.data.dictionary import Dictionary
from fairseq.models.fai... | 63 | 2,093 |
fairseq | examples/speech_recognition/new/decoders/decoder_config.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, field
from typing import Optional
from fairseq.dataclass.configs import FairseqDataclass
from ... | 71 | 2,004 |
fairseq | examples/speech_recognition/new/decoders/viterbi_decoder.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 torch
from typing import List, Dict
from .base_decoder import BaseDecoder
class ViterbiDecoder(BaseDecoder)... | 25 | 705 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.