Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -106,8 +106,10 @@ class CrossEncoderModel:
|
|
| 106 |
def rerank(self, query: str, documents: List[str], top_k: int, truncation: bool) -> List[DocumentScore]:
|
| 107 |
if not documents:
|
| 108 |
raise ValueError("候选文档不能为空")
|
| 109 |
-
if top_k <= 0
|
| 110 |
-
raise ValueError(
|
|
|
|
|
|
|
| 111 |
doc_scores = []
|
| 112 |
for doc in documents:
|
| 113 |
inputs = self.tokenizer(
|
|
|
|
| 106 |
def rerank(self, query: str, documents: List[str], top_k: int, truncation: bool) -> List[DocumentScore]:
|
| 107 |
if not documents:
|
| 108 |
raise ValueError("候选文档不能为空")
|
| 109 |
+
if top_k <= 0:
|
| 110 |
+
raise ValueError("top_k 必须为正整数")
|
| 111 |
+
# 自动将 top_k 限制为文档数量(避免超出)
|
| 112 |
+
top_k = min(top_k, len(documents))
|
| 113 |
doc_scores = []
|
| 114 |
for doc in documents:
|
| 115 |
inputs = self.tokenizer(
|