repo stringlengths 2 99 | file stringlengths 13 225 | code stringlengths 0 18.3M | file_length int64 0 18.3M | avg_line_length float64 0 1.36M | max_line_length int64 0 4.26M | extension_type stringclasses 1
value |
|---|---|---|---|---|---|---|
sign-topic | sign-topic-main/examples/criss/mining/mine.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 argparse
import glob
from subprocess import check_call
try:
import faiss
has_faiss = True
except Imp... | 8,138 | 32.771784 | 87 | py |
sign-topic | sign-topic-main/examples/backtranslation/extract_bt_data.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... | 2,509 | 33.383562 | 89 | py |
sign-topic | sign-topic-main/examples/backtranslation/deduplicate_lines.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_... | 1,221 | 28.095238 | 68 | py |
sign-topic | sign-topic-main/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.
import argparse
import json
import logging
from pathlib import Path
import random
import soundfile as sf
import torch
from tqdm import tqdm
... | 3,285 | 27.08547 | 107 | py |
sign-topic | sign-topic-main/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.
| 177 | 34.6 | 65 | py |
sign-topic | sign-topic-main/examples/speech_to_speech/benchmarking/core.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... | 17,782 | 35.440574 | 131 | py |
sign-topic | sign-topic-main/examples/speech_to_speech/benchmarking/data_utils.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... | 7,893 | 28.788679 | 127 | py |
sign-topic | sign-topic-main/examples/speech_to_speech/benchmarking/get_metrics.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... | 5,053 | 30.006135 | 115 | py |
sign-topic | sign-topic-main/examples/speech_to_speech/preprocessing/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 pathlib import Path
from typing import List, Optional
from examples.speech_to_text.data_utils import S2TDataConfigWriter
def gen_confi... | 2,211 | 30.15493 | 84 | py |
sign-topic | sign-topic-main/examples/speech_to_speech/preprocessing/prep_s2ut_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 tqdm import tqdm
import pandas as ... | 3,891 | 29.170543 | 125 | py |
sign-topic | sign-topic-main/examples/speech_to_speech/preprocessing/prep_s2spect_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 ... | 5,844 | 33.382353 | 125 | py |
sign-topic | sign-topic-main/examples/speech_to_speech/preprocessing/__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.
| 177 | 34.6 | 65 | py |
sign-topic | sign-topic-main/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 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... | 3,174 | 30.435644 | 88 | py |
sign-topic | sign-topic-main/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 os, sys
import subprocess
import re
from subprocess import check_call, check_output
WORKDIR_ROOT = os.environ.get('WORKDIR_ROOT', Non... | 2,761 | 39.617647 | 111 | py |
sign-topic | sign-topic-main/examples/multilingual/data_scripts/remove_valid_test_in_train.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):
... | 11,158 | 37.47931 | 159 | py |
sign-topic | sign-topic-main/examples/multilingual/data_scripts/binarize.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... | 6,944 | 33.552239 | 160 | py |
sign-topic | sign-topic-main/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.
import os
import glob
import argparse
from utils.dedup import deup
import sys
WORKDIR_ROOT = os.environ.get('WORKDIR_ROOT', None)
if WORKDI... | 3,695 | 34.538462 | 109 | py |
sign-topic | sign-topic-main/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 glob
import argparse
from utils.dedup import deup
import sys
WORKDIR_ROOT = os.environ.get('WORKDIR_ROOT', None)
if WORKD... | 1,796 | 32.90566 | 109 | py |
sign-topic | sign-topic-main/examples/multilingual/data_scripts/download_wmt19_and_before.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... | 37,648 | 40.832222 | 294 | py |
sign-topic | sign-topic-main/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
import argparse
import pandas as pd
import sys
WORKDIR_ROOT = os.environ.get('WORKDIR_ROOT', None)
if WORKDIR_ROOT is None or n... | 4,515 | 35.128 | 129 | py |
sign-topic | sign-topic-main/examples/multilingual/data_scripts/download_ted_and_extract.py | # Copyright (c) Facebook, Inc. and 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... | 12,515 | 35.920354 | 133 | py |
sign-topic | sign-topic-main/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.
#!/bin/python
import fasttext
from multiprocessing import Pool
import contextlib
import sys
import argparse
from functools import partial
im... | 2,340 | 35.578125 | 107 | py |
sign-topic | sign-topic-main/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 argparse
def deup(src_file, tgt_file, src_file_out, tgt_file_out):
seen = set()
dup_count = 0
with open(src_file, encodin... | 1,459 | 33.761905 | 76 | py |
sign-topic | sign-topic-main/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.
import math
import torch
import torch.nn as nn
import torch.nn.functional as F
class AdaptiveMask(nn.Module):
"""Soft masking function f... | 5,881 | 35.534161 | 85 | py |
sign-topic | sign-topic-main/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.
from torch.optim import Adagrad
from fairseq.optim import LegacyFairseqOptimizer, register_optimizer
@register_optimizer("adagrad_with_grad... | 4,374 | 32.914729 | 92 | py |
sign-topic | sign-topic-main/examples/adaptive_span/adaptive_span_model.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... | 8,540 | 31.352273 | 87 | py |
sign-topic | sign-topic-main/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 math
from dataclasses import dataclass
import torch.nn.functional as F
from fairseq import metrics, utils
from fairseq.criterions impo... | 4,233 | 38.570093 | 88 | py |
sign-topic | sign-topic-main/examples/adaptive_span/adaptive_span_model_wrapper.py | # Copyright (c) Facebook, Inc. and 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... | 4,692 | 31.143836 | 114 | py |
sign-topic | sign-topic-main/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 importlib
import os
# automatically import any Python files in the current directory
cur_dir = os.path.dirname(__file__)
for file in o... | 669 | 32.5 | 77 | py |
sign-topic | sign-topic-main/examples/adaptive_span/truncated_bptt_lm_task.py | ../truncated_bptt/truncated_bptt_lm_task.py | 43 | 43 | 43 | py |
sign-topic | sign-topic-main/examples/MMPT/setup.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="[email protected]",
description="A package for multimodal pretraining.",
long_description=long_description,
long_descr... | 668 | 25.76 | 59 | py |
sign-topic | sign-topic-main/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.
import argparse
import os
from omegaconf import OmegaConf
from mmpt.utils import recursive_config, overwrite_dir
from mmpt_cli.localjob impor... | 5,336 | 34.818792 | 85 | py |
sign-topic | sign-topic-main/examples/MMPT/mmpt_cli/localjob.py | # Copyright (c) Facebook, Inc. and 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 mmpt.utils import recursive_config
class BaseJob(object):
def __init__(self, yaml_file, dryrun=False):
self.yaml_... | 3,794 | 31.161017 | 120 | py |
sign-topic | sign-topic-main/examples/MMPT/mmpt_cli/predict.py | # Copyright (c) Facebook, Inc. and 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
import pprint
import omegaconf
from omegaconf import OmegaConf
from torch.utils.data import DataLoader
... | 3,937 | 33.54386 | 81 | py |
sign-topic | sign-topic-main/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.
try:
# fairseq user dir
from .datasets import FairseqMMDataset
from .losses import FairseqCriterion
from .models import Fairseq... | 394 | 29.384615 | 65 | py |
sign-topic | sign-topic-main/examples/MMPT/mmpt/modules/mm.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... | 5,537 | 36.931507 | 83 | py |
sign-topic | sign-topic-main/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.
import os
import numpy as np
import pickle
import time
try:
import faiss
except ImportError:
pass
from collections import defaultdict... | 15,471 | 34.981395 | 117 | py |
sign-topic | sign-topic-main/examples/MMPT/mmpt/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.
from .mm import *
try:
from .expmm import *
except ImportError:
pass
| 255 | 22.272727 | 65 | py |
sign-topic | sign-topic-main/examples/MMPT/mmpt/modules/vectorpool.py | # Copyright (c) Facebook, Inc. All Rights Reserved
import torch
import os
import numpy as np
import pickle
from . import retri
from ..utils import get_local_rank
class VectorPool(object):
"""
Base class of retrieval space.
"""
def __init__(self, config):
from transformers import AutoConfig
... | 8,278 | 32.518219 | 82 | py |
sign-topic | sign-topic-main/examples/MMPT/mmpt/models/transformermodel.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... | 26,064 | 34.462585 | 87 | py |
sign-topic | sign-topic-main/examples/MMPT/mmpt/models/fairseqmmmodel.py | # Copyright (c) Facebook, Inc. and 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... | 1,417 | 26.269231 | 65 | py |
sign-topic | sign-topic-main/examples/MMPT/mmpt/models/mmfusionnlg.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... | 48,394 | 47.395 | 246 | py |
sign-topic | sign-topic-main/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 .mmfusion import *
from .transformermodel import *
from .mmfusionnlg import *
try:
from .fairseqmmmodel import *
except ImportError:
... | 395 | 21 | 65 | py |
sign-topic | sign-topic-main/examples/MMPT/mmpt/models/mmfusion.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... | 30,634 | 32.047465 | 90 | py |
sign-topic | sign-topic-main/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.
"""
TODO (huxu): fairseq wrapper class for all dataset you defined: mostly MMDataset.
"""
from collections import OrderedDict
from torch.util... | 1,785 | 29.793103 | 85 | py |
sign-topic | sign-topic-main/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 torch
from collections import OrderedDict
from torch.utils.data import Dataset
from torch.utils.data.dataloader import default_collat... | 3,873 | 33.589286 | 76 | py |
sign-topic | sign-topic-main/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.
from .mmdataset import *
try:
from .fairseqmmdataset import *
except ImportError:
pass
| 273 | 23.909091 | 65 | py |
sign-topic | sign-topic-main/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.
import os
import random
import json
import numpy as np
import torch
import pickle
import math
from tqdm import tqdm
class Predictor(object):... | 23,125 | 37.802013 | 113 | py |
sign-topic | sign-topic-main/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 os
import glob
import numpy as np
from . import metric as metric_path
from . import predictor as predictor_path
class Evaluator(objec... | 2,026 | 35.854545 | 74 | py |
sign-topic | sign-topic-main/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.
from .metric import *
from .evaluator import *
# experimental.
try:
from .expmetric import *
except ImportError:
pass
| 305 | 20.857143 | 65 | py |
sign-topic | sign-topic-main/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 numpy as np
import json
class Metric(object):
def __init__(self, config, metric_names):
self.metric_names = metric_names
... | 10,898 | 33.710191 | 138 | py |
sign-topic | sign-topic-main/examples/MMPT/mmpt/processors/how2processor.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... | 32,302 | 35.377252 | 88 | py |
sign-topic | sign-topic-main/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.
import random
import json
import pickle
from tqdm import tqdm
import os
import numpy as np
class CaptionDedupProcessor(object):
"""remov... | 8,834 | 35.358025 | 85 | py |
sign-topic | sign-topic-main/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 .how2processor import (
ShardedHow2MetaProcessor,
ShardedVideoProcessor,
ShardedTextProcessor,
VariedLenAligner,
Over... | 3,742 | 36.059406 | 130 | py |
sign-topic | sign-topic-main/examples/MMPT/mmpt/processors/processor.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 ... | 9,358 | 33.032727 | 86 | py |
sign-topic | sign-topic-main/examples/MMPT/mmpt/processors/__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 .processor import *
from .how2processor import *
from .how2retriprocessor import *
from .dsprocessor import *
try:
from .rawvideopr... | 652 | 26.208333 | 65 | py |
sign-topic | sign-topic-main/examples/MMPT/mmpt/processors/dsprocessor.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,
... | 29,891 | 34.208481 | 104 | py |
sign-topic | sign-topic-main/examples/MMPT/mmpt/processors/models/s3dg.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... | 12,416 | 35.845697 | 94 | py |
sign-topic | sign-topic-main/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 omegaconf
from omegaconf import OmegaConf
def load_config(args=None, config_file=None, overwrite_fairseq=False):
"""TODO... | 3,155 | 37.487805 | 88 | py |
sign-topic | sign-topic-main/examples/MMPT/mmpt/utils/shardedtensor.py | # Copyright (c) Facebook, Inc. and 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
... | 1,410 | 29.021277 | 65 | py |
sign-topic | sign-topic-main/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 random
import numpy as np
import torch
from .shardedtensor import *
from .load_config import *
def set_seed(seed=43211):
random.s... | 1,886 | 26.347826 | 77 | py |
sign-topic | sign-topic-main/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 os
import torch
import pickle
import random
from tqdm import tqdm
from torch.utils.data import DataLoader
from torch.utils.data.distrib... | 8,413 | 32.125984 | 82 | py |
sign-topic | sign-topic-main/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 MILNCETask(Task):
def reshape_subsample(self, sample):
if (
hasattr(self.... | 954 | 33.107143 | 65 | py |
sign-topic | sign-topic-main/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.
import torch
from .. import tasks
from .. import models
from .. import losses
from ..datasets import MMDataset
from .. import processors
cla... | 6,780 | 35.654054 | 81 | py |
sign-topic | sign-topic-main/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.
import torch
from .task import Task
class VLMTask(Task):
"""A VLM task for reproducibility.
the collator split subsamples into two s... | 856 | 29.607143 | 67 | py |
sign-topic | sign-topic-main/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.
"""
make a general fairseq task for MM pretraining.
"""
import random
from fairseq.tasks import LegacyFairseqTask, register_task
from .task ... | 3,045 | 28.009524 | 85 | py |
sign-topic | sign-topic-main/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.
from .task import *
from .vlmtask import *
from .retritask import *
try:
from .fairseqmmtask import *
except ImportError:
pass
try:
... | 445 | 18.391304 | 65 | py |
sign-topic | sign-topic-main/examples/MMPT/mmpt/losses/loss.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... | 2,095 | 22.818182 | 83 | py |
sign-topic | sign-topic-main/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.
"""
TODO (huxu): a general fairseq criterion for all your pre-defined losses.
"""
from fairseq.criterions import FairseqCriterion, register_c... | 2,233 | 33.90625 | 79 | py |
sign-topic | sign-topic-main/examples/MMPT/mmpt/losses/__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... | 345 | 19.352941 | 65 | py |
sign-topic | sign-topic-main/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.
"""
softmax-based NCE loss, used by this project.
"""
import torch
from torch import nn
from .loss import Loss
class NCE(Loss):
def _... | 4,586 | 28.216561 | 75 | py |
sign-topic | sign-topic-main/examples/MMPT/scripts/text_token_extractor/pretokenization.py | # Copyright (c) Facebook, Inc. and 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 pickle
import os
import argparse
import numpy as np
from torch.utils.data import Dataset, DataLoader
from mmpt.processors import PKLJS... | 3,408 | 30.859813 | 87 | py |
sign-topic | sign-topic-main/examples/MMPT/scripts/video_feature_extractor/videoreader.py | # Copyright Howto100M authors.
# Copyright (c) Facebook, Inc. All Rights Reserved
import torch as th
import pandas as pd
import os
import numpy as np
import ffmpeg
import random
from torch.utils.data import Dataset
class VideoLoader(Dataset):
"""modified from how2's video_feature_extractor."""
def __init__(... | 8,322 | 33.251029 | 86 | py |
sign-topic | sign-topic-main/examples/MMPT/scripts/video_feature_extractor/preprocessing.py | # Copyright Howto100m authors.
# Copyright (c) Facebook, Inc. All Rights Reserved
import torch as th
class Normalize(object):
def __init__(self, mean, std):
self.mean = th.FloatTensor(mean).view(1, 3, 1, 1)
self.std = th.FloatTensor(std).view(1, 3, 1, 1)
def __call__(self, tensor):
t... | 2,071 | 34.724138 | 98 | py |
sign-topic | sign-topic-main/examples/MMPT/scripts/video_feature_extractor/model.py | # Copyright (c) Howto100M authors and Facebook, Inc. All Rights Reserved
import torch as th
from torch import nn
class GlobalAvgPool(nn.Module):
def __init__(self):
super(GlobalAvgPool, self).__init__()
def forward(self, x):
return th.mean(x, dim=[-2, -1])
def get_model(args):
assert ... | 1,921 | 31.576271 | 92 | py |
sign-topic | sign-topic-main/examples/MMPT/scripts/video_feature_extractor/extract.py | # Copyright Howto100M authors.
# Copyright (c) Facebook, Inc. All Rights Reserved
import torch as th
import torch.nn.functional as F
import math
import numpy as np
import argparse
from torch.utils.data import DataLoader
from model import get_model
from preprocessing import Preprocessing
from random_sequence_shuffler ... | 5,529 | 34 | 116 | py |
sign-topic | sign-topic-main/examples/MMPT/scripts/video_feature_extractor/random_sequence_shuffler.py | # Copyright (c) Facebook, Inc. All Rights Reserved
import numpy as np
from torch.utils.data.sampler import Sampler
class RandomSequenceSampler(Sampler):
def __init__(self, n_sample, seq_len):
self.n_sample = n_sample
self.seq_len = seq_len
def _pad_ind(self, ind):
zeros = np.zeros(... | 829 | 26.666667 | 76 | py |
sign-topic | sign-topic-main/examples/MMPT/scripts/video_feature_extractor/shard_feature.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
import os
import pickle
from mmpt.utils import ShardedTensor
class Shard(object):
def __init__(
self,
... | 2,166 | 32.338462 | 97 | py |
sign-topic | sign-topic-main/examples/MMPT/scripts/video_feature_extractor/pathbuilder.py | # Copyright (c) Facebook, Inc. and 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 urllib.parse
import json
import pandas as pd
from tqdm import tqdm
# TODO: extending to other datasets.
supported_formats =... | 3,410 | 36.9 | 78 | py |
sign-topic | sign-topic-main/examples/translation_moe/score.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... | 6,110 | 29.863636 | 87 | py |
sign-topic | sign-topic-main/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.
import torch
import torch.nn.functional as F
class MeanPoolGatingNetwork(torch.nn.Module):
"""A simple mean-pooling gating network for s... | 2,011 | 38.45098 | 84 | py |
sign-topic | sign-topic-main/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
class LogSumExpMoE(torch.autograd.Function):
"""Standard LogSumExp forward pass, but use *posterior* for the backward.
... | 837 | 30.037037 | 78 | py |
sign-topic | sign-topic-main/examples/translation_moe/translation_moe_src/translation_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... | 9,484 | 35.621622 | 95 | py |
sign-topic | sign-topic-main/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.
from . import translation_moe # noqa
| 216 | 30 | 65 | py |
sign-topic | sign-topic-main/examples/laser/laser_src/laser_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.
from collections import OrderedDict, defaultdict
import json
import os
import logging
from argparse import ArgumentError
from fairseq import... | 11,085 | 32.092537 | 134 | py |
sign-topic | sign-topic-main/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.
import logging
from typing import Any, Dict, List, Optional
from torch import Tensor
import torch
import torch.nn as nn
from fairseq.models... | 11,947 | 32.656338 | 88 | py |
sign-topic | sign-topic-main/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 torch
import torch.nn as nn
import torch.nn.functional as F
from fairseq import options, utils
from fairseq.models import (
Fairs... | 20,672 | 34.278157 | 89 | py |
sign-topic | sign-topic-main/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 collections import OrderedDict
import numpy as np
from fairseq.data import BaseWrapperDataset, FairseqDataset, iterators
class MultiI... | 4,332 | 29.090278 | 84 | py |
sign-topic | sign-topic-main/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 .laser_task import * # noqa
from .laser_lstm import * # noqa
from .laser_transformer import * # noqa
| 287 | 31 | 65 | py |
sign-topic | sign-topic-main/examples/text_classification/format_data.py | '''
Ingests csv files with VIDEO ID - TEXT mapping and
prepares data to fit into the data format expected by fairseq's RoBERTa.
'''
import pandas as pd
def main():
for split in ['train', 'test', 'val']:
data = pd.read_csv(f'{split}_filt.csv', sep='\t')
f1 = open(split + '.input0', 'w')
f... | 603 | 26.454545 | 96 | py |
sign-topic | sign-topic-main/examples/text_classification/utils.py | import re
from typing import Dict
from typing import List
from typing import Union
from pathlib import Path
import pdb
import csv
import h5py
import numpy as np
import pandas as pd
from tqdm import tqdm
def save_df_to_tsv(dataframe, path: Union[str, Path]):
_path = path if isinstance(path, str) else path.as_posi... | 2,753 | 28.297872 | 96 | py |
sign-topic | sign-topic-main/examples/text_classification/prep_how2sign.py | #!/usr/bin/env python3
# This code is based on the speech_to_text implementation (commit: d974c70)
#
# Copyright (c) Facebook, Inc. and 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 errno
import os
import h5py
impor... | 3,974 | 29.576923 | 100 | py |
sign-topic | sign-topic-main/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 sys
def _normalize_spaces(line):
return " ".join(line.split())
def main():
parser = argparse.ArgumentParser... | 828 | 27.586207 | 76 | py |
sign-topic | sign-topic-main/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
import numpy as np
aggregate_funcs = {
"std": np.std,
"var": np.var,
"median": np.median,
"mean"... | 1,136 | 26.071429 | 83 | py |
sign-topic | sign-topic-main/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.
import argparse
import math
import os
import subprocess
import sys
import tempfile
from collections import defaultdict
from itertools import c... | 3,472 | 30.572727 | 105 | py |
sign-topic | sign-topic-main/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 fairseq.tasks import register_task
from fairseq.tasks.multilingual_translation import MultilingualTranslationTask
from fairseq.utils impo... | 8,592 | 42.841837 | 116 | py |
sign-topic | sign-topic-main/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.
from . import multilingual_translation_latent_depth # noqa
from .loss import latent_depth # noqa
from .models import latent_multilingual_tra... | 380 | 37.1 | 65 | py |
sign-topic | sign-topic-main/examples/latent_depth/latent_depth_src/modules/__init__.py | 0 | 0 | 0 | py | |
sign-topic | sign-topic-main/examples/latent_depth/latent_depth_src/modules/latent_layers.py | # Copyright (c) Facebook, Inc. and 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... | 2,605 | 33.289474 | 83 | py |
sign-topic | sign-topic-main/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 fairseq.models import register_model, register_model_architecture
from fairseq.models.multilingual_transformer import MultilingualTransfo... | 3,211 | 40.714286 | 88 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.