--- language: - vi metrics: - accuracy - f1 tags: - sentiment-analysis - social-listening library_name: transformers --- # 5CD-ViSoBERT for Vietnamese Sentiment Analysis YOU ARE TOO BORED AND TIRED OF HAVING TO BUILD A 🇻🇳 VIETNAMESE SENTIMENT ANALYSIS MODEL OVER AND OVER AGAIN? BOOM! 🤯 NO WORRIES, WE'RE HERE FOR YOU =)) 🔥! This model is based on our pretrained [5CD-AI/visobert-14gb-corpus](https://huggingface.co/5CD-AI/visobert-14gb-corpus), which has been continuously trained on a 14GB dataset of Vietnamese social content. So it can perform well with many comment sentiments accompanied by emojis 😂👍💬🔥 Our model is fine-tuned on 120K Vietnamese sentiment analysis datasets , including comments and reviews from e-commerce platforms, social media, and forums. Our model has been trained on a diverse range of datasets: SA-VLSP2016, AIVIVN-2019, UIT-VSFC, UIT-VSMEC, UIT-ViCTSD, UIT-ViOCD, UIT-ViSFD, Vi-amazon-reviews, Tiki-reviews. The model will give softmax outputs for three labels. Labels: ``` 0 -> Negative 1 -> Positive 2 -> Neutral ``` ## Dataset Our training dataset. Because of label ambiguity, with UIT-VSMEC, UIT-ViCTSD, VOZ-HSD, we re-label the dataset with Gemini 1.5 Flash API follow the 3 labels. The specific number of samples for each dataset can be seen below:
Dataset Train Test Val
Neg Pos Neu Neg Pos Neu Neg Pos Neu
All-filtered 62708 41400 11593 - - - 5079 3724 638
SA-VLSP2016 4759 4798 4459 1180 1190 1114 - - -
UIT-VSFC 5325 5643 458 1409 1590 167 - - -
UIT-VSMEC (Gemini-label) 3219 1665 594 458 407 210 71 388 239 52
AIVIVN-2019 6776 7879 - 4770 5168 - - - -
UIT-ViCTSD (Gemini-label) 3370 2615 933 3370 2615 933 3370 2615 933
UIT-ViHSD 4162 19886 - 1132 5548 - 482 2190 -
UIT-ViSFD 2850 3670 1266 827 1000 397 409 515 188
UIT-ViOCD 2292 2095 - 279 270 - 283 265 -
Tiki-reviews 20093 6669 4698 - - - - - -
VOZ-HSD (Gemini-label) 2676 1213 1071 - - - - - -
Vietnamese-amazon-polarity 2559 2441 - 1017 983 - 523 477 -
## Evaluation
Model SA-VLSP2016 AIVIVN-2019 UIT-VSFC UIT-VSMEC (Gemini-label) UIT-ViCTSD (Gemini-label)
Acc Prec Recall WF1 Acc Prec Recall WF1 Acc Prec Recall WF1 Acc Prec Recall WF1 Acc Prec Recall WF1
wonrax/phobert-base-vietnamese-sentiment 61.65 63.95 61.65 60.01 84.87 95.12 84.87 89.47 76.37 88.10 76.37 79.53 65.41 74.36 65.41 68.33 62.34 73.08 62.34 65.54
5CD-AI/Vietnamese-Sentiment-visobert 88.06 88.16 88.06 88.06 99.62 99.65 99.62 99.64 94.65 93.30 93.65 93.38 77.91 77.21 77.91 77.46 75.10 74.59 75.10 74.79
Model UIT-ViOCD UIT-ViSFD Vi-amazon-polar
Acc Prec Recall WF1 Acc Prec Recall WF1 Acc Prec Recall WF1
wonrax/phobert-base-vietnamese-sentiment 74.68 87.14 74.68 78.13 67.90 67.95 67.90 66.98 61.40 76.53 61.40 65.70
5CD-AI/Vietnamese-Sentiment-visobert 94.35 94.74 94.35 94.53 93.26 93.20 93.26 93.21 89.90 90.13 89.90 90.01
## Usage (HuggingFace Transformers) Install `transformers` package: pip install transformers ### Pipeline ```python from transformers import pipeline model_path = '5CD-AI/Vietnamese-Sentiment-visobert' sentiment_task = pipeline("sentiment-analysis", model=model_path, tokenizer=model_path) sentiment_task("Miếng dán dễ xước , ko khít với dt 11 prm") ``` Output: ``` [{'label': 'NEG', 'score': 0.998149037361145}] ``` ### Other examples ``` Sentence: Đây là mô hình rất hay, đáp ứng tốt nhu cầu của nhiều doanh nghiệp Việt. ### Sentiment score #### 1) POS: 0.9995 2) NEG: 0.0003 3) NEU: 0.0003 ``` ``` Sentence: Qua vụ này thì uy tín của Trump càng lớn hơn nữa. Nhất là với hình ảnh đầy tính biểu tượng như trên. ### Sentiment score #### 1) POS: 0.9965 2) NEG: 0.0029 3) NEU: 0.0005 ``` ``` Sentence: Bãi đi nó lừa lắm, mình có bỏ vào ví tt này hơn 20 triệu. Lãi tính ra cả tháng dc bao nhiêu mình không nhớ, nhưng khi rút về ngân hàng nó trừ phí giao dịch hơn mịa nó tiền lãi. Nên từ đó cạch luôn ### Sentiment score #### 1) NEG: 0.999 2) POS: 0.0008 3) NEU: 0.0002 ``` ``` Sentence: Vậy chắc tùy nơi rồi :D Chỗ mình chuộng hàng masan lắm, mì gói thì không hẳn (có kokomi cũng bán chạy), con gia vị thì gần như toàn đồ masan. ### Sentiment score #### 1) NEU: 0.9824 2) NEG: 0.0157 3) POS: 0.0019 ``` ``` Sentence: hội sở ở tech trần duy hưng có 1 thằng là thằng Đạt hói. Làm lâu lên lão làng, đc làm lãnh đạo nhưng chả có cái việc mẹ gì chỉ được ngồi xếp ca cho nhân viên. xấu tính bẩn tính sân si nhất cái Tech*. Nghiệp vụ thì ậm ờ đ*o biết gì, chỉ suốt ngày nhận lương đi săm soi nhân viên là nhanh =))) đàn ông đàn ang chả khác mẹ gì mấy con mụ ngoài chợ, nó hành từng nhân viên ra bã, trừ đứa nào nịnh nọt ve vãn với nó. Lậy luôn đhs 1 thằng như thế lại được lên làm lead ở Tech. ### Sentiment score #### 1) NEG: 0.9994 2) POS: 0.0006 3) NEU: 0.0001 ``` ``` Sentence: Cà phê dở ko ngon, ai chưa mua thì đừng mua ### Sentiment score #### 1) NEG: 0.9994 2) POS: 0.0005 3) NEU: 0.0001 ``` ``` Sentence: Cũng tạm. Ko gì đb ### Sentiment score #### 1) NEU: 0.9387 2) NEG: 0.0471 3) POS: 0.0142 ``` ``` Sentence: thui báo ơi.nhà từ trong trứng ra mà sao sáng đc. ### Sentiment score #### 1) NEG: 0.988 2) POS: 0.0119 3) NEU: 0.0001 ``` ``` Sentence: Dm mới kéo cái tuột luôn cái kính cường lực🙂 R phải cầm cái kính tự dán🙂 để lâu quá nó dính hai cục bụi lên nữa chứ má bực thiệt chứ Hình như tại hai cái cục nam châm nó xúc ra 😑 ### Sentiment score #### 1) NEG: 0.9928 2) POS: 0.0071 3) NEU: 0.0001 ``` ``` Sentence: Mấy cái khóa kiểu này ông lên youtube tự học còn ngon hơn. ### Sentiment score #### 1) NEG: 0.9896 2) POS: 0.008 3) NEU: 0.0024 ``` ### Full classification ```python from transformers import AutoModelForSequenceClassification from transformers import TFAutoModelForSequenceClassification from transformers import AutoTokenizer, AutoConfig import numpy as np import torch #### Load model model_path = '5CD-AI/Vietnamese-Sentiment-visobert' tokenizer = AutoTokenizer.from_pretrained(model_path) config = AutoConfig.from_pretrained(model_path) model = AutoModelForSequenceClassification.from_pretrained(model_path).to("cuda") sentence = 'Cũng giống mấy khoá Youtube học cũng được' print('Sentence: ', sentence) input_ids = torch.tensor([tokenizer.encode(sentence)]).to("cuda") with torch.no_grad(): out = model(input_ids) scores = out.logits.softmax(dim=-1).cpu().numpy()[0] # Print labels and scores ranking = np.argsort(scores) ranking = ranking[::-1] print("### Sentiment score ####") for i in range(scores.shape[0]): l = config.id2label[ranking[i]] s = scores[ranking[i]] print(f"{i+1}) {l}: {np.round(float(s), 4)}") ``` Output: ``` Sentence: Cũng giống mấy khoá Youtube học cũng được ### Sentiment score #### 1) NEU: 0.8928 2) NEG: 0.0586 3) POS: 0.0486 ``` ## Fine-tune Configuration We fine-tune `5CD-AI/visobert-14gb-corpus` on downstream tasks with `transformers` library with the following configuration: - seed: 42 - gradient_accumulation_steps: 1 - weight_decay: 0.01 - optimizer: AdamW with betas=(0.9, 0.999) and epsilon=1e-08 - training_epochs: 5 - model_max_length: 256 - learning_rate: 2e-5 - metric_for_best_model: wf1 - strategy: epoch ## References [1] [PhoBERT: Pre-trained language models for Vietnamese](https://aclanthology.org/2020.findings-emnlp.92/) [2] [ViSoBERT: A Pre-Trained Language Model for Vietnamese Social Media Text Processing](https://aclanthology.org/2023.emnlp-main.315/) [3] [The Amazon Polarity dataset](https://paperswithcode.com/dataset/amazon-polarity-1) ## Disclaimer Disclaimer: The data contains actual comments on social networks that might be construed as abusive, offensive, or obscene. Additionally, the examples and dataset may contain negative information about any business. We only collect this data and do not bear any legal responsibility.