python_code
stringlengths
0
992k
repo_name
stringlengths
8
46
file_path
stringlengths
5
162
import glob import os from typing import List, Optional, Tuple import logging import numpy as np import torchvision.transforms.functional as TF import PIL from PIL import Image from torchvision.datasets import VisionDataset logger = logging.getLogger(__name__) class PathDataset(VisionDataset): def __init__( ...
EXA-1-master
exa/libraries/fairseq/examples/data2vec/data/path_dataset.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...
EXA-1-master
exa/libraries/fairseq/examples/emotion_conversion/synthesize.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...
EXA-1-master
exa/libraries/fairseq/examples/emotion_conversion/preprocess/split_km_tsv.py
EXA-1-master
exa/libraries/fairseq/examples/emotion_conversion/preprocess/__init__.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 ...
EXA-1-master
exa/libraries/fairseq/examples/emotion_conversion/preprocess/split_emov_km_tsv_by_uttid.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...
EXA-1-master
exa/libraries/fairseq/examples/emotion_conversion/preprocess/build_translation_manifests.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...
EXA-1-master
exa/libraries/fairseq/examples/emotion_conversion/preprocess/create_core_manifest.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...
EXA-1-master
exa/libraries/fairseq/examples/emotion_conversion/preprocess/process_km.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...
EXA-1-master
exa/libraries/fairseq/examples/emotion_conversion/preprocess/split_km.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=""...
EXA-1-master
exa/libraries/fairseq/examples/emotion_conversion/preprocess/extract_f0.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 ...
EXA-1-master
exa/libraries/fairseq/examples/emotion_conversion/preprocess/build_hifigan_manifest.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 = { ...
EXA-1-master
exa/libraries/fairseq/examples/emotion_conversion/emotion_models/duration_predictor.py
EXA-1-master
exa/libraries/fairseq/examples/emotion_conversion/emotion_models/__init__.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() ...
EXA-1-master
exa/libraries/fairseq/examples/emotion_conversion/emotion_models/utils.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...
EXA-1-master
exa/libraries/fairseq/examples/emotion_conversion/emotion_models/pitch_predictor.py
# Copyright (c) Facebook, Inc. and 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...
EXA-1-master
exa/libraries/fairseq/examples/emotion_conversion/fairseq_models/__init__.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from fairseq.tasks import register_task from fairseq.tasks.multilingual_translation import MultilingualTranslationTask from fairseq.utils impo...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/fairseq/examples/latent_depth/latent_depth_src/loss/latent_depth.py
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/fairseq/examples/latent_depth/latent_depth_src/models/latent_transformer.py
EXA-1-master
exa/libraries/fairseq/examples/latent_depth/latent_depth_src/models/__init__.py
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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
EXA-1-master
exa/libraries/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. ...
EXA-1-master
exa/libraries/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 utils from fairseq.logging import metrics ...
EXA-1-master
exa/libraries/fairseq/examples/translation_moe/translation_moe_src/translation_moe.py
from . import criterions, models, tasks # noqa
EXA-1-master
exa/libraries/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...
EXA-1-master
exa/libraries/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 ...
EXA-1-master
exa/libraries/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 import torch from examples.speech_recognition.data import AsrDataset from examples.speech_recognit...
EXA-1-master
exa/libraries/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)
EXA-1-master
exa/libraries/fairseq/examples/speech_recognition/tasks/__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. from dataclasses import dataclass import hydra from hydra.core.config_store import ConfigStore import logging from ome...
EXA-1-master
exa/libraries/fairseq/examples/speech_recognition/kaldi/kaldi_initializer.py
EXA-1-master
exa/libraries/fairseq/examples/speech_recognition/kaldi/__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. from concurrent.futures import ThreadPoolExecutor import logging from omegaconf import MISSING import os import torch ...
EXA-1-master
exa/libraries/fairseq/examples/speech_recognition/kaldi/kaldi_decoder.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. from __future__ import absolute_import, division, print_function, unicode_literals import argparse import concurrent.f...
EXA-1-master
exa/libraries/fairseq/examples/speech_recognition/datasets/asr_prep_json.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. from __future__ import absolute_import, division, print_function, unicode_literals import re from collections import ...
EXA-1-master
exa/libraries/fairseq/examples/speech_recognition/utils/wer_utils.py
import importlib import os for file in sorted(os.listdir(os.path.dirname(__file__))): if file.endswith(".py") and not file.startswith("_"): model_name = file[: file.find(".py")] importlib.import_module("examples.speech_recognition.models." + model_name)
EXA-1-master
exa/libraries/fairseq/examples/speech_recognition/models/__init__.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import argparse import math from collections.abc import Iterable import torch import torch.nn as nn from examples.speech_recognition.data.dat...
EXA-1-master
exa/libraries/fairseq/examples/speech_recognition/models/vggtransformer.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 math import torch import torch.nn as nn import torch.nn.functional as F from fairseq.models import ( Fairs...
EXA-1-master
exa/libraries/fairseq/examples/speech_recognition/models/w2l_conv_glu_enc.py
EXA-1-master
exa/libraries/fairseq/examples/speech_recognition/new/__init__.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 from dataclasses import dataclass, field,...
EXA-1-master
exa/libraries/fairseq/examples/speech_recognition/new/infer.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. from typing import Union from fairseq.data.dictionary import Dictionary from .decoder_config import DecoderConfig, F...
EXA-1-master
exa/libraries/fairseq/examples/speech_recognition/new/decoders/decoder.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)...
EXA-1-master
exa/libraries/fairseq/examples/speech_recognition/new/decoders/viterbi_decoder.py
EXA-1-master
exa/libraries/fairseq/examples/speech_recognition/new/decoders/__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 itertools as it from typing import Any, Dict, List import torch from fairseq.data.dictionary import Dictionary from fairseq.models.fai...
EXA-1-master
exa/libraries/fairseq/examples/speech_recognition/new/decoders/base_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 math from dataclasses import dataclass, field from typing import Optional from fairseq.dataclass.configs import FairseqDataclass from ...
EXA-1-master
exa/libraries/fairseq/examples/speech_recognition/new/decoders/decoder_config.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...
EXA-1-master
exa/libraries/fairseq/examples/speech_recognition/new/decoders/flashlight_decoder.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. """ Replabel transforms for use with flashlight's ASG criterion. """ def replabel_symbol(i): """ Replabel sy...
EXA-1-master
exa/libraries/fairseq/examples/speech_recognition/data/replabels.py
# Copyright (c) Facebook, Inc. and 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 .asr_dataset import AsrDataset __all__ = [ "AsrDataset", ]
EXA-1-master
exa/libraries/fairseq/examples/speech_recognition/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. """ This module contains collection of classes which implement collate functionalities for various tasks. Collaters should know wh...
EXA-1-master
exa/libraries/fairseq/examples/speech_recognition/data/collaters.py
# Copyright (c) Facebook, Inc. and 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 calc_mean_invstddev(feature): if len(feature.size()) != 2: raise ValueError("We expect the input feature to be ...
EXA-1-master
exa/libraries/fairseq/examples/speech_recognition/data/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 os import numpy as np from fairseq.data import FairseqDataset from . import data_utils from .collaters import Seq2SeqCollater class...
EXA-1-master
exa/libraries/fairseq/examples/speech_recognition/data/asr_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 __future__ import absolute_import, division, print_function, unicode_literals import logging import math import torch import torch.nn.f...
EXA-1-master
exa/libraries/fairseq/examples/speech_recognition/criterions/cross_entropy_acc.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 examples.speech_recognition.data.replabels import pack_replabels from fairseq import utils from fair...
EXA-1-master
exa/libraries/fairseq/examples/speech_recognition/criterions/ASG_loss.py
import importlib import os # ASG loss requires flashlight bindings files_to_skip = set() try: import flashlight.lib.sequence.criterion except ImportError: files_to_skip.add("ASG_loss.py") for file in sorted(os.listdir(os.path.dirname(__file__))): if file.endswith(".py") and not file.startswith("_") and f...
EXA-1-master
exa/libraries/fairseq/examples/speech_recognition/criterions/__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. import sys from sacremoses.normalize import MosesPunctNormalizer def main(args): normalizer = MosesPunctNormal...
EXA-1-master
exa/libraries/fairseq/examples/constrained_decoding/normalize.py
#!/usr/bin/env python3 # # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import sys import sacremoses def main(args): """Tokenizes, preserving tabs""" mt = sacremoses.MosesTokeniz...
EXA-1-master
exa/libraries/fairseq/examples/constrained_decoding/tok.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import logging from dataclasses import dataclass from typing import Dict, List, Optional import torch from fairseq.dataclass import FairseqDa...
EXA-1-master
exa/libraries/fairseq/examples/adaptive_span/adaptive_span_model_wrapper.py
# Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. import math import torch import torch.nn as nn import torch.nn.functional as F from fairseq.modules.layer_norm import Lay...
EXA-1-master
exa/libraries/fairseq/examples/adaptive_span/adaptive_span_model.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import importlib import os # automatically import any Python files in the current directory cur_dir = os.path.dirname(__file__) for file in o...
EXA-1-master
exa/libraries/fairseq/examples/adaptive_span/__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 import torch.nn.functional as F from fairseq import utils from fairseq.logging import metrics f...
EXA-1-master
exa/libraries/fairseq/examples/adaptive_span/adaptive_span_loss.py
../truncated_bptt/truncated_bptt_lm_task.py
EXA-1-master
exa/libraries/fairseq/examples/adaptive_span/truncated_bptt_lm_task.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import math import torch import torch.nn as nn import torch.nn.functional as F class AdaptiveMask(nn.Module): """Soft masking function f...
EXA-1-master
exa/libraries/fairseq/examples/adaptive_span/adaptive_span_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 torch.optim import Adagrad from fairseq.optim import LegacyFairseqOptimizer, register_optimizer @register_optimizer("adagrad_with_grad...
EXA-1-master
exa/libraries/fairseq/examples/adaptive_span/adagrad_with_grad_clip.py
# Copyright (c) Facebook, Inc. and 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.models.bart import BARTModel import argparse XSUM_KWARGS = dict(beam=6, lenpen=1.0, max_len_b=60, min_len=10, no_re...
EXA-1-master
exa/libraries/fairseq/examples/bart/summarize.py
import argparse from pathlib import Path import soundfile def get_insl_frame(parse): out = [] def is_ont_token(tok): return tok[0] in ["[", "]"]; res = [] x = [] for tok in parse.split(): if is_ont_token(tok): res.extend('_'.join(x)) x = [] res.a...
EXA-1-master
exa/libraries/fairseq/examples/audio_nlp/nlu/generate_manifests.py
# Copyright (c) Facebook, Inc. and 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 from utils.dedup import deup import sys WORKDIR_ROOT = os.environ.get('WORKDIR_ROOT', None) if WORKD...
EXA-1-master
exa/libraries/fairseq/examples/multilingual/data_scripts/dedup_all.py
# Copyright (c) Facebook, Inc. and 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 argparse import pandas as pd import sys WORKDIR_ROOT = os.environ.get('WORKDIR_ROOT', None) if WORKDIR_ROOT is None or n...
EXA-1-master
exa/libraries/fairseq/examples/multilingual/data_scripts/check_valid_test_overlaps.py
# Copyright (c) Facebook, Inc. and 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, sys import subprocess import re from subprocess import check_call, check_output WORKDIR_ROOT = os.environ.get('WORKDIR_ROOT', Non...
EXA-1-master
exa/libraries/fairseq/examples/multilingual/data_scripts/check_iswlt_test_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 itertools import os import csv from collections import defaultdict from six.moves import zip import io import wget import sys from su...
EXA-1-master
exa/libraries/fairseq/examples/multilingual/data_scripts/download_ted_and_extract.py
from typing import NamedTuple, List from urllib.parse import urlparse import os, sys import subprocess from subprocess import check_call, check_output import glob import wget import re import multiprocessing as mp from functools import partial import pathlib from collections import OrderedDict WORKDIR_ROOT = os.envir...
EXA-1-master
exa/libraries/fairseq/examples/multilingual/data_scripts/download_wmt19_and_before.py
import os, sys import glob, itertools import pandas as pd WORKDIR_ROOT = os.environ.get('WORKDIR_ROOT', None) if WORKDIR_ROOT is None or not WORKDIR_ROOT.strip(): print('please specify your working directory root in OS environment variable WORKDIR_ROOT. Exitting..."') sys.exit(-1) def load_langs(path): ...
EXA-1-master
exa/libraries/fairseq/examples/multilingual/data_scripts/remove_valid_test_in_train.py
import shutil import os, sys from subprocess import check_call, check_output import glob import argparse import shutil import pathlib import itertools def call_output(cmd): print(f"Executing: {cmd}") ret = check_output(cmd, shell=True) print(ret) return ret def call(cmd): print(cmd) check_call...
EXA-1-master
exa/libraries/fairseq/examples/multilingual/data_scripts/binarize.py
# Copyright (c) Facebook, Inc. and 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 from utils.dedup import deup import sys WORKDIR_ROOT = os.environ.get('WORKDIR_ROOT', None) if WORKDI...
EXA-1-master
exa/libraries/fairseq/examples/multilingual/data_scripts/check_self_overlaps.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. #!/bin/python import fasttext from multiprocessing import Pool import contextlib import sys import argparse from functools import partial im...
EXA-1-master
exa/libraries/fairseq/examples/multilingual/data_scripts/utils/fasttext_multi_filter.py
# Copyright (c) Facebook, Inc. and 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 deup(src_file, tgt_file, src_file_out, tgt_file_out): seen = set() dup_count = 0 with open(src_file, encodin...
EXA-1-master
exa/libraries/fairseq/examples/multilingual/data_scripts/utils/dedup.py
# Copyright (c) Facebook, Inc. and 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 from fairseq import options, utils from fairseq.models import ( Fairs...
EXA-1-master
exa/libraries/fairseq/examples/laser/laser_src/laser_lstm.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import logging from typing import Any, Dict, List, Optional from torch import Tensor import torch import torch.nn as nn from fairseq.models...
EXA-1-master
exa/libraries/fairseq/examples/laser/laser_src/laser_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 collections import OrderedDict import numpy as np from fairseq.data import BaseWrapperDataset, FairseqDataset, iterators class MultiI...
EXA-1-master
exa/libraries/fairseq/examples/laser/laser_src/multitask_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. from .laser_task import * # noqa from .laser_lstm import * # noqa from .laser_transformer import * # noqa
EXA-1-master
exa/libraries/fairseq/examples/laser/laser_src/__init__.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from collections import OrderedDict, defaultdict import json import os import logging from argparse import ArgumentError from fairseq import...
EXA-1-master
exa/libraries/fairseq/examples/laser/laser_src/laser_task.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...
EXA-1-master
exa/libraries/fairseq/examples/MMPT/setup.py
# Copyright (c) Facebook, Inc. and 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...
EXA-1-master
exa/libraries/fairseq/examples/MMPT/locallaunch.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. try: # fairseq user dir from .datasets import FairseqMMDataset from .losses import FairseqCriterion from .models import Fairseq...
EXA-1-master
exa/libraries/fairseq/examples/MMPT/mmpt/__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 .loss import * from .nce import * try: from .fairseqmmloss import * except ImportError: pass try: from .expnce import * exce...
EXA-1-master
exa/libraries/fairseq/examples/MMPT/mmpt/losses/__init__.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...
EXA-1-master
exa/libraries/fairseq/examples/MMPT/mmpt/losses/loss.py
# Copyright (c) Facebook, Inc. and 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...
EXA-1-master
exa/libraries/fairseq/examples/MMPT/mmpt/losses/fairseqmmloss.py
# Copyright (c) Facebook, Inc. and 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 _...
EXA-1-master
exa/libraries/fairseq/examples/MMPT/mmpt/losses/nce.py
# Copyright (c) Facebook, Inc. and 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...
EXA-1-master
exa/libraries/fairseq/examples/MMPT/mmpt/tasks/task.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. """ make a general fairseq task for MM pretraining. """ import random from fairseq.tasks import LegacyFairseqTask, register_task from .task ...
EXA-1-master
exa/libraries/fairseq/examples/MMPT/mmpt/tasks/fairseqmmtask.py
# Copyright (c) Facebook, Inc. and 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: ...
EXA-1-master
exa/libraries/fairseq/examples/MMPT/mmpt/tasks/__init__.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import os import torch import pickle import random from tqdm import tqdm from torch.utils.data import DataLoader from torch.utils.data.distrib...
EXA-1-master
exa/libraries/fairseq/examples/MMPT/mmpt/tasks/retritask.py
# Copyright (c) Facebook, Inc. and 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....
EXA-1-master
exa/libraries/fairseq/examples/MMPT/mmpt/tasks/milncetask.py
# Copyright (c) Facebook, Inc. and 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...
EXA-1-master
exa/libraries/fairseq/examples/MMPT/mmpt/tasks/vlmtask.py
# Copyright (c) Facebook, Inc. and 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...
EXA-1-master
exa/libraries/fairseq/examples/MMPT/mmpt/datasets/fairseqmmdataset.py
# Copyright (c) Facebook, Inc. and 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 .mmdataset import * try: from .fairseqmmdataset import * except ImportError: pass
EXA-1-master
exa/libraries/fairseq/examples/MMPT/mmpt/datasets/__init__.py