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 from multiprocessing import Pool import numpy as np from fairseq import options from fairseq.data import dictionary from fairseq....
EXA-1-master
exa/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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 import torch import torch.nn as nn from fairseq import metrics, utils from fairseq.mode...
EXA-1-master
exa/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/fairseq/examples/pointer_generator/pointer_generator_src/__init__.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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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 import os from pathlib import Path import shutil from itertools import groupby from temp...
EXA-1-master
exa/models/unilm-master/decoding/IAD/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 csv from pathlib import Path import zipfile from functools import reduce from multiprocessing import cpu_count f...
EXA-1-master
exa/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/fairseq/examples/speech_to_text/prep_librispeech_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. # Use: echo {text} | python tokenize_indic.py {language} import sys from indicnlp.normalize.indic_normalize import In...
EXA-1-master
exa/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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 criterions, eval, models # noqa
EXA-1-master
exa/models/unilm-master/decoding/IAD/fairseq/examples/simultaneous_translation/__init__.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import torch def exclusive_cumprod(tensor, dim: int, eps: float = 1e-10): """ Implementing exclusive cumprod. There is cumprod i...
EXA-1-master
exa/models/unilm-master/decoding/IAD/fairseq/examples/simultaneous_translation/utils/functions.py
# Copyright (c) Facebook, Inc. and 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 LatencyMetric(object): @staticmethod def length_from_padding_mask(padding_mask, batch_first: bool = False): ...
EXA-1-master
exa/models/unilm-master/decoding/IAD/fairseq/examples/simultaneous_translation/utils/latency.py
# Copyright (c) Facebook, Inc. and 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 os.listdir(os.path.dirname(__fil...
EXA-1-master
exa/models/unilm-master/decoding/IAD/fairseq/examples/simultaneous_translation/utils/__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 import torch.nn.functional as F from examples.simultaneous_translation.modules.monotonic_transformer_layer ...
EXA-1-master
exa/models/unilm-master/decoding/IAD/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 os.listdir(os.path.dirname(__file__)): if file.endswith(".py") and not file.startswith("_"): ...
EXA-1-master
exa/models/unilm-master/decoding/IAD/fairseq/examples/simultaneous_translation/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 json import sys from scorers import build_scorer from tornado import ioloop, web DEFAULT_HOSTNAME = "localhost" DEFAU...
EXA-1-master
exa/models/unilm-master/decoding/IAD/fairseq/examples/simultaneous_translation/eval/server.py
# Copyright (c) Facebook, Inc. and 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 torch from examples.simultaneous_translation.utils.latency import LatencyInference LATENCY_METRICS = [ ...
EXA-1-master
exa/models/unilm-master/decoding/IAD/fairseq/examples/simultaneous_translation/eval/eval_latency.py
# Copyright (c) Facebook, Inc. and 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 Optional import requests from scorers import build_scorer class SimulSTEvaluationService(object): DEFAULT_HOSTNAME =...
EXA-1-master
exa/models/unilm-master/decoding/IAD/fairseq/examples/simultaneous_translation/eval/client.py
# Copyright (c) Facebook, Inc. and 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/models/unilm-master/decoding/IAD/fairseq/examples/simultaneous_translation/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 from agents import build_agent from client import SimulSTEvaluationService, SimulSTLocalEvaluationService from fairseq.regist...
EXA-1-master
exa/models/unilm-master/decoding/IAD/fairseq/examples/simultaneous_translation/eval/evaluate.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. class SubwordSplitter(object): def process_line(self, string): raise NotImplementedError def split(self, string): ra...
EXA-1-master
exa/models/unilm-master/decoding/IAD/fairseq/examples/simultaneous_translation/eval/agents/word_splitter.py
# Copyright (c) Facebook, Inc. and 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 from fairseq import registry build_agent, register_agent, MONOTONIC_AGENT, _ = registry.setup_registry( "--a...
EXA-1-master
exa/models/unilm-master/decoding/IAD/fairseq/examples/simultaneous_translation/eval/agents/__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 . import DEFAULT_EOS, GET, register_agent from .simul_trans_agent import SimulTransAgent from .word_splitter import SPLITTER_DICT @regi...
EXA-1-master
exa/models/unilm-master/decoding/IAD/fairseq/examples/simultaneous_translation/eval/agents/simul_trans_text_agent.py
# Copyright (c) Facebook, Inc. and 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 time from functools import partial from multiprocessing.pool import ThreadPool as Pool from . import DEFAULT_EOS, GET, SEND class Ag...
EXA-1-master
exa/models/unilm-master/decoding/IAD/fairseq/examples/simultaneous_translation/eval/agents/agent.py
# Copyright (c) Facebook, Inc. and 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 from fairseq import checkpoint_utils, tasks, utils from . import DEFAULT_EOS, GET, SEND from .agent import Agent cla...
EXA-1-master
exa/models/unilm-master/decoding/IAD/fairseq/examples/simultaneous_translation/eval/agents/simul_trans_agent.py
# Copyright (c) Facebook, Inc. and 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 from fairseq import registry (build_scorer, register_scorer, SCORER_REGISTRIES, _) = registry.setup_registry( ...
EXA-1-master
exa/models/unilm-master/decoding/IAD/fairseq/examples/simultaneous_translation/eval/scorers/__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 . import register_scorer from .scorer import SimulScorer @register_scorer("text") class SimulTextScorer(SimulScorer): def __init__(...
EXA-1-master
exa/models/unilm-master/decoding/IAD/fairseq/examples/simultaneous_translation/eval/scorers/text_scorer.py
# Copyright (c) Facebook, Inc. and 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 from collections import defaultdict from examples.simultaneous_translation.eval.eval_latency import LatencyScorer from ...
EXA-1-master
exa/models/unilm-master/decoding/IAD/fairseq/examples/simultaneous_translation/eval/scorers/scorer.py
# Copyright (c) Facebook, Inc. and 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 LayerNorm, TransformerDecoderLayer, TransformerEncoderLayer from . import build_monotonic_attention class Trans...
EXA-1-master
exa/models/unilm-master/decoding/IAD/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 import torch.nn as nn import torch.nn.functional as F from examples.simultaneous_translation.utils.functions import ...
EXA-1-master
exa/models/unilm-master/decoding/IAD/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 importlib import os from fairseq import registry ( build_monotonic_attention, register_monotonic_attention, MONOTONIC_AT...
EXA-1-master
exa/models/unilm-master/decoding/IAD/fairseq/examples/simultaneous_translation/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 importlib import os for file in os.listdir(os.path.dirname(__file__)): if file.endswith(".py") and not file.startswith("_"): ...
EXA-1-master
exa/models/unilm-master/decoding/IAD/fairseq/examples/simultaneous_translation/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 examples.simultaneous_translation.utils.latency import LatencyTraining from fairseq.criterions import register_criterion from fairseq.cri...
EXA-1-master
exa/models/unilm-master/decoding/IAD/fairseq/examples/simultaneous_translation/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. from .models import linformer_roberta # noqa
EXA-1-master
exa/models/unilm-master/decoding/IAD/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 from fairseq.models import register_model, register_model_architectur...
EXA-1-master
exa/models/unilm-master/decoding/IAD/fairseq/examples/linformer/linformer_src/models/linformer_roberta.py
EXA-1-master
exa/models/unilm-master/decoding/IAD/fairseq/examples/linformer/linformer_src/models/__init__.py
EXA-1-master
exa/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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.modules import TransformerSentenceEncoder from .linformer_sentence_encoder_layer import Linfo...
EXA-1-master
exa/models/unilm-master/decoding/IAD/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. from typing import Callable from fairseq.modules import TransformerSentenceEncoderLayer from .multihead_linear_attention import MultiheadLin...
EXA-1-master
exa/models/unilm-master/decoding/IAD/fairseq/examples/linformer/linformer_src/modules/linformer_sentence_encoder_layer.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from fairseq.tasks import register_task from fairseq.tasks.multilingual_translation import MultilingualTranslationTask from .loss.latent_dept...
EXA-1-master
exa/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/fairseq/examples/latent_depth/latent_depth_src/loss/latent_depth.py
EXA-1-master
exa/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/fairseq/examples/latent_depth/latent_depth_src/models/latent_transformer.py
EXA-1-master
exa/models/unilm-master/decoding/IAD/fairseq/examples/latent_depth/latent_depth_src/models/__init__.py
EXA-1-master
exa/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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. import torch from fairseq import metrics, utils from fairseq.tasks import register_task from fairseq.tasks.translation import TranslationTask ...
EXA-1-master
exa/models/unilm-master/decoding/IAD/fairseq/examples/translation_moe/translation_moe_src/translation_moe.py
from . import criterions, models, tasks # noqa
EXA-1-master
exa/models/unilm-master/decoding/IAD/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 import warnings from collections ...
EXA-1-master
exa/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/fairseq/examples/speech_recognition/tasks/speech_recognition.py
import importlib import os for file in 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/models/unilm-master/decoding/IAD/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 __future__ import absolute_import, division, print_function, unicode_literals import argparse import concurrent.f...
EXA-1-master
exa/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/fairseq/examples/speech_recognition/utils/wer_utils.py
import importlib import os for file in 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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/fairseq/examples/speech_recognition/models/w2l_conv_glu_enc.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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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 os.listdir(os.path.dirname(__file__)): if file.endswith(".py") and not file.startswith("_") and file not ...
EXA-1-master
exa/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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 metrics, utils from fairseq.criterions impo...
EXA-1-master
exa/models/unilm-master/decoding/IAD/fairseq/examples/adaptive_span/adaptive_span_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 logging import os from dataclasses import dataclass, field from typing import List, Optional, Tuple import torch from fairseq import d...
EXA-1-master
exa/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/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/models/unilm-master/decoding/IAD/fairseq/examples/adaptive_span/adagrad_with_grad_clip.py