Views
No views yet
pip install -U FlagEmbedding1from FlagEmbedding import FlagReranker
2
3reranker = FlagReranker('namdp-ptit/ViRanker',
4 use_fp16=True) # Setting use_fp16 to True speeds up computation with a slight performance degradation
5
6score = reranker.compute_score(['ai là vị vua cuối cùng của việt nam', 'vua bảo đại là vị vua cuối cùng của nước ta'])
7print(score) # 13.71875
8
9# You can map the scores into 0-1 by set "normalize=True", which will apply sigmoid function to the score
10score = reranker.compute_score(['ai là vị vua cuối cùng của việt nam', 'vua bảo đại là vị vua cuối cùng của nước ta'],
11 normalize=True)
12print(score) # 0.99999889840464
13
14scores = reranker.compute_score(
15 [
16 ['ai là vị vua cuối cùng của việt nam', 'vua bảo đại là vị vua cuối cùng của nước ta'],
17 ['ai là vị vua cuối cùng của việt nam', 'lý nam đế là vị vua đầu tiên của nước ta']
18 ]
19)
20print(scores) # [13.7265625, -8.53125]
21
22# You can map the scores into 0-1 by set "normalize=True", which will apply sigmoid function to the score
23scores = reranker.compute_score(
24 [
25 ['ai là vị vua cuối cùng của việt nam', 'vua bảo đại là vị vua cuối của nước ta'],
26 ['ai là vị vua cuối cùng của việt nam', 'lý nam đế là vị vua đầu tiên của nước ta']
27 ],
28 normalize=True
29)
30print(scores) # [0.99999889840464, 0.00019716942196222918]pip install -U transformers1import torch
2from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
4tokenizer = AutoTokenizer.from_pretrained('namdp-ptit/ViRanker')
5model = AutoModelForSequenceClassification.from_pretrained('namdp-ptit/ViRanker')
6model.eval()
7
8pairs = [
9 ['ai là vị vua cuối cùng của việt nam', 'vua bảo đại là vị vua cuối cùng của nước ta'],
10 ['ai là vị vua cuối cùng của việt nam', 'lý nam đế là vị vua đầu tiên của nước ta']
11],
12with torch.no_grad():
13 inputs = tokenizer(pairs, padding=True, truncation=True, return_tensors='pt', max_length=512)
14 scores = model(**inputs, return_dict=True).logits.view(-1, ).float()
15 print(scores){"query": str, "pos": List[str], "neg": List[str]}query is the query, and pos is a list of positive texts, neg is a list of negative texts. If you have no negative
texts for a query, you can random sample some from the entire corpus as the negatives.| Model Name | NDCG@3 | MRR@3 | NDCG@5 | MRR@5 | NDCG@10 | MRR@10 |
|---|---|---|---|---|---|---|
| namdp-ptit/ViRanker | 0.6815 | 0.6641 | 0.6983 | 0.6894 | 0.7302 | 0.7107 |
| itdainb/PhoRanker | 0.6625 | 0.6458 | 0.7147 | 0.6731 | 0.7422 | 0.6830 |
| kien-vu-uet/finetuned-phobert-passage-rerank-best-eval | 0.0963 | 0.0883 | 0.1396 | 0.1131 | 0.1681 | 0.1246 |
| BAAI/bge-reranker-v2-m3 | 0.6087 | 0.5841 | 0.6513 | 0.6062 | 0.6872 | 0.6209 |
| BAAI/bge-reranker-v2-gemma | 0.6088 | 0.5908 | 0.6446 | 0.6108 | 0.6785 | 0.6249 |
1@misc{ViRanker,
2 title={ViRanker: A Cross-encoder Model for Vietnamese Text Ranking},
3 author={Nam Dang Phuong},
4 year={2024},
5 publisher={Huggingface},
6}