HiImHa commited on
Commit
4497bd1
·
verified ·
1 Parent(s): 9227843

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +129 -148
README.md CHANGED
@@ -1,189 +1,170 @@
1
  ---
 
 
 
 
 
 
 
 
 
 
 
2
  library_name: transformers
3
- tags: []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  ---
5
 
6
- # Model Card for Model ID
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
 
9
 
 
10
 
 
 
 
 
 
11
 
12
- ## Model Details
13
 
14
- ### Model Description
15
-
16
- <!-- Provide a longer summary of what this model is. -->
17
-
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
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
- ### Training Data
69
-
70
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
71
-
72
- [More Information Needed]
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
- [More Information Needed]
 
 
 
 
 
 
 
 
130
 
131
- ## Environmental Impact
132
 
133
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
 
 
 
 
 
 
134
 
135
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
136
 
137
- - **Hardware Type:** [More Information Needed]
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
- ## Technical Specifications [optional]
144
 
145
- ### Model Architecture and Objective
146
 
147
- [More Information Needed]
 
 
148
 
149
- ### Compute Infrastructure
150
 
151
- [More Information Needed]
 
 
152
 
153
- #### Hardware
 
 
 
154
 
155
- [More Information Needed]
 
 
 
 
 
 
156
 
157
- #### Software
 
158
 
159
- [More Information Needed]
 
160
 
161
- ## Citation [optional]
162
 
163
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
 
 
 
164
 
165
- **BibTeX:**
166
 
167
- [More Information Needed]
 
 
168
 
169
- **APA:**
170
 
171
- [More Information Needed]
 
 
172
 
173
- ## Glossary [optional]
174
 
175
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
 
 
 
176
 
177
- [More Information Needed]
178
 
179
- ## More Information [optional]
 
 
 
180
 
181
- [More Information Needed]
182
 
183
- ## Model Card Authors [optional]
 
184
 
185
- [More Information Needed]
186
 
187
- ## Model Card Contact
188
 
189
- [More Information Needed]
 
 
 
 
 
 
 
 
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
+ ```