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 math import torch import torch.nn.functional as F from fairseq import utils from fairseq.logging import metrics from fairseq.criterion...
EXA-1-master
exa/libraries/fairseq/fairseq/criterions/legacy_masked_lm.py
# Copyright (c) Facebook, Inc. and 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.functional as F from fairseq import utils from fairseq.logging import metrics from fairseq.criterion...
EXA-1-master
exa/libraries/fairseq/fairseq/criterions/nat_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. """isort:skip_file""" import importlib import os from fairseq import registry from fairseq.criterions.fairseq_criterion import ( # noqa ...
EXA-1-master
exa/libraries/fairseq/fairseq/criterions/__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 dataclasses import dataclass, field import torch from fairseq import utils from fairseq.logging import metrics from fairseq.criterions im...
EXA-1-master
exa/libraries/fairseq/fairseq/criterions/label_smoothed_cross_entropy_latency_augmented.py
# Copyright (c) Facebook, Inc. and 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 import torch from fairseq import utils from fairseq.logging import metrics from fairseq....
EXA-1-master
exa/libraries/fairseq/fairseq/criterions/label_smoothed_cross_entropy.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 from dataclasses im...
EXA-1-master
exa/libraries/fairseq/fairseq/criterions/tacotron2_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. from fairseq import utils from fairseq.criterions import LegacyFairseqCriterion, register_criterion from torch import nn @register_criterion...
EXA-1-master
exa/libraries/fairseq/fairseq/criterions/composite_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. import math import re from dataclasses import dataclass, field from typing import List, Optional import torch import torch.nn.functional as F...
EXA-1-master
exa/libraries/fairseq/fairseq/criterions/hubert_criterion.py
# Copyright (c) Facebook, Inc. and 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 dataclasses import dataclass, field import torch.nn.functional as F from fairseq.logging import metrics from fairseq.tasks ...
EXA-1-master
exa/libraries/fairseq/fairseq/criterions/speech_ulm_criterion.py
# Copyright (c) Facebook, Inc. and 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 itertools import chain import numpy as np import torch import torch.nn.functional a...
EXA-1-master
exa/libraries/fairseq/fairseq/criterions/sentence_prediction.py
# Copyright (c) Facebook, Inc. and 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 fairseq import utils from fairseq.logging import metrics from fairseq.criterions import register_criterion from .label_smoo...
EXA-1-master
exa/libraries/fairseq/fairseq/criterions/label_smoothed_cross_entropy_with_alignment.py
# Copyright (c) Facebook, Inc. and 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 collections import OrderedDict import torch from fairseq import utils from fairseq.logging import metrics fr...
EXA-1-master
exa/libraries/fairseq/fairseq/criterions/speech_to_speech_criterion.py
# Copyright (c) Facebook, Inc. and 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 math from omegaconf import II import torch from fairseq import modules, utils from fairseq.logging i...
EXA-1-master
exa/libraries/fairseq/fairseq/criterions/masked_lm.py
# Copyright (c) Facebook, Inc. and 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.functional as F from fairseq import utils from fairseq.logging import metrics from fairseq.criterion...
EXA-1-master
exa/libraries/fairseq/fairseq/criterions/sentence_ranking.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved # type: ignore from pathlib import Path from read_version import read_version from setuptools import find_namespace_packages, setup setup( name="dependency-submitit-launcher", version=read_version("hydra_plugins/dependency_submitit_launche...
EXA-1-master
exa/libraries/fairseq/hydra_plugins/dependency_submitit_launcher/setup.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved from dataclasses import dataclass, field from hydra.core.config_store import ConfigStore from hydra_plugins.hydra_submitit_launcher.config import SlurmQueueConf @dataclass class DependencySubmititConf(SlurmQueueConf): """Slurm configuration ...
EXA-1-master
exa/libraries/fairseq/hydra_plugins/dependency_submitit_launcher/hydra_plugins/dependency_submitit_launcher/config.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved __version__ = "0.1"
EXA-1-master
exa/libraries/fairseq/hydra_plugins/dependency_submitit_launcher/hydra_plugins/dependency_submitit_launcher/__init__.py
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import logging import os import subprocess from pathlib import Path from typing import Any, List, Sequence from hydra.core.singleton import Singleton from hydra.core.utils import JobReturn, filter_overrides from omegaconf import OmegaConf log = lo...
EXA-1-master
exa/libraries/fairseq/hydra_plugins/dependency_submitit_launcher/hydra_plugins/dependency_submitit_launcher/launcher.py
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # fairseq documentation build configuration file, created by # sphinx-quickstart on Fri Aug 17 21:45:30 2018. # # This file is execfile()d with the current directory set to its # containing dir. # # Note that not all possible configuration values are present in this # au...
EXA-1-master
exa/libraries/fairseq/docs/conf.py
#!/usr/bin/env python3 -u # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import logging import os import hydra import torch from hydra.core.hydra_config import HydraConfig from omegaconf i...
EXA-1-master
exa/libraries/fairseq/fairseq_cli/hydra_train.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. """ Data pre-processing: build vocabularies and binarize training data. """ import logging import os import shutil impo...
EXA-1-master
exa/libraries/fairseq/fairseq_cli/preprocess.py
#!/usr/bin/env python3 -u # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. """ Translate pre-processed data with a trained model. """ import ast import logging import math import os import sy...
EXA-1-master
exa/libraries/fairseq/fairseq_cli/generate.py
#!/usr/bin/env python3 -u # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import logging import os import sys from itertools import chain import torch from hydra.core.hydra_config import Hy...
EXA-1-master
exa/libraries/fairseq/fairseq_cli/hydra_validate.py
EXA-1-master
exa/libraries/fairseq/fairseq_cli/__init__.py
#!/usr/bin/env python3 -u # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import logging import os import sys from argparse import Namespace from itertools import chain import torch from om...
EXA-1-master
exa/libraries/fairseq/fairseq_cli/validate.py
#!/usr/bin/env python3 -u # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. """ Translate raw text with a trained model. Batches data on-the-fly. """ import ast import fileinput import logging...
EXA-1-master
exa/libraries/fairseq/fairseq_cli/interactive.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. """ Train a new model on one or across multiple GPUs. """ import argparse import logging import math import os impor...
EXA-1-master
exa/libraries/fairseq/fairseq_cli/train.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. """ Evaluate the perplexity of a trained language model. """ import logging import math import os import sys from a...
EXA-1-master
exa/libraries/fairseq/fairseq_cli/eval_lm.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. """ BLEU scoring of generated translations against reference translations. """ import argparse import os import sys fr...
EXA-1-master
exa/libraries/fairseq/fairseq_cli/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. try: from fairseq.version import __version__ # noqa except ImportError: pass
EXA-1-master
exa/libraries/fairseq/examples/__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 multiprocessing import Pool import numpy as np from fairseq import options from fairseq.data import dictionary from fairseq....
EXA-1-master
exa/libraries/fairseq/examples/noisychannel/rerank.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from fairseq import options def get_reranking_parser(default_task="translation"): parser = options.get_parser("Generation and reranking"...
EXA-1-master
exa/libraries/fairseq/examples/noisychannel/rerank_options.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import argparse import random import numpy as np from fairseq import options from examples.noisychannel import rerank, rerank_options def ...
EXA-1-master
exa/libraries/fairseq/examples/noisychannel/rerank_tune.py
# Copyright (c) Facebook, Inc. and 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 .rerank_options import * # noqa
EXA-1-master
exa/libraries/fairseq/examples/noisychannel/__init__.py
#!/usr/bin/env python3 -u # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. """ Generate n-best translations using a trained model. """ import os import subprocess from contextlib import redi...
EXA-1-master
exa/libraries/fairseq/examples/noisychannel/rerank_generate.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import math import os import re import subprocess from contextlib import redirect_stdout from fairseq import options from fairseq_cli import ...
EXA-1-master
exa/libraries/fairseq/examples/noisychannel/rerank_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 from fairseq import options from examples.noisychannel import rerank_options, rerank_utils def score_lm(args): using_nbest =...
EXA-1-master
exa/libraries/fairseq/examples/noisychannel/rerank_score_lm.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import os from contextlib import redirect_stdout from fairseq import options from fairseq_cli import generate from examples.noisychannel imp...
EXA-1-master
exa/libraries/fairseq/examples/noisychannel/rerank_score_bw.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import argparse from itertools import zip_longest def replace_oovs(source_in, target_in, vocabulary, source_out, targ...
EXA-1-master
exa/libraries/fairseq/examples/pointer_generator/preprocess.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 re import sys class OOVIndexError(IndexError): def __init__(self, pos, source_seq, target_...
EXA-1-master
exa/libraries/fairseq/examples/pointer_generator/postprocess.py
# Copyright (c) Facebook, Inc. and 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, Optional, List, Tuple import torch import torch.nn as nn from fairseq import utils from fairseq....
EXA-1-master
exa/libraries/fairseq/examples/pointer_generator/pointer_generator_src/transformer_pg.py
# Copyright (c) Facebook, Inc. and 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 transformer_pg # noqa
EXA-1-master
exa/libraries/fairseq/examples/pointer_generator/pointer_generator_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 argparse import json import logging from pathlib import Path import random import soundfile as sf import torch from tqdm import tqdm ...
EXA-1-master
exa/libraries/fairseq/examples/speech_to_speech/generate_waveform_from_code.py
# Copyright (c) Facebook, Inc. and 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 unity # noqa
EXA-1-master
exa/libraries/fairseq/examples/speech_to_speech/__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 Dict, List, Optional import torch import torch.nn as nn from torch import Tensor from fairseq import search class Multi...
EXA-1-master
exa/libraries/fairseq/examples/speech_to_speech/unity/sequence_generator_multi_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. from . import sequence_generator # noqa from . import sequence_generator_multi_decoder # noqa
EXA-1-master
exa/libraries/fairseq/examples/speech_to_speech/unity/__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 sys from typing import Dict, List, Optional import torch from torch import Tensor from fairseq.sequence_generator import ...
EXA-1-master
exa/libraries/fairseq/examples/speech_to_speech/unity/sequence_generator.py
import os from typing import Dict, List import sacrebleu import pandas as pd from glob import glob from pathlib import Path from utils import retrieve_asr_config, ASRGenerator from tqdm import tqdm from argparse import ArgumentParser def merge_tailo_init_final(text): """ Hokkien ASR hypothesis post-processing...
EXA-1-master
exa/libraries/fairseq/examples/speech_to_speech/asr_bleu/compute_asr_bleu.py
EXA-1-master
exa/libraries/fairseq/examples/speech_to_speech/asr_bleu/__init__.py
import json import re import urllib.request from pathlib import Path import fairseq import torch from fairseq.data.data_utils import lengths_to_padding_mask from tqdm import tqdm try: import torchaudio from torchaudio.models.decoder import ctc_decoder except ImportError: raise ImportError("Upgrade torchau...
EXA-1-master
exa/libraries/fairseq/examples/speech_to_speech/asr_bleu/utils.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import argparse from pathlib import Path from tqdm import tqdm def process(args): args.output_root.mkdir(exist_o...
EXA-1-master
exa/libraries/fairseq/examples/speech_to_speech/preprocessing/prep_sn_output_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.
EXA-1-master
exa/libraries/fairseq/examples/speech_to_speech/preprocessing/__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 argparse import logging from pathlib import Path import soundfile as sf from tqdm import tqdm import pandas as ...
EXA-1-master
exa/libraries/fairseq/examples/speech_to_speech/preprocessing/prep_s2ut_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. from pathlib import Path from typing import List, Optional from examples.speech_to_text.data_utils import S2TDataConfigWriter def gen_confi...
EXA-1-master
exa/libraries/fairseq/examples/speech_to_speech/preprocessing/data_utils.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. # # Adapted from examples/wav2vec/wav2vec_manifest.py """ Data preparation for the speech normalizer """ import argpars...
EXA-1-master
exa/libraries/fairseq/examples/speech_to_speech/preprocessing/prep_sn_data.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import argparse import logging import os from pathlib import Path import shutil import torchaudio import soundfile as ...
EXA-1-master
exa/libraries/fairseq/examples/speech_to_speech/preprocessing/prep_s2spect_data.py
import timeit import logging import torch from pypapi import events, papi_high as high from memory_profiler import memory_usage from torch import nn from argparse import Namespace from fairseq.dataclass.utils import convert_namespace_to_omegaconf from fairseq.data import data_utils as fairseq_data_utils from fairseq im...
EXA-1-master
exa/libraries/fairseq/examples/speech_to_speech/benchmarking/core.py
from fairseq import tasks import numpy as np import logging import random from fairseq import options import torch import os import soundfile as sf from fairseq.data.audio.audio_utils import ( get_waveform, parse_path, ) logging.basicConfig() logging.root.setLevel(logging.INFO) logging.basicConfig(level=loggi...
EXA-1-master
exa/libraries/fairseq/examples/speech_to_speech/benchmarking/data_utils.py
import copy import torch import logging from argparse import Namespace import yaml from fairseq import options from examples.speech_to_speech.benchmarking.core import ( Processing, SpeechGeneration, Cascaded2StageS2ST, Cascaded3StageS2ST, S2UT, ) from examples.speech_to_speech.benchmarking.data_util...
EXA-1-master
exa/libraries/fairseq/examples/speech_to_speech/benchmarking/get_metrics.py
#!/usr/bin/env python # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import argparse import fileinput from tqdm import tqdm def main(): parser = argparse.ArgumentParser( desc...
EXA-1-master
exa/libraries/fairseq/examples/backtranslation/extract_bt_data.py
#!/usr/bin/python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import argparse import fileinput import hashlib import sys from multiprocessing import Pool def get_hashes_and_lines(raw_...
EXA-1-master
exa/libraries/fairseq/examples/backtranslation/deduplicate_lines.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import argparse import logging from pathlib import Path import shutil from tempfile import NamedTemporaryFile from typi...
EXA-1-master
exa/libraries/fairseq/examples/speech_to_text/prep_covost_data.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import argparse import logging from pathlib import Path import soundfile as sf from examples.speech_to_text.prep_mustc_...
EXA-1-master
exa/libraries/fairseq/examples/speech_to_text/seg_mustc_data.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import argparse import logging import os from pathlib import Path import shutil from itertools import groupby from temp...
EXA-1-master
exa/libraries/fairseq/examples/speech_to_text/prep_mustc_data.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import argparse import logging import os from pathlib import Path import shutil from itertools import groupby from temp...
EXA-1-master
exa/libraries/fairseq/examples/speech_to_text/prep_mtedx_data.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import csv from pathlib import Path import zipfile from functools import reduce from multiprocessing import cpu_count from typing import Any, ...
EXA-1-master
exa/libraries/fairseq/examples/speech_to_text/data_utils.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import argparse import logging from pathlib import Path import shutil from tempfile import NamedTemporaryFile import p...
EXA-1-master
exa/libraries/fairseq/examples/speech_to_text/prep_librispeech_data.py
import math import os import json import numpy as np import torch import torchaudio.compliance.kaldi as kaldi import yaml from fairseq import checkpoint_utils, tasks from fairseq.file_io import PathManager try: from simuleval import READ_ACTION, WRITE_ACTION, DEFAULT_EOS from simuleval.agents import SpeechAgen...
EXA-1-master
exa/libraries/fairseq/examples/speech_to_text/simultaneous_translation/agents/fairseq_simul_st_agent.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. # Use: echo {text} | python tokenize_indic.py {language} import sys from indicnlp.normalize.indic_normalize import In...
EXA-1-master
exa/libraries/fairseq/examples/m2m_100/tokenizers/tokenize_indic.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import sys from pythainlp import word_tokenize for line in sys.stdin: print(" ".join(word_tokenize(line.strip())...
EXA-1-master
exa/libraries/fairseq/examples/m2m_100/tokenizers/tokenize_thai.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import fileinput import sacrebleu for line in fileinput.input(): print(sacrebleu.tokenize_zh(line))
EXA-1-master
exa/libraries/fairseq/examples/m2m_100/tokenizers/tokenize_zh.py
import argparse from collections import namedtuple import os DATADIR = "/path/to/train_data" DEDUP_FROM_DIR = "/path/to/eval/data" OUTPUT_DIR = "/path/to/output/data" def main(args): languages = set() for language_directory in os.listdir(DATADIR): if "_" in language_directory: src, tgt = ...
EXA-1-master
exa/libraries/fairseq/examples/m2m_100/process_data/dedup_data.py
import gzip import argparse from string import punctuation def len_no_punc(s, punc): return len([ch for ch in s if ch in punc]) def filter_overpunc(len_npunc, len_sen): return len_npunc < 0.5*len_sen def main(args): punc = punctuation + "—|–" print('Processing file {}'.format(args.input)) with gz...
EXA-1-master
exa/libraries/fairseq/examples/m2m_100/process_data/remove_too_much_punc.py
import argparse parser = argparse.ArgumentParser() parser.add_argument('--src', type=str, help='Source language') parser.add_argument('--tgt', type=str, help='Target language') parser.add_argument('--src-file', type=str, help='Input source file') parser.add_argument('--tgt-file', type=str, help='Input target file') pa...
EXA-1-master
exa/libraries/fairseq/examples/m2m_100/process_data/clean_histogram.py
#!/usr/bin/env python3 -u import argparse import fileinput import logging import os import sys from fairseq.models.transformer import TransformerModel logging.getLogger().setLevel(logging.INFO) def main(): parser = argparse.ArgumentParser(description="") parser.add_argument("--en2fr", required=True, help=...
EXA-1-master
exa/libraries/fairseq/examples/paraphraser/paraphrase.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import argparse import sys import numpy as np aggregate_funcs = { "std": np.std, "var": np.var, "median": np.median, "mean"...
EXA-1-master
exa/libraries/fairseq/examples/unsupervised_quality_estimation/aggregate_scores.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import argparse import sys def _normalize_spaces(line): return " ".join(line.split()) def main(): parser = argparse.ArgumentParser...
EXA-1-master
exa/libraries/fairseq/examples/unsupervised_quality_estimation/repeat_lines.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import argparse import math import os import subprocess import sys import tempfile from collections import defaultdict from itertools import c...
EXA-1-master
exa/libraries/fairseq/examples/unsupervised_quality_estimation/meteor.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from . import models # noqa
EXA-1-master
exa/libraries/fairseq/examples/simultaneous_translation/__init__.py
import argparse import unittest from typing import Any, Dict import torch from examples.simultaneous_translation.models import ( transformer_monotonic_attention ) from tests.test_roberta import FakeTask DEFAULT_CONFIG = { "attention_eps": 1e-6, "mass_preservation": True, "noise_type": "flat", "...
EXA-1-master
exa/libraries/fairseq/examples/simultaneous_translation/tests/test_text_models.py
import unittest import numpy as np import torch import hypothesis.strategies as st from hypothesis import assume, given, settings from torch.testing._internal.common_utils import TestCase from examples.simultaneous_translation.utils.functions import exclusive_cumprod TEST_CUDA = torch.cuda.is_available() class Al...
EXA-1-master
exa/libraries/fairseq/examples/simultaneous_translation/tests/test_alignment_train.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import torch def prob_check(tensor, eps=1e-10): assert not torch.isnan(tensor).any(), ( "Nan in a probability tensor." ) ...
EXA-1-master
exa/libraries/fairseq/examples/simultaneous_translation/utils/functions.py
from typing import Optional, Dict from torch import Tensor import torch def waitk_p_choose( tgt_len: int, src_len: int, bsz: int, waitk_lagging: int, key_padding_mask: Optional[Tensor] = None, incremental_state: Optional[Dict[str, Dict[str, Optional[Tensor]]]] = None ): max_src_len = src_...
EXA-1-master
exa/libraries/fairseq/examples/simultaneous_translation/utils/p_choose_strategy.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import importlib import os # automatically import any Python files in the criterions/ directory for file in sorted(os.listdir(os.path.dirnam...
EXA-1-master
exa/libraries/fairseq/examples/simultaneous_translation/utils/__init__.py
from typing import Optional import torch from torch import Tensor from examples.simultaneous_translation.utils.functions import ( exclusive_cumprod, prob_check, moving_sum, ) def expected_alignment_from_p_choose( p_choose: Tensor, padding_mask: Optional[Tensor] = None, eps: float = 1e-6 ): ...
EXA-1-master
exa/libraries/fairseq/examples/simultaneous_translation/utils/monotonic_attention.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from typing import Dict, List, NamedTuple, Optional import torch import torch.nn as nn from examples.simultaneous_translation.modules.monoton...
EXA-1-master
exa/libraries/fairseq/examples/simultaneous_translation/models/transformer_monotonic_attention.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import importlib import os for file in sorted(os.listdir(os.path.dirname(__file__))): if file.endswith(".py") and not file.startswith("_...
EXA-1-master
exa/libraries/fairseq/examples/simultaneous_translation/models/__init__.py
# Copyright (c) 2017-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the license found in the LICENSE file in # the root directory of this source tree. An additional grant of patent rights # can be found in the PATENTS file in the same directory. from fairseq import checkpoint_uti...
EXA-1-master
exa/libraries/fairseq/examples/simultaneous_translation/models/convtransformer_simul_trans.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import os from fairseq import checkpoint_utils, tasks import sentencepiece as spm import torch try: from simuleval import READ_ACTION, W...
EXA-1-master
exa/libraries/fairseq/examples/simultaneous_translation/eval/agents/simul_t2t_enja.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from fairseq.modules import TransformerDecoderLayer, TransformerEncoderLayer from . import build_monotonic_attention from typing import Dict...
EXA-1-master
exa/libraries/fairseq/examples/simultaneous_translation/modules/monotonic_transformer_layer.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import math import torch from torch import Tensor import torch.nn as nn from examples.simultaneous_translation.utils.p_choose_strategy impor...
EXA-1-master
exa/libraries/fairseq/examples/simultaneous_translation/modules/monotonic_multihead_attention.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import os import importlib from fairseq import registry ( build_monotonic_attention, register_monotonic_attention, MONOTONIC_ATT...
EXA-1-master
exa/libraries/fairseq/examples/simultaneous_translation/modules/__init__.py
from functools import partial import torch from torch import Tensor import math import torch.nn.functional as F from . import register_monotonic_attention from .monotonic_multihead_attention import ( MonotonicAttention, MonotonicInfiniteLookbackAttention, WaitKAttention ) from typing import Dict, Optional...
EXA-1-master
exa/libraries/fairseq/examples/simultaneous_translation/modules/fixed_pre_decision.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from .models import linformer_roberta # noqa
EXA-1-master
exa/libraries/fairseq/examples/linformer/linformer_src/__init__.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. """ Linformer: Self-Attention with Linear Complexity """ import logging import torch from fairseq import utils from fairseq.models import reg...
EXA-1-master
exa/libraries/fairseq/examples/linformer/linformer_src/models/linformer_roberta.py
EXA-1-master
exa/libraries/fairseq/examples/linformer/linformer_src/models/__init__.py
EXA-1-master
exa/libraries/fairseq/examples/linformer/linformer_src/modules/__init__.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import math from typing import Dict, Optional, Tuple import torch import torch.nn.functional as F from fairseq import utils from fairseq.incr...
EXA-1-master
exa/libraries/fairseq/examples/linformer/linformer_src/modules/multihead_linear_attention.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import math import torch.nn as nn from fairseq.models.transformer import TransformerEncoder from .linformer_sentence_encoder_layer import Li...
EXA-1-master
exa/libraries/fairseq/examples/linformer/linformer_src/modules/linformer_sentence_encoder.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import torch from fairseq import utils from fairseq.modules import TransformerEncoderLayer from .multihead_linear_attention import MultiheadL...
EXA-1-master
exa/libraries/fairseq/examples/linformer/linformer_src/modules/linformer_sentence_encoder_layer.py