python_code
stringlengths
0
992k
repo_name
stringlengths
8
46
file_path
stringlengths
5
162
# Copyright (c) Facebook, Inc. and 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...
EXA-1-master
exa/libraries/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):...
EXA-1-master
exa/libraries/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 ...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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 | ...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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_...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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 def main(): """ Create code file with the following format: {'audio': 'file1', 'unitA': 'file1_chnl1_units',...
EXA-1-master
exa/libraries/fairseq/examples/textless_nlp/dgslm/create_code_file.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 torch import json from fairseq import utils from fairseq.models.text_to_speech.vocoder import CodeHiFiGANVocoder #...
EXA-1-master
exa/libraries/fairseq/examples/textless_nlp/dgslm/dgslm_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 os import ast import argparse import logging import torch from fairseq import utils from fairseq.models.speech_dlm import SpeechDLM l...
EXA-1-master
exa/libraries/fairseq/examples/textless_nlp/dgslm/sample_speech_dlm.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 ast import argparse import json import logging from pathlib import Path import soundfile as sf import torch from tqdm import tqdm fro...
EXA-1-master
exa/libraries/fairseq/examples/textless_nlp/dgslm/vocoder_hifigan/generate_stereo_waveform.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 from functools import partial import numpy as np import torch from tqdm import tqdm from data_utils impor...
EXA-1-master
exa/libraries/fairseq/examples/textless_nlp/pgslm/quantize_f0.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 multiprocessing import Pool import os from collections import defaultdict from itertools import starmap import torch from npy_append_arr...
EXA-1-master
exa/libraries/fairseq/examples/textless_nlp/pgslm/prepare_dataset.py
# Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import torch import warnings def truncated_laplace(mean, T, truncate_by_zero=False): """Generating a sample from a Laplace distribution, ...
EXA-1-master
exa/libraries/fairseq/examples/textless_nlp/pgslm/truncated_laplace.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 ast import argparse import json import logging from pathlib import Path import soundfile as sf import torch from tqdm import tqdm fro...
EXA-1-master
exa/libraries/fairseq/examples/textless_nlp/pgslm/generate_waveform.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 from tqdm import tqdm from data_utils import load_audio_path from fairseq.data.codedataset import get_f0_by_filename d...
EXA-1-master
exa/libraries/fairseq/examples/textless_nlp/pgslm/preprocess_f0.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 warnings class Naive_F0_Decoder(torch.nn.Module): def __init__(self, bounds_path, n_units=32): super().__init...
EXA-1-master
exa/libraries/fairseq/examples/textless_nlp/pgslm/naive_decoder.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 from tqdm import tqdm class Stat: def __init__(self, keep_raw=False): self.x = 0.0 self.x2 = 0.0 ...
EXA-1-master
exa/libraries/fairseq/examples/textless_nlp/pgslm/data_utils.py
# Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import torch class InferenceDataset: def __init__( self, dataset, prefix, only_prefix=True, pres...
EXA-1-master
exa/libraries/fairseq/examples/textless_nlp/pgslm/inference_dataset.py
# Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import json import argparse import pathlib def main(): parser = argparse.ArgumentParser() parser.add_argument("--manifest", required=...
EXA-1-master
exa/libraries/fairseq/examples/textless_nlp/pgslm/scripts/join_units_manifest.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.
EXA-1-master
exa/libraries/fairseq/examples/textless_nlp/pgslm/sample/__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 os import torch.multiprocessing as mp import numpy as np import json import torch from torch.distributions.categorical import Categori...
EXA-1-master
exa/libraries/fairseq/examples/textless_nlp/pgslm/sample/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. import os import numpy as np import scipy import torch import torch.multiprocessing as mp from fairseq import checkpoint_utils, options from ...
EXA-1-master
exa/libraries/fairseq/examples/textless_nlp/pgslm/eval/cont_metrics.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.
EXA-1-master
exa/libraries/fairseq/examples/textless_nlp/pgslm/eval/__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 import os import joblib import numpy as np from examples.textless_nlp.gslm.speech2unit.clustering.utils impor...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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()...
EXA-1-master
exa/libraries/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 ...
EXA-1-master
exa/libraries/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 imp...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/fairseq/examples/textless_nlp/gslm/tools/resynthesize_speech.py
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/fairseq/examples/textless_nlp/gslm/speech2unit/clustering/cluster_kmeans.py
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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 ...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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)...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/fairseq/examples/textless_nlp/gslm/unit2speech/tacotron2/waveglow_denoiser.py
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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__...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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 scipy.io.wavfi...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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 ...
EXA-1-master
exa/libraries/fairseq/examples/textless_nlp/gslm/ulm/sample.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 torch from omegaconf import OmegaConf from fairseq.criterions.model_criterion import ModelCrit...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/fb_convert_beit_cp.py
EXA-1-master
exa/libraries/fairseq/examples/data2vec/__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. import logging import sys import t...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/tasks/mae_image_classification.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. import os.path as osp import loggi...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/tasks/image_classification.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. import sys from dataclasses impor...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/tasks/multimodal.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. import logging import os import nu...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/tasks/audio_classification.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 .image_pretraining import ImagePretrainingTask, ImagePretrainingConfig from .image_classification import ImageClassificationTask, ImageCl...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/tasks/__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. import logging import sys import o...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/tasks/image_pretraining.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. import logging import sys from ty...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/tasks/mae_image_pretraining.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. # The code in this file is adapted from the BeiT implementation which can be found here: # https://github.com/microsoft/unilm/tree/master/beit...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/models/data2vec_text_classification.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 from typing import Optional import logging import math import torch import torch.nn as nn import tor...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/models/data2vec_text.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. # The code in this file is adapted from the BeiT implementation which can be found here: # https://github.com/microsoft/unilm/tree/master/beit...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/models/mae_image_classification.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. # The code in this file is adapted from the BeiT implementation which can be found here: # https://github.com/microsoft/unilm/tree/master/beit...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/models/mae.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 from dataclasses import dataclass, field from typing import Optional, Callable from functools import partial import...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/models/data2vec2.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import contextlib import logging import re from dataclasses import dataclass, field from typing import Any, Optional import torch import torc...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/models/audio_classification.py
EXA-1-master
exa/libraries/fairseq/examples/data2vec/models/__init__.py
import math import torch def get_alibi( max_positions: int, attention_heads: int, ): def get_slopes(n): def get_slopes_power_of_2(n): start = 2 ** (-(2 ** -(math.log2(n) - 3))) ratio = start return [start * ratio ** i for i in range(n)] # In the paper, w...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/models/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 math from dataclasses import dataclass, field from typing import Optional from omegaconf import II import torch import...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/models/data2vec_audio.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. # The code in this file is adapted from the BeiT implementation which can be found here: # https://github.com/microsoft/unilm/tree/master/beit...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/models/data2vec_image_classification.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. # The code in this file is adapted from the BeiT implementation which can be found here: # https://github.com/microsoft/unilm/tree/master/beit...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/models/data2vec_vision.py
EXA-1-master
exa/libraries/fairseq/examples/data2vec/models/modalities/__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 dataclasses import dataclass from functools import partial from typing import Callable, Dict, Optional import torch.nn as nn...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/models/modalities/text.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import torch import torch.nn as nn import torch.nn.functional as F import numpy as np from functools import partial from dataclasses import da...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/models/modalities/images.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 functools import partial import torch import torch.nn as nn import numpy as np from dataclasses import dataclass, field from typing impor...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/models/modalities/audio.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import torch import torch.nn as nn import torch.nn.functional as F import numpy as np from dataclasses import dataclass from fairseq.modules i...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/models/modalities/modules.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...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/models/modalities/base.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import argparse import os def get_parser(): parser = argparse.ArgumentParser(description="convert audioset labels...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/scripts/convert_audioset_labels.py
from valids import parser, main as valids_main import os.path as osp args = parser.parse_args() args.target = "valid_accuracy" args.best_biggest = True args.best = True args.last = 0 args.path_contains = None res = valids_main(args, print_output=False) grouped = {} for k, v in res.items(): k = osp.dirname(k) ...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/scripts/text/glue.py
import os, argparse, re, json, copy, math from collections import OrderedDict import numpy as np parser = argparse.ArgumentParser(description='Process some integers.') parser.add_argument('base', help='base log path') parser.add_argument('--file_name', default='train.log', help='the log file name') parser.add_argument...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/scripts/text/valids.py
import json import os import tqdm from fairseq.data import Dictionary, data_utils def load_dictionary(dict_path): return Dictionary.load(dict_path) def load_dataset(split_path, src_dict): dataset = data_utils.load_indexed_dataset( split_path, src_dict, combine=False, # set to true fo...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/scripts/text/unprocess_data.py
import os.path as osp import re from collections import defaultdict from valids import parser, main as valids_main TASK_TO_METRIC = { "cola": "mcc", "qnli": "accuracy", "mrpc": "acc_and_f1", "rte": "accuracy", "sst_2": "accuracy", "mnli": "accuracy", "qqp": "acc_and_f1", "sts_b": "pea...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/scripts/text/glue_lr.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 functools import partial import logging import math import random import time import numpy as np import os import torch from torchvis...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/data/mae_image_dataset.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import torch from fairseq.data import BaseWrapperDataset, data_utils class AddClassTargetDataset(BaseWrapperDataset): def __init__( ...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/data/add_class_target_dataset.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import logging import numpy as np import os from typing import Optional, Callable, Set import torch from torchvision.datasets.vision impor...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/data/image_dataset.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from .image_dataset import ImageDataset from .path_dataset import PathDataset from .mae_image_dataset import MaeImageDataset from .mae_finetun...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/data/__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 logging import numpy as np import os import torch from torchvision import datasets, transforms from timm.data import create_transf...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/data/mae_finetuning_image_dataset.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 enum import Enum, auto clas...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/data/modality.py