MCPcopy Create free account
hub / github.com/BeastyZ/ConvSearch-R1 / Encoder

Class Encoder

src/retrieval/server.py:137–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

135########################### utils end #############################
136
137class Encoder:
138 def __init__(self, model_path, max_length):
139 self.max_length = max_length
140 self.tokenizer, self.model = load_model(model_path=model_path)
141 self.model.eval()
142
143 @torch.no_grad()
144 def encode(self, query_list: List[str]):
145 inputs = self.tokenizer(
146 query_list,
147 max_length=self.max_length,
148 padding=True,
149 truncation=True,
150 return_tensors="pt",
151 add_special_tokens=True
152 ).to('cuda')
153 query_embs = self.model(input_ids=inputs['input_ids'], attention_mask=inputs['attention_mask'])
154 query_embs = query_embs.detach().cpu().numpy()
155 return query_embs
156
157
158class BaseRetriever:

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected