python_code stringlengths 0 4.04M | repo_name stringlengths 7 58 | file_path stringlengths 5 147 |
|---|---|---|
# Download from https://cs.nyu.edu/~ylclab/data/norb-v1.0/
import sys
import pickle as pkl
# sys.path.insert(0, '../../')
import numpy as np
from sklearn.preprocessing import OneHotEncoder
from norb import NORBDataset
from scipy.misc import imresize
from data_utils import normalize_data, apply_normalization
MAX_VAL =... | structured-nets-master | scripts/data/preprocess_norb.py |
# Download from http://www.iro.umontreal.ca/~lisa/twiki/bin/view.cgi/Public/DeepVsShallowComparisonICML2007
import numpy as np
import pickle as pkl
from sklearn.preprocessing import OneHotEncoder
from data_utils import normalize_data, apply_normalization
def process_data(data):
X = data[:, :-1]
Y = np.expand_... | structured-nets-master | scripts/data/preprocess_mnist_bg_rot.py |
import numpy as np
import os,sys,h5py
import scipy.io as sio
from scipy.linalg import solve_sylvester
import pickle as pkl
from sklearn.preprocessing import OneHotEncoder
import torch
from torchvision import datasets, transforms
import utils
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
de... | structured-nets-master | pytorch/dataset.py |
import torch
import torch.nn as nn
def mse_loss(pred, true):
loss_fn = nn.MSELoss()
mse = loss_fn(pred, true)
accuracy = torch.FloatTensor([0])
return mse, accuracy
def cross_entropy_loss(pred, true):
loss_fn = nn.CrossEntropyLoss()
_, true_argmax = torch.max(true, 1)
cross_entropy = loss... | structured-nets-master | pytorch/utils.py |
import sys, os, datetime, subprocess
import pickle as pkl
import itertools
import argparse, argh
import threading
import logging
import pprint
import numpy as np
import torch
from torch.optim.lr_scheduler import StepLR
from inspect import signature
# Add PyTorch root to path
pytorch_root = os.path.join(os.path.dirname... | structured-nets-master | pytorch/main.py |
import numpy as np
import os, time, logging
import pickle as pkl
import torch
import torch.optim as optim
from torch.optim.lr_scheduler import StepLR
from tensorboardX import SummaryWriter
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
def test_split(net, dataloader, loss_fn):
n = len(dat... | structured-nets-master | pytorch/learning/train.py |
import numpy as np
from learning import train
import torch
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
def generate_mask(W, prune_factor):
weights = W.W.cpu().data.numpy()
N = int(weights.size/prune_factor)
# Get indices of N highest magnitude weights
idx = np.abs(weights.f... | structured-nets-master | pytorch/learning/prune.py |
import numpy as np
import os, sys
sys.path.insert(0, '../../pytorch/')
import torch
from torch_utils import *
from torch.autograd import Variable
import torch.optim as optim
from torchtext import data, datasets
import spacy
from tensorboardX import SummaryWriter
sys.path.insert(0, '../../pytorch/attention/')
from atten... | structured-nets-master | pytorch/old/misc/attention/optimize_iwslt.py |
"""
http://nlp.seas.harvard.edu/2018/04/03/attention.html
"""
import sys
sys.path.insert(0, '../')
from structured_layer import *
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
import copy, math
import numpy as np
class EncoderDecoder(nn.Module):
"""
A s... | structured-nets-master | pytorch/old/misc/attention/attention.py |
import numpy as np
import os, sys
sys.path.insert(0, '../../pytorch/')
import torch
from torch_utils import *
from torch.autograd import Variable
import torch.optim as optim
from tensorboardX import SummaryWriter
sys.path.insert(0, '../../pytorch/attention/')
from attention import *
sys.path.insert(0, '../../')
from da... | structured-nets-master | pytorch/old/misc/attention/optimize_nmt.py |
import torch
import torch.nn as nn
import torch.nn.functional as F
import math, copy, time
from torch.autograd import Variable
import matplotlib.pyplot as plt
import numpy as np
from attention import *
from torchtext import data, datasets
# Skip if not interested in multigpu.
class MultiGPULossCompute:
"A multi-g... | structured-nets-master | pytorch/old/misc/attention/train.py |
import copy
import numpy as np
import torch
import torch.nn.functional as F
from torchvision import transforms
from torch.autograd import Variable
use_cuda = torch.cuda.is_available()
def get_train_valid_datasets(dataset,
valid_size=0.1,
random_seed=None,
... | structured-nets-master | pytorch/old/misc/circtest/utils.py |
import numpy as np
import math
import torch
import torch.optim as optim
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.parameter import Parameter
from torchvision import datasets, transforms
from torch import autograd
from torch.autograd import Variable
from utils import get_train_valid_datasets,... | structured-nets-master | pytorch/old/misc/circtest/circulant.py |
# -*- coding: utf-8 -*-
"""
Classifying Names with a Character-Level RNN
*********************************************
**Author**: `Sean Robertson <https://github.com/spro/practical-pytorch>`_
We will be building and training a basic character-level RNN to classify
words. A character-level RNN reads words as a series ... | structured-nets-master | pytorch/old/misc/charRNN/char_rnn_classification_tutorial.py |
import torch
import functools
import numpy as np
from torch.autograd import Variable
import time
# Down shift
def Z_mult_fn(f, x):
return torch.cat((f * x[-1], x[:-1]))
# Up shift
def Z_transpose_mult_fn(f, x):
#print('x[1:]: ', x[1:])
#print('f*x[0]: ', f*x[0])
#return torch.cat((x[1:], torch.FloatTe... | structured-nets-master | pytorch/old/utils/torch_krylov.py |
import torch
from torch.autograd import Variable
import time
from torch_utils import *
from torch_krylov import *
from scipy.linalg import toeplitz
import numpy as np
import functools
def krylov(fn, v, n):
cols = [v]
for _ in range(n - 1):
v = fn(v)
cols.append(v)
return torch.stack(cols, d... | structured-nets-master | pytorch/old/utils/torch_reconstruction.py |
import torch
import torch.nn as nn
from torch.autograd import Variable
import numpy as np
# Circulant sparsity pattern
def gen_Z_f(m, f, v=None):
if v is not None:
assert v.size <= m-1
I_m = np.eye(m-1, m-1)
Z_f = np.hstack((I_m, np.zeros((m-1, 1))))
Z_f = np.vstack((np.zeros((1, m)), Z_f))
... | structured-nets-master | pytorch/old/utils/torch_utils.py |
from inspect import signature
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.parameter import Parameter
import structure.LDR as ldr
import structure.layer as sl
def construct_model(cls, in_size, out_size, args):
args_fn = cls.args
options = {param: vars(ar... | structured-nets-master | pytorch/models/nets.py |
"""
Modified from pytorch/examples/word_language_model to demonstrate 'StructuredLinear' usage.
"""
###############################################################################
# Language Modeling on Penn Tree Bank
#
# This file generates new sentences sampled from the language model
#
#############################... | structured-nets-master | pytorch/examples/word_language_model/generate.py |
"""
Modified from pytorch/examples/word_language_model to demonstrate 'StructuredLinear' usage.
"""
import torch.nn as nn
from torch.nn import Parameter
import torch
import numpy as np
import sys
from lstm import SingleLayerLSTM, LSTMCell
class RNNModel(nn.Module):
"""Container module with an encoder, a recurrent... | structured-nets-master | pytorch/examples/word_language_model/model.py |
"""
Some parts modified from https://github.com/jihunchoi/recurrent-batch-normalization-pytorch/blob/master/bnlstm.py
"""
import torch
from torch import nn
from torch.nn import init
from torch.autograd import Variable
import sys
sys.path.insert(0, '../../../pytorch/')
import structure.layer as sl
class LSTMCell(nn.Mo... | structured-nets-master | pytorch/examples/word_language_model/lstm.py |
"""
Modified from pytorch/examples/word_language_model to demonstrate 'StructuredLinear' usage.
"""
# coding: utf-8
import argparse, os
import time
import math
import torch
import torch.nn as nn
import pickle as pkl
import data
import model
parser = argparse.ArgumentParser(description='PyTorch Wikitext-2 RNN/LSTM La... | structured-nets-master | pytorch/examples/word_language_model/main.py |
"""
Modified from pytorch/examples/word_language_model to demonstrate 'StructuredLinear' usage.
"""
import os
import torch
class Dictionary(object):
def __init__(self):
self.word2idx = {}
self.idx2word = []
def add_word(self, word):
if word not in self.word2idx:
self.idx2w... | structured-nets-master | pytorch/examples/word_language_model/data.py |
"""
Modified from pytorch/examples/vae to demonstrate 'StructuredLinear' usage.
"""
from __future__ import print_function
import argparse, sys, os
import torch
import torch.utils.data
from torch import nn, optim
from torch.nn import functional as F
from torchvision import datasets, transforms
from torchvision.utils im... | structured-nets-master | pytorch/examples/vae/main.py |
''' Utility functions for handling complex tensors: conjugate and complex_mult.
Pytorch (as of 0.4.0) does not support complex tensors, so we store them as
float tensors where the last dimension is 2 (real and imaginary parts).
'''
import torch
def conjugate(X):
assert X.shape[-1] == 2, 'Last dimension must be 2... | structured-nets-master | pytorch/structure/complex_utils.py |
import numpy as np
import scipy.fftpack as fft
import itertools
from scipy import signal
class KT_Toeplitz():
"""Multiply Krylov(A, v)^T @ u when A is zero except on the subdiagonal.
"""
def __init__(self, n, f=0, batch_size=1, rank=1):
m = int(np.log2(n))
assert n == 1 << m, 'n must be a... | structured-nets-master | pytorch/structure/toeplitz_cpu.py |
import torch
from torch.autograd import Variable
import torch.nn as nn
from torch.nn.parameter import Parameter
from . import toeplitz as toep
from . import krylov as kry
# TODO: rewrite with structure.layer
# TODO: subclass with each DR type
class LDR(nn.Module):
def name(self):
return str(self.in_chann... | structured-nets-master | pytorch/structure/LDR.py |
import numpy as np
import torch
use_hadamard_transform_cuda = True
try:
import hadamard_cuda
# import torch.utils.cpp_extension
# hadamard_cuda = torch.utils.cpp_extension.load(
# name='hadamard_cuda',
# sources=[
# 'hadamard_cuda/hadamard_cuda.cpp',
# 'hadamard_cuda... | structured-nets-master | pytorch/structure/hadamard.py |
import numpy as np
import torch
import torch.nn as nn
from torch.nn.parameter import Parameter
from torch.autograd import Variable
from . import toeplitz as toep
from . import krylov as kry
from . import circulant as circ
from . import fastfood as ff
from utils import descendants
class Layer(nn.Module):
class_ty... | structured-nets-master | pytorch/structure/layer.py |
'''Functions to multiply by an LDR matrix with subdiagonal and tridiagonal
operator matrices.
We implement the fast multiplication for the subdiagonal case.
This comprises two steps: Krylov(g) @ Krylov(h)^T @ u, which are Krylov
transpose multiply and Krylov multiply.
For tridiagonal case, we implement the slow multi... | structured-nets-master | pytorch/structure/krylov.py |
import torch
from scipy.linalg import circulant
from .complex_utils import complex_mult
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
def circulant_multiply(c, x):
""" Multiply circulant matrix with first column c by x
Parameters:
c: (n, )
x: (batch_size, n) or (n, )
... | structured-nets-master | pytorch/structure/circulant.py |
from .hadamard import hadamard_transform
import torch
import numpy as np
from scipy.linalg import hadamard
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
# S,G,B: diagonal
# P: permutation
# x: batch_size x n_features
def fastfood_multiply(S,G,B,P,x):
HBx = hadamard_transform(B*x)
PHB... | structured-nets-master | pytorch/structure/fastfood.py |
'''Functions to multiply by a Toeplitz-like matrix.
'''
import numpy as np
import torch
from .complex_utils import complex_mult, conjugate
from .krylov import Krylov
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
##### Fast multiplication for the Toeplitz-like case
def toeplitz_krylov_tran... | structured-nets-master | pytorch/structure/toeplitz.py |
import torch.cuda
from setuptools import setup
from torch.utils.cpp_extension import CppExtension, CUDAExtension, BuildExtension
from torch.utils.cpp_extension import CUDA_HOME
ext_modules = []
if torch.cuda.is_available() and CUDA_HOME is not None:
extension = CUDAExtension(
'hadamard_cuda', [
... | structured-nets-master | pytorch/structure/hadamard_cuda/setup.py |
import numpy as np
import itertools
import pyfftw
import sys
sys.path.insert(0,'../../../pytorch/')
from structure.scratch.krylovslow import krylov_construct
# define fft calls
def _plan_ffts(in_shape, lib='numpy'):
out_shape = in_shape[:-1] + (in_shape[-1]//2 + 1,)
if lib == 'numpy':
x_for = np.zero... | structured-nets-master | pytorch/structure/scratch/krylovfast.py |
import os
os.environ['MKL_NUM_THREADS'] = '1'
os.environ['OMP_NUM_THREADS'] = '1'
os.environ['NUMEXPR_NUM_THREADS'] = '1'
os.environ['VECLIB_MAXIMUM_THREADS'] = '1'
import numpy as np
from krylovfast import *
from krylovslow import *
np.random.seed(0)
# n, m = 2, 1
# A = np.array([[0,0],[1,0]])
# u = np.array([1,1])... | structured-nets-master | pytorch/structure/scratch/tests_snippets.py |
import numpy as np
import itertools
p=2
d=3
N=p << (d-1)
f = np.arange(N)
print(np.fft.fft(f))
def init(f):
x = np.zeros(d*[p], dtype=np.complex_)
idx = [list(range(p)) for i in range(d)]
powers = np.array([p**i for i in range(d)])
for t in itertools.product(*idx):
x[t] = f[np.sum(powers*... | structured-nets-master | pytorch/structure/scratch/fft.py |
import numpy as np
import scipy.fftpack as fft
from scipy import signal
# should create a poly class later
p1 = np.full(5, 2)
p2 = np.full(10, 3)
def poly_add(p1, p2, n):
"""p1,p2 of degree exactly n-1"""
# TODO: change these to equals
assert p1.shape == (n,)
assert p2.shape == (n,)
# n = np.maxim... | structured-nets-master | pytorch/structure/scratch/krylovslow.py |
import torch.cuda
from setuptools import setup
from torch.utils.cpp_extension import CppExtension, CUDAExtension, BuildExtension
from torch.utils.cpp_extension import CUDA_HOME
ext_modules = []
if torch.cuda.is_available() and CUDA_HOME is not None:
extension = CUDAExtension(
'diag_mult_cuda', [
... | structured-nets-master | pytorch/structure/diag_mult_cuda/setup.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 setuptools import setup
with open("README.md") as f:
readme = f.read()
setup(
name="BLINK",
version... | BLINK-main | setup.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 re
import os
import pysolr
import sys
import blink.candidate_retrieval.utils as utils
def get_model(params):
... | BLINK-main | blink/candidate_generation.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 argparse
import prettytable
import blink.main_dense as main_dense
import blink.candidate_ranking.utils as utils
D... | BLINK-main | blink/run_benchmark.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.
#
from blink.candidate_ranking.bert_reranking import BertReranker
def get_model(params):
return BertReranker(params)
| BLINK-main | blink/reranker.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 pickle
import emoji
def get_model(parameters):
return Wikimedia_Data_Fetcher(parameters["path_to_candidate_da... | BLINK-main | blink/candidate_data_fetcher.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 argparse
import json
import sys
from tqdm import tqdm
import logging
import torch
import numpy as np
from colorama... | BLINK-main | blink/main_dense.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.
#
| BLINK-main | blink/__init__.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 argparse
import logging
import numpy
import os
import time
import torch
from blink.indexer.faiss_indexer import De... | BLINK-main | blink/build_faiss_index.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.
#
from flair.models import SequenceTagger
from flair.data import Sentence
def get_model(parameters=None):
return Flair... | BLINK-main | blink/ner.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 io
import json
import os
import pickle
from segtok.segmenter import split_multi
##### Reading helpers #####
def r... | BLINK-main | blink/utils.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 os
import blink.utils as utils
import blink.ner as NER
import blink.candidate_generation as CG
import blink.candid... | BLINK-main | blink/main_solr.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.
#
from multiprocessing.pool import ThreadPool
from candidate_generators import (
Simple_Candidate_Generator,
Pregene... | BLINK-main | blink/candidate_retrieval/perform_and_evaluate_candidate_retrieval_multithreaded.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 argparse
import pysolr
import pickle
import emoji
import time
import os
parser = argparse.ArgumentParser()
parser... | BLINK-main | blink/candidate_retrieval/data_ingestion.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 pickle
import os
import argparse
import sys
parser = argparse.ArgumentParser()
parser.add_argument(
"--output... | BLINK-main | blink/candidate_retrieval/link_wikipedia_and_wikidata.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 xml.etree.ElementTree as ET
import io
import re
import argparse
import os
import pickle
import sys
import urllib.pa... | BLINK-main | blink/candidate_retrieval/process_wiki_extractor_output_links.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 xml.etree.ElementTree as ET
import io
import re
import argparse
import os
import pickle
import sys
parser = argpar... | BLINK-main | blink/candidate_retrieval/process_wiki_extractor_output.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 re
import pickle
import os
import time
import numpy as np
"""
This script is adapted from https://github.com/lepho... | BLINK-main | blink/candidate_retrieval/dataset.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 sqlite3
import pickle
import os
import io
import argparse
import sys
parser = argparse.ArgumentParser()
parser.ad... | BLINK-main | blink/candidate_retrieval/enrich_data.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 sys
import pickle
import subprocess
import blink.candidate_retrieval.dataset as D
import re
import os
ESCAPE_CHAR... | BLINK-main | blink/candidate_retrieval/utils.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 pysolr
import sys
import utils
def mention_data_summary(mention):
return (mention["mention"], mention["query_... | BLINK-main | blink/candidate_retrieval/candidate_generators.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 xml.etree.ElementTree as ET
import io
import re
import argparse
import os
import pickle
import sys
parser = argpar... | BLINK-main | blink/candidate_retrieval/process_wiki_extractor_output_full.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 bz2
import sys
import pickle
import os
import json
import argparse
parser = argparse.ArgumentParser()
parser.add_... | BLINK-main | blink/candidate_retrieval/process_wikidata.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 os
import pickle
import nltk.data
import argparse
import sys
from tqdm import tqdm
parser = argparse.ArgumentPars... | BLINK-main | blink/candidate_retrieval/process_intro_sents.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 sqlite3
import pickle
import os
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
"--in... | BLINK-main | blink/candidate_retrieval/generate_wiki2wikidata_mappings.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 matplotlib.pyplot as plt
import numpy as np
from collections import Counter
class Evaluator:
def __init__(sel... | BLINK-main | blink/candidate_retrieval/evaluator.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 argparse
import pickle
import json
import emoji
import sys
import os
import io
import blink.candidate_retrieval.ut... | BLINK-main | blink/candidate_retrieval/json_data_generation.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 os
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from collections import O... | BLINK-main | blink/crossencoder/crossencoder.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 torch
import sys
import numpy as np
from tqdm import tqdm
import blink.biencoder.data_process as data
from blink.c... | BLINK-main | blink/crossencoder/data_process.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 os
import argparse
import pickle
import torch
import json
import sys
import io
import random
import time
import num... | BLINK-main | blink/crossencoder/train_cross.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 argparse
import json
import logging
import os
import torch
from tqdm import tqdm
from torch.utils.data import Dat... | BLINK-main | blink/biencoder/eval_biencoder.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.
#
# Utility code for zeshel dataset
import json
import torch
DOC_PATH = "/private/home/ledell/zeshel/data/documents/"
WOR... | BLINK-main | blink/biencoder/zeshel_utils.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 json
import logging
import torch
from tqdm import tqdm
import blink.candidate_ranking.utils as utils
from blink.b... | BLINK-main | blink/biencoder/nn_prediction.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.
#
| BLINK-main | blink/biencoder/__init__.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 logging
import torch
from tqdm import tqdm, trange
from torch.utils.data import DataLoader, TensorDataset
from py... | BLINK-main | blink/biencoder/data_process.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 os
import argparse
import pickle
import torch
import json
import sys
import io
import random
import time
import num... | BLINK-main | blink/biencoder/train_biencoder.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 os
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from tqdm import tqdm
fro... | BLINK-main | blink/biencoder/biencoder.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 torch
import os
import numpy as np
from pytorch_transformers.modeling_bert import (
BertPreTrainedModel,
B... | BLINK-main | blink/candidate_ranking/bert_reranking.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 os
import io
import sys
import json
import torch
import logging
import numpy as np
from collections import Ordere... | BLINK-main | blink/candidate_ranking/utils.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 os
import argparse
import pickle
import torch
import json
import sys
import io
import random
import sys
import time... | BLINK-main | blink/candidate_ranking/train.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 time
import utils
import torch
import utils
import argparse
import os
from bert_reranking import BertReranker
from... | BLINK-main | blink/candidate_ranking/evaluate.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.
#
# Provide an argument parser and default command line options for using BLINK.
import argparse
import importlib
import os... | BLINK-main | blink/common/params.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.
#
from torch import nn
def get_model_obj(model):
model = model.module if hasattr(model, "module") else model
retur... | BLINK-main | blink/common/ranker_base.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 torch
import os
import numpy as np
from pytorch_transformers.modeling_bert import (
BertPreTrainedModel,
B... | BLINK-main | blink/common/optimizer.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.
#
"""
FAISS-based index components. Original from
https://github.com/facebookresearch/DPR/blob/master/dpr/indexer/faiss_ind... | BLINK-main | blink/indexer/faiss_indexer.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 argparse
import json
import sys
from elq.index.faiss_indexer import DenseFlatIndexer, DenseHNSWFlatIndexer, DenseIV... | BLINK-main | elq/main_dense.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 argparse
import logging
import numpy
import os
import time
import torch
from elq.index.faiss_indexer import DenseF... | BLINK-main | elq/build_faiss_index.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.
#
# Code partially adopted from https://github.com/allenai/allennlp
#
from typing import Any, Dict, List, Optional, Sequenc... | BLINK-main | elq/biencoder/allennlp_span_utils.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 os
import json
import logging
import torch
from tqdm import tqdm, trange
from torch.utils.data import DataLoader, ... | BLINK-main | elq/biencoder/data_process.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 torch
import numpy as np
def batch_reshape_mask_left(
input_t, selected, pad_idx=0, left_align_mask=None
):
... | BLINK-main | elq/biencoder/utils.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 os
import argparse
import faiss
import pickle
import torch
import json
import sys
import io
import random
import ti... | BLINK-main | elq/biencoder/train_biencoder.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 os
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from tqdm import tqdm
from... | BLINK-main | elq/biencoder/biencoder.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 os
import io
import sys
import json
import torch
import logging
import numpy as np
from collections import Ordere... | BLINK-main | elq/candidate_ranking/utils.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.
#
# Provide an argument parser and default command line options for using ELQ.
import argparse
import importlib
import os
i... | BLINK-main | elq/common/params.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.
#
from torch import nn
import torch
def get_model_obj(model):
model = model.module if hasattr(model, "module") else mo... | BLINK-main | elq/common/ranker_base.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.
#
"""
FAISS-based index components. Original from
https://github.com/facebookresearch/DPR/blob/master/dpr/indexer/faiss_ind... | BLINK-main | elq/index/faiss_indexer.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 numpy as np
def entity_linking_tp_with_overlap(gold, predicted):
"""
Partially adopted from: https://gith... | BLINK-main | elq/vcg_utils/measures.py |
import argparse
import json
import logging
import os
import random
import time
import torch
from datetime import timedelta
WORLDS = {
'american_football',
'doctor_who',
'fallout',
'final_fantasy',
'military',
'pro_wrestling',
'starwars',
'world_of_warcraft',
'coronation_street',
... | BLINK-main | examples/zeshel/create_BLINK_zeshel_data.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 torch
from torch.utils.data import DataLoader, RandomSampler, SequentialSampler, TensorDataset
from elq.biencoder.b... | BLINK-main | scripts/generate_candidates.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 json
import os
import requests
from bs4 import BeautifulSoup
from tqdm import tqdm
BEGIN_ENT_TOKEN = "[START_ENT]"... | BLINK-main | scripts/create_BLINK_benchmark_data.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 torch
import json
import os
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--path_to_s... | BLINK-main | scripts/merge_candidates.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 json
import os
import numpy as np
import torch
from elq.vcg_utils.measures import entity_linking_tp_with_overlap
fr... | BLINK-main | scripts/tune_hyperparams_new.py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.