Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from collections import defaultdict
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from deeprank import select_module
class GroupPointerNet(select_module.SelectNet):
def __init__(self, config, out_device=None):
super().__init__(config)
self.output_type = 'LL'
self.pad_value = self.config['pad_value']
self.win_size = self.config['win_size']
self.max_match = self.config['max_match']
self.embedding = nn.Embedding(
config['vocab_size'],
config['embed_dim'],
padding_idx=self.pad_value
)
self.embedding.weight.requires_grad = self.config['finetune_embed']
from collections import defaultdict
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from deeprank import select_module
class IdentityNet(select_module.SelectNet):
def __init__(self, config):
super().__init__(config)
def forward(self, q_data, d_data, q_len, d_len):
q_data = q_data[:, :self.config['q_limit']]
d_data = d_data[:, :self.config['d_limit']]
q_len = torch.clamp(q_len, max=self.config['q_limit'])
d_len = torch.clamp(d_len, max=self.config['d_limit'])
return q_data, d_data, q_len, d_len
from collections import defaultdict
from itertools import chain
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from deeprank import select_module
class QueryCentricNet(select_module.SelectNet):
def __init__(self, config, out_device=None):
super().__init__(config)
self.output_type = 'LL'
self.pad_value = self.config['pad_value']
self.max_match = self.config['max_match']
self.win_size = self.config['win_size']
self.q_size = self.config['q_limit']
self.d_size = self.max_match
# key (doc_id, q_item)
self.cache = {}
self.out_device = out_device
from collections import defaultdict
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from deeprank import select_module
class PointerNet(select_module.SelectNet):
def __init__(self, config, out_device=None):
super().__init__(config)
self.output_type = 'LL'
self.pad_value = self.config['pad_value']
self.win_size = self.config['win_size']
self.max_match = self.config['max_match']
self.embedding = nn.Embedding(
config['vocab_size'],
config['embed_dim'],
padding_idx=self.pad_value
)
self.embedding.weight.requires_grad = self.config['finetune_embed']
def __init__(self, config_file):
self.config_file = config_file
self.config = json.loads( open(config_file).read() )
self.Letor07Path = self.config['data_dir'] #'/home/pangliang/matching/data/letor/r5w/'
self.word_dict, self.iword_dict = utils.read_word_dict(
filename=self.Letor07Path + '/word_dict.txt')
self.query_data = utils.read_data(
filename=self.Letor07Path + '/qid_query.txt')
self.doc_data = utils.read_data(
filename=self.Letor07Path + '/docid_doc.txt')
self.embed_dict = utils.read_embedding(
filename=self.Letor07Path + '/embed_wiki-pdc_d50_norm')
self.idf_dict = utils.read_embedding(
filename=self.Letor07Path + '/embed.idf')
self.feat_size = self.config['feat_size']
self._PAD_ = len(self.word_dict)
self.word_dict[self._PAD_] = '[PAD]'
self.iword_dict['[PAD]'] = self._PAD_
def __init__(self, config_file):
self.config_file = config_file
self.config = json.loads( open(config_file).read() )
self.Letor07Path = self.config['data_dir'] #'/home/pangliang/matching/data/letor/r5w/'
self.word_dict, self.iword_dict = utils.read_word_dict(
filename=self.Letor07Path + '/word_dict.txt')
self.query_data = utils.read_data(
filename=self.Letor07Path + '/qid_query.txt')
self.doc_data = utils.read_data(
filename=self.Letor07Path + '/docid_doc.txt')
self.embed_dict = utils.read_embedding(
filename=self.Letor07Path + '/embed_wiki-pdc_d50_norm')
self.idf_dict = utils.read_embedding(
filename=self.Letor07Path + '/embed.idf')
self.feat_size = self.config['feat_size']
self._PAD_ = len(self.word_dict)
self.word_dict[self._PAD_] = '[PAD]'
self.iword_dict['[PAD]'] = self._PAD_
self.embed_dict[self._PAD_] = np.zeros((50, ), dtype=np.float32)
self.W_init_embed = np.float32(
def __init__(self, rel_file, config):
rel = utils.read_relation(filename=rel_file)
self.pair_list = self.make_pair(rel)
self.config = config
self.feat_size = self.config['feat_size']
self._PAD_ = len(self.word_dict)
self.word_dict[self._PAD_] = '[PAD]'
self.iword_dict['[PAD]'] = self._PAD_
self.embed_dict[self._PAD_] = np.zeros((50, ), dtype=np.float32)
self.W_init_embed = np.float32(
np.random.uniform(-0.02, 0.02, [len(self.word_dict), 50]))
self.embedding = utils.convert_embed_2_numpy(
self.embed_dict, embed = self.W_init_embed)
self.W_init_idf = np.float32(
np.zeros([len(self.word_dict), 1]))
self.idf_embedding = utils.convert_embed_2_numpy(
self.idf_dict, embed = self.W_init_idf)
filename=self.Letor07Path + '/docid_doc.txt')
self.embed_dict = utils.read_embedding(
filename=self.Letor07Path + '/embed_wiki-pdc_d50_norm')
self.idf_dict = utils.read_embedding(
filename=self.Letor07Path + '/embed.idf')
self.feat_size = self.config['feat_size']
self._PAD_ = len(self.word_dict)
self.word_dict[self._PAD_] = '[PAD]'
self.iword_dict['[PAD]'] = self._PAD_
self.embed_dict[self._PAD_] = np.zeros((50, ), dtype=np.float32)
self.W_init_embed = np.float32(
np.random.uniform(-0.02, 0.02, [len(self.word_dict), 50]))
self.embedding = utils.convert_embed_2_numpy(
self.embed_dict, embed = self.W_init_embed)
self.W_init_idf = np.float32(
np.zeros([len(self.word_dict), 1]))
self.idf_embedding = utils.convert_embed_2_numpy(
self.idf_dict, embed = self.W_init_idf)
def __init__(self, config_file):
self.config_file = config_file
self.config = json.loads( open(config_file).read() )
self.Letor07Path = self.config['data_dir'] #'/home/pangliang/matching/data/letor/r5w/'
self.word_dict, self.iword_dict = utils.read_word_dict(
filename=self.Letor07Path + '/word_dict.txt')
self.query_data = utils.read_data(
filename=self.Letor07Path + '/qid_query.txt')
self.doc_data = utils.read_data(
filename=self.Letor07Path + '/docid_doc.txt')
self.embed_dict = utils.read_embedding(
filename=self.Letor07Path + '/embed_wiki-pdc_d50_norm')
self.idf_dict = utils.read_embedding(
filename=self.Letor07Path + '/embed.idf')
self.feat_size = self.config['feat_size']
self._PAD_ = len(self.word_dict)
self.word_dict[self._PAD_] = '[PAD]'
self.iword_dict['[PAD]'] = self._PAD_
self.embed_dict[self._PAD_] = np.zeros((50, ), dtype=np.float32)
self.W_init_embed = np.float32(
np.random.uniform(-0.02, 0.02, [len(self.word_dict), 50]))
self.embedding = utils.convert_embed_2_numpy(