PhoRanker / README.md
itdainb's picture
Update README.md
d5b4fb0 verified
|
raw
history blame
4.97 kB
---
language:
- vi
license: apache-2.0
library_name: transformers
tags:
- cross-encoder
- rerank
datasets:
- unicamp-dl/mmarco
widget:
- text: Trường UIT ?.
output:
- label: >-
Trường Đại_học Công_nghệ Thông_tin có tên tiếng Anh là University of
Information_Technology ( viết tắt là UIT ) là thành_viên của Đại_học
Quốc_Gia TP. HCM.
score: 4.0033
- label: >-
Trường Đại_học Kinh_tế – Luật ( tiếng Anh : University of Economics and
Law – UEL ) là trường đại_học đào_tạo và nghiên_cứu khối ngành kinh_tế ,
kinh_doanh và luật hàng_đầu Việt_Nam .
score: 0
- label: >-
Quĩ_uỷ_thác đầu_tư ( tiếng Anh : Unit Investment_Trusts ; viết tắt : UIT )
là một công_ty đầu_tư mua hoặc nắm giữ một danh_mục đầu_tư cố_định
score: 2.5138
pipeline_tag: text-classification
---
#### Table of contents
1. [Installation](#installation)
2. [Pre-processing](#pre-processing)
3. [Usage with `sentence-transformers`](#usage-with-sentence-transformers)
4. [Usage with `transformers`](#usage-with-transformers)
5. [Performance](#performance)
6. [Citation](#citation)
## Installation
- Install `pyvi` to word segment:
- `pip install pyvi`
- Install `sentence-transformers` (recommend) - [Usage](#usage-with-sentence-transformers):
- `pip install sentence-transformers`
- Install `transformers` (optional) - [Usage](#usage-with-transformers):
- `pip install transformers`
## Pre-processing
```python
from pyvi import ViTokenizer
query = "UIT là gì?"
sentences = [
"Trường Đại học Công nghệ Thông tin có tên tiếng Anh là University of Information Technology (viết tắt là UIT) là thành viên của Đại học Quốc Gia TP.HCM.",
"Trường Đại học Kinh tế – Luật (tiếng Anh: University of Economics and Law – UEL) là trường đại học đào tạo và nghiên cứu khối ngành kinh tế, kinh doanh và luật hàng đầu Việt Nam.",
"Quĩ uỷ thác đầu tư (tiếng Anh: Unit Investment Trusts; viết tắt: UIT) là một công ty đầu tư mua hoặc nắm giữ một danh mục đầu tư cố định"
]
tokenized_query = ViTokenizer.tokenize(query)
tokenized_sentences = [ViTokenizer.tokenize(sent) for sent in sentences]
tokenized_pairs = [[tokenized_query, sent] for sent in tokenized_sentences]
model_id = 'itdainb/PhoRanker'
```
## Usage with sentence-transformers
```python
from sentence_transformers import CrossEncoder
model = CrossEncoder(model_id, max_length=256)
# For fp16 usage
model.model.half()
scores = model.predict(tokenized_pairs)
```
## Usage with transformers
```python
from transformers import AutoTokenizer, AutoModelForSequenceClassification
model = AutoModelForSequenceClassification.from_pretrained(model_id)
tokenizer = AutoTokenizer.from_pretrained(model_id)
# For fp16 usage
model.half()
features = tokenizer(tokenized_pairs, padding=True, truncation="longest_first", return_tensors="pt", max_length=256)
model.eval()
with torch.no_grad():
model_predictions = model(**features, return_dict=True)
logits = model_predictions.logits
scores = [score[0] for score in logits]
print(scores)
```
## Performance
In the following table, we provide various pre-trained Cross-Encoders together with their performance on the [MS MMarco Passage Reranking - Vi - Dev](https://huggingface.co/datasets/unicamp-dl/mmarco) dataset.
| Model-Name | NDCG@3 | MRR@3 | NDCG@5 | MRR@5 | NDCG@10 | MRR@10 | Docs / Sec |
| ----------------------------------------------------- |:------ | :---- |:------ | :---- |:------ | :----| :--- |
|itdainb/PhoRanker |**0.6625**|**0.6458**|**0.7147**|**0.6731**|**0.7422**|**0.6830**|15
|[amberoad/bert-multilingual-passage-reranking-msmarco](https://huggingface.co/amberoad/bert-multilingual-passage-reranking-msmarco) |0.4634|0.5233|0.5041|0.5383|0.5416|0.5523|**22**
|[kien-vu-uet/finetuned-phobert-passage-rerank-best-eval](https://huggingface.co/kien-vu-uet/finetuned-phobert-passage-rerank-best-eval) |0.0963|0.0883|0.1396|0.1131|0.1681|0.1246|15
|[BAAI/bge-reranker-v2-m3](https://huggingface.co/BAAI/bge-reranker-v2-m3) |0.6087|0.5841|0.6513|0.6062|0.6872|0.62091|3.51
|[BAAI/bge-reranker-v2-gemma](https://huggingface.co/BAAI/bge-reranker-v2-gemma) |0.6088|0.5908|0.6446|0.6108|0.6785|0.6249|1.29
Note: Runtime was computed on a A100 GPU with fp16.
## Citation
Please cite as
```Plaintext
@misc{PhoRanker,
title={PhoRanker: A Cross-encoder Model for Vietnamese Text Ranking},
author={Dai Nguyen Ba ({ORCID:0009-0008-8559-3154})},
year={2024},
publisher={Huggingface},
journal={huggingface repository},
howpublished={\url{https://huggingface.co/itdainb/PhoRanker}},
}
```