Text Classification
Transformers
Safetensors
roberta
reranking
cross-encoder
vietnamese
phobert
rag
Generated from Trainer
Eval Results (legacy)
Instructions to use HiImHa/phobert-cross-encoder with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use HiImHa/phobert-cross-encoder with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="HiImHa/phobert-cross-encoder")# Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("HiImHa/phobert-cross-encoder") model = AutoModelForSequenceClassification.from_pretrained("HiImHa/phobert-cross-encoder") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,189 +1,170 @@
|
|
| 1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
library_name: transformers
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
---
|
| 5 |
|
| 6 |
-
#
|
| 7 |
|
| 8 |
-
|
|
|
|
| 9 |
|
|
|
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
##
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
- **Shared by [optional]:** Hong Ha
|
| 21 |
-
- **Language(s) (NLP):** Vietnamese
|
| 22 |
-
- **Finetuned from model [optional]:** vinai-phobert-base-v2
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
## Uses
|
| 27 |
-
|
| 28 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
| 29 |
-
|
| 30 |
-
### Direct Use
|
| 31 |
-
|
| 32 |
-
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
| 33 |
-
|
| 34 |
-
[More Information Needed]
|
| 35 |
-
|
| 36 |
-
### Downstream Use [optional]
|
| 37 |
-
|
| 38 |
-
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
| 39 |
-
|
| 40 |
-
[More Information Needed]
|
| 41 |
-
|
| 42 |
-
### Out-of-Scope Use
|
| 43 |
-
|
| 44 |
-
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
| 45 |
-
|
| 46 |
-
[More Information Needed]
|
| 47 |
-
|
| 48 |
-
## Bias, Risks, and Limitations
|
| 49 |
-
|
| 50 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
| 51 |
-
|
| 52 |
-
[More Information Needed]
|
| 53 |
-
|
| 54 |
-
### Recommendations
|
| 55 |
-
|
| 56 |
-
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
| 57 |
-
|
| 58 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
| 59 |
-
|
| 60 |
-
## How to Get Started with the Model
|
| 61 |
-
|
| 62 |
-
Use the code below to get started with the model.
|
| 63 |
-
|
| 64 |
-
[More Information Needed]
|
| 65 |
|
| 66 |
## Training Details
|
| 67 |
|
| 68 |
-
###
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
### Training Procedure
|
| 75 |
-
|
| 76 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
| 77 |
-
|
| 78 |
-
#### Preprocessing [optional]
|
| 79 |
-
|
| 80 |
-
[More Information Needed]
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
#### Training Hyperparameters
|
| 84 |
-
|
| 85 |
-
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
| 86 |
-
|
| 87 |
-
#### Speeds, Sizes, Times [optional]
|
| 88 |
-
|
| 89 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
| 90 |
-
|
| 91 |
-
[More Information Needed]
|
| 92 |
-
|
| 93 |
-
## Evaluation
|
| 94 |
-
|
| 95 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
| 96 |
-
|
| 97 |
-
### Testing Data, Factors & Metrics
|
| 98 |
-
|
| 99 |
-
#### Testing Data
|
| 100 |
-
|
| 101 |
-
<!-- This should link to a Dataset Card if possible. -->
|
| 102 |
-
|
| 103 |
-
[More Information Needed]
|
| 104 |
-
|
| 105 |
-
#### Factors
|
| 106 |
-
|
| 107 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
| 108 |
-
|
| 109 |
-
[More Information Needed]
|
| 110 |
-
|
| 111 |
-
#### Metrics
|
| 112 |
-
|
| 113 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
| 114 |
-
|
| 115 |
-
[More Information Needed]
|
| 116 |
-
|
| 117 |
-
### Results
|
| 118 |
-
|
| 119 |
-
[More Information Needed]
|
| 120 |
-
|
| 121 |
-
#### Summary
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
## Model Examination [optional]
|
| 126 |
-
|
| 127 |
-
<!-- Relevant interpretability work for the model goes here -->
|
| 128 |
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
|
| 131 |
-
##
|
| 132 |
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
-
|
| 136 |
|
| 137 |
-
|
| 138 |
-
- **Hours used:** [More Information Needed]
|
| 139 |
-
- **Cloud Provider:** [More Information Needed]
|
| 140 |
-
- **Compute Region:** [More Information Needed]
|
| 141 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 142 |
|
| 143 |
-
|
| 144 |
|
| 145 |
-
##
|
| 146 |
|
| 147 |
-
|
|
|
|
|
|
|
| 148 |
|
| 149 |
-
|
| 150 |
|
| 151 |
-
|
|
|
|
|
|
|
| 152 |
|
| 153 |
-
###
|
|
|
|
|
|
|
|
|
|
| 154 |
|
| 155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
|
| 157 |
-
|
|
|
|
| 158 |
|
| 159 |
-
|
|
|
|
| 160 |
|
| 161 |
-
##
|
| 162 |
|
| 163 |
-
|
|
|
|
|
|
|
|
|
|
| 164 |
|
| 165 |
-
|
| 166 |
|
| 167 |
-
|
|
|
|
|
|
|
| 168 |
|
| 169 |
-
|
| 170 |
|
| 171 |
-
|
|
|
|
|
|
|
| 172 |
|
| 173 |
-
##
|
| 174 |
|
| 175 |
-
|
|
|
|
|
|
|
|
|
|
| 176 |
|
| 177 |
-
|
| 178 |
|
| 179 |
-
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
-
|
| 182 |
|
| 183 |
-
|
|
|
|
| 184 |
|
| 185 |
-
|
| 186 |
|
| 187 |
-
|
| 188 |
|
| 189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
tags:
|
| 3 |
+
- transformers
|
| 4 |
+
- text-classification
|
| 5 |
+
- reranking
|
| 6 |
+
- cross-encoder
|
| 7 |
+
- vietnamese
|
| 8 |
+
- phobert
|
| 9 |
+
- rag
|
| 10 |
+
- generated_from_trainer
|
| 11 |
+
base_model: vinai/phobert-base-v2
|
| 12 |
+
pipeline_tag: text-classification
|
| 13 |
library_name: transformers
|
| 14 |
+
metrics:
|
| 15 |
+
- accuracy
|
| 16 |
+
- f1
|
| 17 |
+
model-index:
|
| 18 |
+
- name: PhoBERT Cross-Encoder for Reranking
|
| 19 |
+
results:
|
| 20 |
+
- task:
|
| 21 |
+
type: text-classification
|
| 22 |
+
name: Relevance Classification
|
| 23 |
+
dataset:
|
| 24 |
+
name: cross_eval
|
| 25 |
+
type: cross_eval
|
| 26 |
+
metrics:
|
| 27 |
+
- type: accuracy
|
| 28 |
+
value: 0.995473
|
| 29 |
+
name: Accuracy
|
| 30 |
+
- type: f1
|
| 31 |
+
value: 0.990951
|
| 32 |
+
name: F1 Score
|
| 33 |
---
|
| 34 |
|
| 35 |
+
# PhoBERT Cross-Encoder for Vietnamese Reranking
|
| 36 |
|
| 37 |
+
This model is a cross-encoder fine-tuned from `vinai/phobert-base-v2` for binary relevance classification between a query and a document.
|
| 38 |
+
Unlike bi-encoders, this model jointly encodes (query, context) pairs, enabling high-accuracy reranking in retrieval systems.
|
| 39 |
|
| 40 |
+
## Model Overview
|
| 41 |
|
| 42 |
+
* **Architecture:** Cross-Encoder (Sequence Classification)
|
| 43 |
+
* **Base Model:** `vinai/phobert-base-v2`
|
| 44 |
+
* **Task:** Binary classification (relevant / not relevant)
|
| 45 |
+
* **Input Format:** `[CLS] query [SEP] context [SEP]`
|
| 46 |
+
* **Max Sequence Length:** 256 tokens
|
| 47 |
|
| 48 |
+
## Intended Use
|
| 49 |
|
| 50 |
+
This model is designed for:
|
| 51 |
+
* Reranking top-k results from a bi-encoder
|
| 52 |
+
* Improving semantic search precision
|
| 53 |
+
* Vietnamese legal QA systems
|
| 54 |
+
* Second-stage ranking in RAG pipelines
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
## Training Details
|
| 57 |
|
| 58 |
+
### Dataset
|
| 59 |
+
**Format:**
|
| 60 |
+
* query
|
| 61 |
+
* context
|
| 62 |
+
* label (0 = irrelevant, 1 = relevant)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
+
### Training Configuration
|
| 65 |
+
* **Epochs:** 5
|
| 66 |
+
* **Learning rate:** 2e-5
|
| 67 |
+
* **Batch size:**
|
| 68 |
+
* Train: 16
|
| 69 |
+
* Eval: 32
|
| 70 |
+
* **Warmup:** 0.1
|
| 71 |
+
* **Weight decay:** 0.01
|
| 72 |
+
* **Mixed precision:** FP16 (if GPU available)
|
| 73 |
|
| 74 |
+
## Evaluation Results
|
| 75 |
|
| 76 |
+
| Epoch | Validation Loss | Accuracy | F1 Score |
|
| 77 |
+
| :---: | :---: | :---: | :---: |
|
| 78 |
+
| 1 | 0.0820 | 0.9934 | 0.9869 |
|
| 79 |
+
| 2 | 0.0675 | 0.9936 | 0.9871 |
|
| 80 |
+
| 3 | 0.0793 | 0.9934 | 0.9869 |
|
| 81 |
+
| 4 | 0.0572 | 0.9955 | 0.9910 |
|
| 82 |
+
| 5 | 0.0711 | 0.9955 | 0.9910 |
|
| 83 |
|
| 84 |
+
*Best model selected based on F1 score = 0.9909*
|
| 85 |
|
| 86 |
+
## Model Architecture
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
+
PhoBERT (RoBERTa-based encoder) -> Classification Head (dense + output layer)
|
| 89 |
|
| 90 |
+
## Usage
|
| 91 |
|
| 92 |
+
### Load model
|
| 93 |
+
```python
|
| 94 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 95 |
|
| 96 |
+
model_name = "HiImHa/phobert-cross-encoder"
|
| 97 |
|
| 98 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 99 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 100 |
+
```
|
| 101 |
|
| 102 |
+
### Inference Example
|
| 103 |
+
```python
|
| 104 |
+
query = "Tôi lái xe không giữ khoảng cách an toàn thì bị phạt như thế nào?"
|
| 105 |
+
context = "Phạt tiền từ 2.000.000 đến 3.000.000 đồng nếu không giữ khoảng cách an toàn."
|
| 106 |
|
| 107 |
+
inputs = tokenizer(
|
| 108 |
+
query,
|
| 109 |
+
context,
|
| 110 |
+
return_tensors="pt",
|
| 111 |
+
truncation="only_second",
|
| 112 |
+
max_length=256
|
| 113 |
+
)
|
| 114 |
|
| 115 |
+
outputs = model(**inputs)
|
| 116 |
+
score = outputs.logits.softmax(dim=-1)[0][1].item()
|
| 117 |
|
| 118 |
+
print(score) # relevance score
|
| 119 |
+
```
|
| 120 |
|
| 121 |
+
## How to Use in RAG
|
| 122 |
|
| 123 |
+
Typical pipeline:
|
| 124 |
+
1. Use bi-encoder -> retrieve top-k documents
|
| 125 |
+
2. Use this cross-encoder -> rerank candidates
|
| 126 |
+
3. Select top results for downstream tasks
|
| 127 |
|
| 128 |
+
## Notes on Initialization
|
| 129 |
|
| 130 |
+
* Classification head was randomly initialized and trained during fine-tuning
|
| 131 |
+
* Some PhoBERT pretraining weights (e.g., `lm_head`) are unused -> expected behavior
|
| 132 |
+
* LayerNorm naming differences (beta/gamma vs weight/bias) are automatically handled
|
| 133 |
|
| 134 |
+
## Limitations
|
| 135 |
|
| 136 |
+
* Slower than bi-encoder (pairwise inference)
|
| 137 |
+
* Limited to 256 tokens -> long contexts are truncated
|
| 138 |
+
* Binary classification may not capture nuanced ranking differences
|
| 139 |
|
| 140 |
+
## Future Improvements
|
| 141 |
|
| 142 |
+
* Pairwise / listwise ranking loss
|
| 143 |
+
* Hard negative mining
|
| 144 |
+
* Knowledge distillation from cross -> bi encoder
|
| 145 |
+
* Larger and more diverse dataset
|
| 146 |
|
| 147 |
+
## Training Configuration (Summary)
|
| 148 |
|
| 149 |
+
* **Epochs:** 5
|
| 150 |
+
* **Learning rate:** 2e-5
|
| 151 |
+
* **Loss:** Cross-entropy
|
| 152 |
+
* **Metric:** F1 (primary)
|
| 153 |
|
| 154 |
+
## Acknowledgements
|
| 155 |
|
| 156 |
+
* PhoBERT by VinAI
|
| 157 |
+
* Hugging Face Transformers
|
| 158 |
|
| 159 |
+
## License
|
| 160 |
|
| 161 |
+
Specify your license here (e.g., MIT / Apache 2.0)
|
| 162 |
|
| 163 |
+
## Citation
|
| 164 |
+
```bibtex
|
| 165 |
+
@inproceedings{reimers-2019-sentence-bert,
|
| 166 |
+
title={Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks},
|
| 167 |
+
author={Reimers, Nils and Gurevych, Iryna},
|
| 168 |
+
year={2019}
|
| 169 |
+
}
|
| 170 |
+
```
|