Sentence Similarity
sentence-transformers
PyTorch
Transformers
English
t5
text-embedding
embeddings
information-retrieval
beir
text-classification
language-model
text-clustering
text-semantic-similarity
text-evaluation
prompt-retrieval
text-reranking
feature-extraction
English
Sentence Similarity
natural_questions
ms_marco
fever
hotpot_qa
mteb
Eval Results
Inference Endpoints
update handler
Browse files- handler.py +26 -0
handler.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Dict, List, Any
|
2 |
+
from InstructorEmbedding import INSTRUCTOR
|
3 |
+
|
4 |
+
class EndpointHandler:
|
5 |
+
def __init__(self, path=""):
|
6 |
+
# load model on gpu
|
7 |
+
self.model = INSTRUCTOR(path, device="cuda")
|
8 |
+
|
9 |
+
def __call__(self, data: Dict[str, Any]) -> List[List[float]]:
|
10 |
+
"""
|
11 |
+
data args:
|
12 |
+
inputs (:obj: `str`)
|
13 |
+
Return:
|
14 |
+
A :obj:`list` | `dict`: will be serialized and returned
|
15 |
+
"""
|
16 |
+
# get inputs
|
17 |
+
inputs: dict = data.pop("inputs", data)
|
18 |
+
|
19 |
+
# add instruction
|
20 |
+
query = [['Retrieve documents that can help answer the question:',
|
21 |
+
inputs]]
|
22 |
+
|
23 |
+
# encode
|
24 |
+
embedding = self.model.encode(query)
|
25 |
+
|
26 |
+
return embedding[0]
|