Spaces:
Sleeping
Sleeping
fix rerank bug
Browse files- backend/reranker.py +3 -4
backend/reranker.py
CHANGED
@@ -7,7 +7,6 @@ def rerank_documents(ce_model_name, documents, query, top_k_rerank):
|
|
7 |
for doc in documents:
|
8 |
pairs.append((query, doc))
|
9 |
ce_model = CrossEncoder(ce_model_name, max_length=512)
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
return reranked_docs[:top_k_rerank]
|
|
|
7 |
for doc in documents:
|
8 |
pairs.append((query, doc))
|
9 |
ce_model = CrossEncoder(ce_model_name, max_length=512)
|
10 |
+
scores = ce_model.predict(pairs)
|
11 |
+
reranked_docs = [x[1] for _, x in sorted(zip(scores, pairs), key=lambda p: p[0], reverse = True)]
|
12 |
+
return reranked_docs[:top_k_rerank]
|
|