answerer-api / mapper.py
DaniilAlpha's picture
Create mapper.py
c542da9
raw
history blame
515 Bytes
from sentence_transformers import SentenceTransformer, util
class Mapper:
def __init__(self, repo: str, model: str):
self.__model = SentenceTransformer(f"{repo}/{model}")
def __call__(self, query: str, *data):
query_emb = self.__model.encode(query)
data_emb = self.__model.encode(data)
scores = util.dot_score(query_emb, data_emb)[0].cpu().tolist()
data_score_pairs = list(zip(data, scores))
return sorted(
data_score_pairs,
key=lambda x: x[1],
reverse=True,
)