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. 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/edgelm/examples/latent_depth/latent_depth_src/models/latent_transformer.py
EXA-1-master
exa/models/unilm-master/edgelm/examples/latent_depth/latent_depth_src/models/__init__.py
EXA-1-master
exa/models/unilm-master/edgelm/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/edgelm/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/edgelm/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/edgelm/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/edgelm/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/edgelm/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 metrics, utils from fairseq.dataclass impo...
EXA-1-master
exa/models/unilm-master/edgelm/examples/translation_moe/translation_moe_src/translation_moe.py
from . import criterions, models, tasks # noqa
EXA-1-master
exa/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/edgelm/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/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/examples/speech_recognition/kaldi/kaldi_initializer.py
EXA-1-master
exa/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/edgelm/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/models/unilm-master/edgelm/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/edgelm/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/edgelm/examples/speech_recognition/models/w2l_conv_glu_enc.py
EXA-1-master
exa/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/examples/speech_recognition/new/decoders/viterbi_decoder.py
EXA-1-master
exa/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/edgelm/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/edgelm/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/edgelm/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/edgelm/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/edgelm/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/edgelm/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/models/unilm-master/edgelm/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/edgelm/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/edgelm/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/edgelm/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/edgelm/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/edgelm/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/edgelm/examples/adaptive_span/adaptive_span_loss.py
../truncated_bptt/truncated_bptt_lm_task.py
EXA-1-master
exa/models/unilm-master/edgelm/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/edgelm/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/edgelm/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/models/unilm-master/edgelm/examples/bart/summarize.py
# Copyright (c) Facebook, Inc. and 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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/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/models/unilm-master/edgelm/examples/MMPT/mmpt/datasets/__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 from collections import OrderedDict from torch.utils.data import Dataset from torch.utils.data.dataloader import default_collat...
EXA-1-master
exa/models/unilm-master/edgelm/examples/MMPT/mmpt/datasets/mmdataset.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import random import numpy as np import torch from .shardedtensor import * from .load_config import * def set_seed(seed=43211): random.s...
EXA-1-master
exa/models/unilm-master/edgelm/examples/MMPT/mmpt/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 os import omegaconf from omegaconf import OmegaConf def load_config(args=None, config_file=None, overwrite_fairseq=False): """TODO...
EXA-1-master
exa/models/unilm-master/edgelm/examples/MMPT/mmpt/utils/load_config.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import os import pickle import numpy as np class ShardedTensor(object): def __init__(self, data, starts): self.data = data ...
EXA-1-master
exa/models/unilm-master/edgelm/examples/MMPT/mmpt/utils/shardedtensor.py
# coding=utf-8 # Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team. # Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a cop...
EXA-1-master
exa/models/unilm-master/edgelm/examples/MMPT/mmpt/models/transformermodel.py
# Copyright (c) Facebook, Inc. and 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 .mmfusion import * from .transformermodel import * from .mmfusionnlg import * try: from .fairseqmmmodel import * except ImportError: ...
EXA-1-master
exa/models/unilm-master/edgelm/examples/MMPT/mmpt/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.models import ( BaseFairseqModel, register_model, register_model_architecture ) @register_model("mmmodel") class Fa...
EXA-1-master
exa/models/unilm-master/edgelm/examples/MMPT/mmpt/models/fairseqmmmodel.py
# coding=utf-8 # Copyright 2018 The Google AI Language Team Authors, Facebook AI Research authors and The HuggingFace Inc. team. # Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the L...
EXA-1-master
exa/models/unilm-master/edgelm/examples/MMPT/mmpt/models/mmfusionnlg.py
# coding=utf-8 # Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team. # Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a cop...
EXA-1-master
exa/models/unilm-master/edgelm/examples/MMPT/mmpt/models/mmfusion.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import os import random import json import numpy as np import torch import pickle import math from tqdm import tqdm class Predictor(object):...
EXA-1-master
exa/models/unilm-master/edgelm/examples/MMPT/mmpt/evaluators/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 .metric import * from .evaluator import * # experimental. try: from .expmetric import * except ImportError: pass
EXA-1-master
exa/models/unilm-master/edgelm/examples/MMPT/mmpt/evaluators/__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 numpy as np import json class Metric(object): def __init__(self, config, metric_names): self.metric_names = metric_names ...
EXA-1-master
exa/models/unilm-master/edgelm/examples/MMPT/mmpt/evaluators/metric.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import os import glob import numpy as np from . import metric as metric_path from . import predictor as predictor_path class Evaluator(objec...
EXA-1-master
exa/models/unilm-master/edgelm/examples/MMPT/mmpt/evaluators/evaluator.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import random import json import pickle from tqdm import tqdm import os import numpy as np class CaptionDedupProcessor(object): """remov...
EXA-1-master
exa/models/unilm-master/edgelm/examples/MMPT/mmpt/processors/dedupprocessor.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from .how2processor import ( ShardedHow2MetaProcessor, ShardedVideoProcessor, ShardedTextProcessor, VariedLenAligner, Over...
EXA-1-master
exa/models/unilm-master/edgelm/examples/MMPT/mmpt/processors/how2retriprocessor.py
# Copyright (c) Facebook, Inc. and 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 .processor import * from .how2processor import * from .how2retriprocessor import * from .dsprocessor import * try: from .rawvideopr...
EXA-1-master
exa/models/unilm-master/edgelm/examples/MMPT/mmpt/processors/__init__.py
# Copyright (c) Facebook, Inc. All Rights Reserved import numpy as np import os import torch class Processor(object): """ A generic processor for video (codec, feature etc.) and text. """ def __call__(self, **kwargs): raise NotImplementedError class MetaProcessor(Processor): """ A ...
EXA-1-master
exa/models/unilm-master/edgelm/examples/MMPT/mmpt/processors/processor.py
# Copyright (c) Facebook, Inc. All Rights Reserved """ Processors for all downstream (ds) tasks. """ import json import os import pickle import random import math import numpy as np import torch from collections import defaultdict from .processor import ( MetaProcessor, VideoProcessor, TextProcessor, ...
EXA-1-master
exa/models/unilm-master/edgelm/examples/MMPT/mmpt/processors/dsprocessor.py
# coding=utf-8 # Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team. # Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a cop...
EXA-1-master
exa/models/unilm-master/edgelm/examples/MMPT/mmpt/processors/how2processor.py
# This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. """Contains a PyTorch definition for Gated Separable 3D network (S3D-G) with a text module for computing joint text-video embedding from raw text and video input. The following code will enable y...
EXA-1-master
exa/models/unilm-master/edgelm/examples/MMPT/mmpt/processors/models/s3dg.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import os import numpy as np import pickle import time try: import faiss except ImportError: pass from collections import defaultdict...
EXA-1-master
exa/models/unilm-master/edgelm/examples/MMPT/mmpt/modules/retri.py
# Copyright (c) Facebook, Inc. and 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 .mm import * try: from .expmm import * except ImportError: pass
EXA-1-master
exa/models/unilm-master/edgelm/examples/MMPT/mmpt/modules/__init__.py