Commit
·
39d1084
1
Parent(s):
fb163e5
Update README.md
Browse files
README.md
CHANGED
@@ -3,4 +3,44 @@ license: apache-2.0
|
|
3 |
language:
|
4 |
- zh
|
5 |
library_name: transformers
|
6 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
language:
|
4 |
- zh
|
5 |
library_name: transformers
|
6 |
+
---
|
7 |
+
|
8 |
+
### RankingPrompter
|
9 |
+
RankingPrompter是由人工智能与数字经济广东省实验室(深圳光明实验室)开发的一个开源的重排/精排模型。
|
10 |
+
- 在大约1500万中文句对数据集上进行训练。
|
11 |
+
- 在多项中文测试集上均取得最好的效果。
|
12 |
+
|
13 |
+
如果希望使用RankingPrompter更加丰富的功能(如完整的文档编码-召回-精排链路),我们推荐使用配套代码库(To be released)。
|
14 |
+
|
15 |
+
### 如何使用
|
16 |
+
|
17 |
+
You can use this model simply as a re-ranker, note now the model is only available for Chinese.
|
18 |
+
本模型可简单用作一个强力的重排/精排模型,现阶段仅支持中文。
|
19 |
+
|
20 |
+
```python
|
21 |
+
from transformers import AutoTokenizer, AutoModel
|
22 |
+
|
23 |
+
tokenizer = AutoTokenizer.from_pretrained("howard-hou/RankingPrompterForPreTraining-small")
|
24 |
+
model = AutoModel.from_pretrained("howard-hou/RankingPrompterForPreTraining-small")
|
25 |
+
|
26 |
+
#
|
27 |
+
documents = [
|
28 |
+
'水库诱发地震的震中多在库底和水库边缘。',
|
29 |
+
'双标紫斑蝶广泛分布于南亚、东南亚、澳洲、新几内亚等地。台湾地区于本岛中海拔地区可见,多以特有亚种归类。',
|
30 |
+
'月经停止是怀孕最显著也是最早的一个信号,如果在无避孕措施下进行了性生活而出现月经停止的话,很可能就是怀孕了。'
|
31 |
+
]
|
32 |
+
|
33 |
+
question = "什么是怀孕最显著也是最早的信号?"
|
34 |
+
|
35 |
+
question_input = tokenizer('question', return_tensors="pt")
|
36 |
+
docs_input = tokenizer(documents , padding="max_length", return_tensors="pt")
|
37 |
+
# document input shape should be [batch_size, num_docs, seq_len]
|
38 |
+
# so if only input one sample of documents, add one dim by unsqueeze(0)
|
39 |
+
output = model(
|
40 |
+
document_input_ids=docs_input.input_ids.unsqueeze(0),
|
41 |
+
document_attention_mask=docs_input.attention_mask.unsqueeze(0),
|
42 |
+
question_input_ids=question_input.input_ids,
|
43 |
+
question_attention_mask=question_input.attention_mask
|
44 |
+
)
|
45 |
+
print("reranking scores: ", output.logits)
|
46 |
+
```
|