Update README.md
Browse files
README.md
CHANGED
|
@@ -1,199 +1,190 @@
|
|
| 1 |
---
|
| 2 |
library_name: transformers
|
| 3 |
-
tags:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
---
|
| 5 |
|
| 6 |
-
#
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
| 9 |
|
|
|
|
| 10 |
|
|
|
|
| 11 |
|
| 12 |
## Model Details
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
- **Developed by:** [More Information Needed]
|
| 21 |
-
- **Funded by [optional]:** [More Information Needed]
|
| 22 |
-
- **Shared by [optional]:** [More Information Needed]
|
| 23 |
-
- **Model type:** [More Information Needed]
|
| 24 |
-
- **Language(s) (NLP):** [More Information Needed]
|
| 25 |
-
- **License:** [More Information Needed]
|
| 26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
| 27 |
-
|
| 28 |
-
### Model Sources [optional]
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
-
- **Paper [optional]:** [More Information Needed]
|
| 34 |
-
- **Demo [optional]:** [More Information Needed]
|
| 35 |
|
| 36 |
## Uses
|
| 37 |
|
| 38 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
| 39 |
-
|
| 40 |
### Direct Use
|
|
|
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
[More Information Needed]
|
| 45 |
-
|
| 46 |
-
### Downstream Use [optional]
|
| 47 |
-
|
| 48 |
-
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
| 49 |
-
|
| 50 |
-
[More Information Needed]
|
| 51 |
|
| 52 |
### Out-of-Scope Use
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
[More Information Needed]
|
| 57 |
|
| 58 |
## Bias, Risks, and Limitations
|
| 59 |
|
| 60 |
-
|
|
|
|
| 61 |
|
| 62 |
-
|
| 63 |
|
| 64 |
-
|
| 65 |
|
| 66 |
-
|
| 67 |
|
| 68 |
-
|
|
|
|
|
|
|
| 69 |
|
| 70 |
-
|
|
|
|
|
|
|
| 71 |
|
| 72 |
-
|
|
|
|
| 73 |
|
| 74 |
-
[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
## Training Details
|
| 77 |
|
| 78 |
-
###
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
#### Preprocessing [optional]
|
| 89 |
-
|
| 90 |
-
[More Information Needed]
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
#### Training Hyperparameters
|
| 94 |
-
|
| 95 |
-
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
| 96 |
-
|
| 97 |
-
#### Speeds, Sizes, Times [optional]
|
| 98 |
-
|
| 99 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
| 100 |
-
|
| 101 |
-
[More Information Needed]
|
| 102 |
|
| 103 |
## Evaluation
|
| 104 |
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
| 124 |
-
|
| 125 |
-
[More Information Needed]
|
| 126 |
-
|
| 127 |
-
### Results
|
| 128 |
-
|
| 129 |
-
[More Information Needed]
|
| 130 |
-
|
| 131 |
-
#### Summary
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
## Model Examination [optional]
|
| 136 |
-
|
| 137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
| 138 |
-
|
| 139 |
-
[More Information Needed]
|
| 140 |
-
|
| 141 |
-
## Environmental Impact
|
| 142 |
-
|
| 143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
| 144 |
-
|
| 145 |
-
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).
|
| 146 |
-
|
| 147 |
-
- **Hardware Type:** [More Information Needed]
|
| 148 |
-
- **Hours used:** [More Information Needed]
|
| 149 |
-
- **Cloud Provider:** [More Information Needed]
|
| 150 |
-
- **Compute Region:** [More Information Needed]
|
| 151 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 152 |
-
|
| 153 |
-
## Technical Specifications [optional]
|
| 154 |
-
|
| 155 |
-
### Model Architecture and Objective
|
| 156 |
-
|
| 157 |
-
[More Information Needed]
|
| 158 |
-
|
| 159 |
-
### Compute Infrastructure
|
| 160 |
-
|
| 161 |
-
[More Information Needed]
|
| 162 |
-
|
| 163 |
-
#### Hardware
|
| 164 |
-
|
| 165 |
-
[More Information Needed]
|
| 166 |
-
|
| 167 |
-
#### Software
|
| 168 |
-
|
| 169 |
-
[More Information Needed]
|
| 170 |
-
|
| 171 |
-
## Citation [optional]
|
| 172 |
-
|
| 173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
| 174 |
-
|
| 175 |
-
**BibTeX:**
|
| 176 |
-
|
| 177 |
-
[More Information Needed]
|
| 178 |
-
|
| 179 |
-
**APA:**
|
| 180 |
-
|
| 181 |
-
[More Information Needed]
|
| 182 |
-
|
| 183 |
-
## Glossary [optional]
|
| 184 |
-
|
| 185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
| 186 |
|
| 187 |
-
|
| 188 |
|
| 189 |
-
|
|
|
|
|
|
|
|
|
|
| 190 |
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
-
|
| 194 |
|
| 195 |
-
|
| 196 |
|
| 197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
|
| 199 |
-
|
|
|
|
|
|
| 1 |
---
|
| 2 |
library_name: transformers
|
| 3 |
+
tags:
|
| 4 |
+
- sequence-classification
|
| 5 |
+
- text-classification
|
| 6 |
+
- nli
|
| 7 |
+
- xlm-roberta
|
| 8 |
+
- vietnamese
|
| 9 |
+
- kaggle
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# XLM-RoBERTa-base fine-tuned for Vietnamese NLI
|
| 13 |
|
| 14 |
+
A Vietnamese Natural Language Inference (NLI) model that predicts the relation between a **premise** and a **hypothesis** as one of:
|
| 15 |
+
- `c` (contradiction)
|
| 16 |
+
- `n` (neutral)
|
| 17 |
+
- `e` (entailment)
|
| 18 |
|
| 19 |
+
This model fine-tunes **xlm-roberta-base** using a stratified 80/10/10 split, optimized to run on a single GPU (Kaggle T4/P100).
|
| 20 |
|
| 21 |
+
---
|
| 22 |
|
| 23 |
## Model Details
|
| 24 |
|
| 25 |
+
- **Developed by:** Lê Lý (MoMo Talent 2025)
|
| 26 |
+
- **Model type:** XLM-RoBERTa encoder for sequence classification (3 labels)
|
| 27 |
+
- **Languages:** Vietnamese (vi)
|
| 28 |
+
- **License:** Inherits from upstream **xlm-roberta-base** (set the model page license accordingly)
|
| 29 |
+
- **Finetuned from:** `xlm-roberta-base`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
### Model Sources
|
| 32 |
+
- **Base model:** XLM-RoBERTa (Conneau et al., 2020)
|
| 33 |
+
- **Training script:** Included below in this card (Kaggle-ready)
|
| 34 |
|
| 35 |
+
---
|
|
|
|
|
|
|
| 36 |
|
| 37 |
## Uses
|
| 38 |
|
|
|
|
|
|
|
| 39 |
### Direct Use
|
| 40 |
+
- Vietnamese NLI inference for research, demos, or as a component in larger systems (e.g., retrieval/ranking, dialog consistency checks).
|
| 41 |
|
| 42 |
+
### Downstream Use
|
| 43 |
+
- Fine-tune further on domain-specific VN NLI or related tasks (stance detection, contradiction detection in QA/assistants).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
### Out-of-Scope Use
|
| 46 |
+
- Non-VN text without adaptation.
|
| 47 |
+
- Safety-critical decisions without human oversight.
|
| 48 |
+
- Open-domain factual verification (this is NLI, not a fact-checker).
|
| 49 |
|
| 50 |
+
---
|
|
|
|
|
|
|
| 51 |
|
| 52 |
## Bias, Risks, and Limitations
|
| 53 |
|
| 54 |
+
- Trained on a VN NLI dataset; distributional shift (domain, register, slang, figurative language) may degrade performance.
|
| 55 |
+
- NLI labels can be sensitive to annotation style/instructions; avoid over-interpreting borderline cases.
|
| 56 |
|
| 57 |
+
**Recommendations:** Evaluate on your target domain; monitor confusion between `n` vs `e`/`c`; consider calibration or thresholding if used in pipelines.
|
| 58 |
|
| 59 |
+
---
|
| 60 |
|
| 61 |
+
## How to Get Started
|
| 62 |
|
| 63 |
+
```python
|
| 64 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 65 |
+
import torch
|
| 66 |
|
| 67 |
+
model_id = "YOUR_USERNAME/xlmr-vinli-finetune" # replace with your repo id
|
| 68 |
+
tok = AutoTokenizer.from_pretrained(model_id)
|
| 69 |
+
mdl = AutoModelForSequenceClassification.from_pretrained(model_id)
|
| 70 |
|
| 71 |
+
id2label = mdl.config.id2label # {0:'c',1:'n',2:'e'}
|
| 72 |
+
text = {"premise": "Trời đang mưa rất to.", "hypothesis": "Bên ngoài khô ráo và không có mưa."}
|
| 73 |
|
| 74 |
+
enc = tok(text["premise"], text["hypothesis"], return_tensors="pt", truncation=True, max_length=256)
|
| 75 |
+
with torch.no_grad():
|
| 76 |
+
logits = mdl(**enc).logits
|
| 77 |
+
pred = logits.softmax(-1).argmax(-1).item()
|
| 78 |
+
print("Prediction:", id2label[pred])
|
| 79 |
+
```
|
| 80 |
|
| 81 |
## Training Details
|
| 82 |
|
| 83 |
+
### Data
|
| 84 |
+
- **Path (Kaggle):** `/kaggle/input/nli-vietnam/full_data_true.json`
|
| 85 |
+
- **Labels:** `{"c":0, "n":1, "e":2}`
|
| 86 |
+
- **Split:** Stratified ~80/10/10 (train/val/test)
|
| 87 |
+
|
| 88 |
+
*Ensure JSON has fields: `id`, `premise`, `hypothesis`, `label` (labels in `{c,n,e}`).*
|
| 89 |
+
|
| 90 |
+
### Procedure
|
| 91 |
+
|
| 92 |
+
**Preprocessing**
|
| 93 |
+
- **Tokenizer:** `XLMRobertaTokenizerFast` (max_length=256, truncation)
|
| 94 |
+
|
| 95 |
+
**Hyperparameters**
|
| 96 |
+
- **Epochs:** 4
|
| 97 |
+
- **Optim:** AdamW (via HF Trainer)
|
| 98 |
+
- **LR:** 2e-5
|
| 99 |
+
- **Weight decay:** 0.01
|
| 100 |
+
- **Warmup ratio:** 0.06
|
| 101 |
+
- **Scheduler:** linear
|
| 102 |
+
- **Batch:** `per_device_train_batch_size=8`, `per_device_eval_batch_size=32`
|
| 103 |
+
- **Grad Accumulation:** 2 (effective train batch ~16)
|
| 104 |
+
- **Precision:** `bf16` if available (Ampere+), else `fp16`
|
| 105 |
+
- **Label smoothing:** 0.05
|
| 106 |
+
- **Early stopping:** patience 2
|
| 107 |
+
- **Gradient checkpointing:** enabled
|
| 108 |
+
- `save_safetensors=True`, `load_best_model_at_end=True` on `f1_macro`
|
| 109 |
+
|
| 110 |
+
### Compute
|
| 111 |
+
- **Hardware:** Single NVIDIA T4/P100 16GB (Kaggle)
|
| 112 |
+
- `dataloader_num_workers=2`, `pin_memory=True`
|
| 113 |
+
|
| 114 |
+
### Speeds, Sizes, Times
|
| 115 |
+
- **Checkpoint size:** standard `xlm-roberta-base` head (+classifier)
|
| 116 |
+
- *Exact wall-clock depends on GPU; typical Kaggle session completes within normal time limits.*
|
| 117 |
|
| 118 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
## Evaluation
|
| 121 |
|
| 122 |
+
### Metrics & Factors
|
| 123 |
+
- **Metrics:** Accuracy, Macro F1
|
| 124 |
+
- **Factors:** Per-label performance (c, n, e)
|
| 125 |
+
|
| 126 |
+
### Results (Test)
|
| 127 |
+
```yaml
|
| 128 |
+
Accuracy: 0.9901
|
| 129 |
+
Macro F1: 0.9878
|
| 130 |
+
Support: 1113 samples (c=429, n=108, e=576)
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
**Classification Report:**
|
| 134 |
+
```
|
| 135 |
+
precision recall f1-score support
|
| 136 |
+
|
| 137 |
+
c 0.9930 0.9883 0.9907 429
|
| 138 |
+
n 0.9815 0.9815 0.9815 108
|
| 139 |
+
e 0.9896 0.9931 0.9913 576
|
| 140 |
+
|
| 141 |
+
weighted avg 0.9901 0.9901 0.9901 1113
|
| 142 |
+
```
|
| 143 |
+
|
| 144 |
+
**Confusion Matrix:**
|
| 145 |
+
```[[424 0 5],
|
| 146 |
+
[ 1 106 1],
|
| 147 |
+
[ 2 2 572]]
|
| 148 |
+
```
|
| 149 |
+
*Note: Replicate numbers may vary slightly due to randomness/hardware.*
|
| 150 |
+
|
| 151 |
+
### Environmental Impact
|
| 152 |
+
- **Hardware:** Single T4/P100 16GB (Kaggle)
|
| 153 |
+
- **Cloud Provider/Region:** Kaggle (unspecified)
|
| 154 |
+
- **Hours used:** Not logged
|
| 155 |
+
- **Carbon Emitted:** Not estimated
|
| 156 |
+
- *You can estimate with the [MLCO2 Impact calculator](https://mlco2.github.io/impact#compute).*
|
| 157 |
|
| 158 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
+
## Technical Specifications
|
| 161 |
|
| 162 |
+
### Architecture & Objective
|
| 163 |
+
- **Backbone:** XLM-RoBERTa Base
|
| 164 |
+
- **Head:** Linear classification (3 labels)
|
| 165 |
+
- **Objective:** Cross-entropy with label smoothing (0.05); optional class weighting (off by default)
|
| 166 |
|
| 167 |
+
### Software
|
| 168 |
+
- `transformers==4.43.3`
|
| 169 |
+
- `datasets==2.21.0`
|
| 170 |
+
- `accelerate==0.33.0`
|
| 171 |
+
- `evaluate==0.4.2`
|
| 172 |
+
- `scikit-learn==1.5.1`
|
| 173 |
+
- `torch` (CUDA)
|
| 174 |
|
| 175 |
+
---
|
| 176 |
|
| 177 |
+
## Citation
|
| 178 |
|
| 179 |
+
### XLM-RoBERTa
|
| 180 |
+
```bibtex
|
| 181 |
+
@inproceedings{conneau2020unsupervised,
|
| 182 |
+
title={Unsupervised Cross-lingual Representation Learning at Scale},
|
| 183 |
+
author={Conneau, Alexis and Khandelwal, Kartikay and Goyal, Naman and Chaudhary, Vishrav and Wenzek, Guillaume and Guzm{\'a}n, Francisco and Grave, Edouard and Ott, Myle and Zettlemoyer, Luke and Stoyanov, Veselin},
|
| 184 |
+
booktitle={ACL},
|
| 185 |
+
year={2020}
|
| 186 |
+
}
|
| 187 |
+
```
|
| 188 |
|
| 189 |
+
## Contact
|
| 190 |
+
**Author:** Lê Lý
|