Downloads · 30 days
0
tung1707/vietnamese-sentiment-lora
vietnamese-sentiment-lora is a machine learning model from tung1707. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
Fine-tuned Gemma 2B-IT bằng QLoRA để phân loại cảm xúc (sentiment) tiếng Việt trên dataset UIT-VSFC.
Downloads · 30 days
0
Access
Public
Updated May 19, 2026
Repo size
41.7 MB
Likes
0
Public
Click a slice to open those files.
.json34.4 MB · 82%
From the Hugging Face model README
Fine-tuned Gemma 2B-IT bằng QLoRA để phân loại cảm xúc (sentiment) tiếng Việt trên dataset UIT-VSFC.
| Metric | Baseline (zero-shot) | Fine-tuned (LoRA) | Cải thiện |
|---|---|---|---|
| Weighted F1 | 10.7% | 94.9% | +787% |
| Accuracy | 10.0% | 95.0% | +850% |
| Class | Precision | Recall | F1-score |
|---|---|---|---|
| Positive | 0.97 | 0.94 | 0.96 |
| Negative | 0.93 | 0.99 | 0.96 |
| Neutral | 0.83 | 0.62 | 0.71 |
Neutral F1 thấp hơn do chỉ có 8 samples trong test set, không phải do model kém.
Phân loại câu phản hồi của sinh viên Việt Nam thành 3 loại: positive, negative, neutral.
UIT-VSFC — Vietnamese Students' Feedback Corpus, gồm 16,000+ câu tiếng Việt được gán nhãn bởi người.
| Split | Samples |
|---|---|
| Train | 11,426 |
| Validation | 1,583 |
| Test | 3,166 |
QLoRA (Quantized Low-Rank Adaptation):
google/gemma-2b-itq_proj, v_projTraining config:
| Epoch | Training Loss | Validation Loss |
|---|---|---|
| 1 | 0.9493 | 0.8839 |
| 2 | 0.8964 | 0.8458 |
| 3 | 0.8533 | 0.8422 |
pip install transformers peft bitsandbytes accelerate torch
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
from peft import PeftModel
import torch
# Load base model với 4-bit quantization
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.float16,
)
base_model = AutoModelForCausalLM.from_pretrained(
"google/gemma-2b-it",
quantization_config=bnb_config,
device_map="auto",
)
# Load LoRA adapter
model = PeftModel.from_pretrained(base_model, "tung1707/vietnamese-sentiment-lora")
tokenizer = AutoTokenizer.from_pretrained("tung1707/vietnamese-sentiment-lora")
# Predict
def predict_sentiment(text):
prompt = f"""Phân loại sentiment của câu tiếng Việt sau thành đúng 1 từ: positive, negative, hoặc neutral.
Câu: "{text}"
Sentiment:"""
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model.generate(**inputs, max_new_tokens=10, do_sample=False)
response = tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
return response.strip().lower()
# Test
print(predict_sentiment("Giảng viên dạy rất nhiệt tình")) # → positive
print(predict_sentiment("Phòng học quá nóng")) # → negative
print(predict_sentiment("Lịch thi được thông báo đúng hạn")) # → neutral
├── LoRA_Vietnamese_Sentiment.ipynb # Notebook training hoàn chỉnh
├── README.md
├── adapter_config.json # LoRA config
└── adapter_model.safetensors # LoRA weights (~vài MB)