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']