tien02/ensemble-roberta-fasttext-vietnamese

Ensemble PhoBERT with FastText Embedding to improve performance on Vietnamese Sentiment Analysis tasks.

Python

16

2 commits

updated Jun 29, 2023

See the code

README

Ensemble PhoBERT & FastText in Vietnamese Sentiment Analysis task

UPDATE:

  • Optimize code directory structure

TO DO:

  • fix ensemble procedure
  • Containerize with Docker

Dataset

I used UIT-VSFC (Vietnamese Students’ Feedback Corpus) dataset in this project. This dataset collected students feedback about the school after every semester from 2013 to 2016. It contains over 16,000 sentences with 2 tasks: sentiments and topics. In this project I just experimented with sentiment task only.

In sentimenst task, there are 3 labels: 0: Positive, 1:Neural and 2:Negative. The distriution of this task is highly imbalanced, most of the label in Positive and Negative which tremendously affect the performance.

Model

  • Finetune PhoBERT on downstream task.
  • Build a FastText embedding on train+val corpus, vector_dim=300.

I experimented on these models:

  • PhoBERT(base/large) + FeedForward.
  • PhoBERT(base/large) + LSTM.
  • FastText + LSTM.
  • FastText + SVM.

Experiment

  • Use CrossEntropyLoss as loss function.
  • Final Dense Layer used LogSoftmax as acivation function. Experiment shows that it not only helps training process more stable but also improves performance.
  • Finetuning PhoBERT(large) on Google Colab always faced with OOM, I used Gradient Accumulation to fix this issue.
  • Finetune PhoBERT with Adam optimizer, learning_rate=1e-4, apply OneCycleLR learning rate scheduler with max_lr=learning_rate.
  • FastText_LSTM also use Adam optimizer, learning_rate=1e-3, apply OneCycleLR learning rate scheduler with max_lr=learning_rate.
  • First experiment show on Confusion Matrix that majority of models's performance not good in predicting 1:Neural because of Imbalanced dataset.
  • Ensemble model on first experiment does not significantly improve the model's performance.
  • Then experiment with class_weight in order to due with class imbalanced improved Precision and F1-score on all models.
  • Ensemble model with second experiment improve all models's performance.

Ensemble_pred= ratio * pred1 + (1-ratio) * pred2

  • ratio in range[0, 1]

  • pred1 is the model with superior performance, pred2 vice versa. Ensemble_pred compares result with pred1's model.

Directory Structure

Expect directory structure be like:

├── /config
├── /data
│   ├── README.txt
│   ├── dev
│   │   ├── sentiments.txt
│   │   ├── sents.txt
│   │   └── topics.txt
│   ├── test
│   │   ├── sentiments.txt
│   │   ├── sents.txt
│   │   └── topics.txt
│   └── train
│       ├── sentiments.txt
│       ├── sents.txt
│       └── topics.txt
├── /src
├── ensemble.py
├── main.py
├── requirements.txt
├── test.sh
├── train.sh
├── train_fasttext.sh
├── train_svm.sh
└── utils.py

data is the UIT-VSFC downloaded

Run code

Run the following command for execution information:

python main.py --help
  1. Install dependencies
pip install -r requirements.txt
  1. Train FastText Embedding
bash train_fasttext.sh
  1. Train BERT-base models & FastText-LSTM
  • Check hyperpamter at config folder, modify it as your need
bash train.sh
  1. Test BERT-base models & FastText-LSTM
bash test.sh

Result

Evaluation on Test Set

ModelPrecisionRecallF1-score
(1) PhoBERT (base) + FeedForward0.925020.929880.92348
(2) PhoBERT (large) + FeedForward0.914470.909350.88475
(3) PhoBERT (base) + LSTM0.923990.928930.92259
(4) PhoBERT (large) + LSTM0.910620.905560.88104
(5) FastText + LSTM0.840220.863230.84127
(6) FastText + SVM0.848250.866390.85023

Emsemble evaluation on Test Set

ModelRatioPrecisionRecallF1-score
(2) + (6)0.50.894170.911240.88877
(2) + (4)0.70.915870.910930.88627
(2) + (5)0.80.915210.910300.88565
(4) + (6)0.20.890820.905560.88562
(4) + (5)0.70.911450.906510.88195
(5) + (6)0.40.855320.872080.85340

Evaluation on Test set with class weights

ModelPrecisionRecallF1-score
(1) PhoBERT (base) + FeedForward0.928670.926720.92751
(2) PhoBERT (large) + FeedForward0.907560.90240.87796
(3) PhoBERT (base) + LSTM0.924890.923560.92407
(4) PhoBERT (large) + LSTM0.909650.904610.8801
(5) FastText + LSTM0.857270.812070.83015
(6) FastText + SVM0.853760.862290.85561

Ensemble Evaluation on Test set with class weights

ModelRatioPrecisionRecallF1-score
(1) + (4)0.80.928450.929560.92889
(1) + (2)0.90.928990.927980.92837
(1) + (6)0.50.929320.928300.92830
(1) + (5)0.90.929430.926720.92783
(3) + (4)0.80.925070.927040.92584
(3) + (6)0.80.925450.924510.92484
(3) + (5)0.60.926540.923560.92474
bert
bert-fine-tuning
fasttext
fasttext-embeddings
fine-tuning
gensim-word2vec
lstm
mlp-classifier
nlp
phobert
pytorch
pytorch-lightning
sentiment-analysis
sentiment-classification
svm-classifier
text-classification

tien02/ensemble-roberta-fasttext-vietnamese

Ensemble PhoBERT with FastText Embedding to improve performance on Vietnamese Sentiment Analysis tasks.

Python

16

2 commits

updated Jun 29, 2023

See the code

README

Ensemble PhoBERT & FastText in Vietnamese Sentiment Analysis task

UPDATE:

  • Optimize code directory structure

TO DO:

  • fix ensemble procedure
  • Containerize with Docker

Dataset

I used UIT-VSFC (Vietnamese Students’ Feedback Corpus) dataset in this project. This dataset collected students feedback about the school after every semester from 2013 to 2016. It contains over 16,000 sentences with 2 tasks: sentiments and topics. In this project I just experimented with sentiment task only.

In sentimenst task, there are 3 labels: 0: Positive, 1:Neural and 2:Negative. The distriution of this task is highly imbalanced, most of the label in Positive and Negative which tremendously affect the performance.

Model

  • Finetune PhoBERT on downstream task.
  • Build a FastText embedding on train+val corpus, vector_dim=300.

I experimented on these models:

  • PhoBERT(base/large) + FeedForward.
  • PhoBERT(base/large) + LSTM.
  • FastText + LSTM.
  • FastText + SVM.

Experiment

  • Use CrossEntropyLoss as loss function.
  • Final Dense Layer used LogSoftmax as acivation function. Experiment shows that it not only helps training process more stable but also improves performance.
  • Finetuning PhoBERT(large) on Google Colab always faced with OOM, I used Gradient Accumulation to fix this issue.
  • Finetune PhoBERT with Adam optimizer, learning_rate=1e-4, apply OneCycleLR learning rate scheduler with max_lr=learning_rate.
  • FastText_LSTM also use Adam optimizer, learning_rate=1e-3, apply OneCycleLR learning rate scheduler with max_lr=learning_rate.
  • First experiment show on Confusion Matrix that majority of models's performance not good in predicting 1:Neural because of Imbalanced dataset.
  • Ensemble model on first experiment does not significantly improve the model's performance.
  • Then experiment with class_weight in order to due with class imbalanced improved Precision and F1-score on all models.
  • Ensemble model with second experiment improve all models's performance.

Ensemble_pred= ratio * pred1 + (1-ratio) * pred2

  • ratio in range[0, 1]

  • pred1 is the model with superior performance, pred2 vice versa. Ensemble_pred compares result with pred1's model.

Directory Structure

Expect directory structure be like:

├── /config
├── /data
│   ├── README.txt
│   ├── dev
│   │   ├── sentiments.txt
│   │   ├── sents.txt
│   │   └── topics.txt
│   ├── test
│   │   ├── sentiments.txt
│   │   ├── sents.txt
│   │   └── topics.txt
│   └── train
│       ├── sentiments.txt
│       ├── sents.txt
│       └── topics.txt
├── /src
├── ensemble.py
├── main.py
├── requirements.txt
├── test.sh
├── train.sh
├── train_fasttext.sh
├── train_svm.sh
└── utils.py

data is the UIT-VSFC downloaded

Run code

Run the following command for execution information:

python main.py --help
  1. Install dependencies
pip install -r requirements.txt
  1. Train FastText Embedding
bash train_fasttext.sh
  1. Train BERT-base models & FastText-LSTM
  • Check hyperpamter at config folder, modify it as your need
bash train.sh
  1. Test BERT-base models & FastText-LSTM
bash test.sh

Result

Evaluation on Test Set

ModelPrecisionRecallF1-score
(1) PhoBERT (base) + FeedForward0.925020.929880.92348
(2) PhoBERT (large) + FeedForward0.914470.909350.88475
(3) PhoBERT (base) + LSTM0.923990.928930.92259
(4) PhoBERT (large) + LSTM0.910620.905560.88104
(5) FastText + LSTM0.840220.863230.84127
(6) FastText + SVM0.848250.866390.85023

Emsemble evaluation on Test Set

ModelRatioPrecisionRecallF1-score
(2) + (6)0.50.894170.911240.88877
(2) + (4)0.70.915870.910930.88627
(2) + (5)0.80.915210.910300.88565
(4) + (6)0.20.890820.905560.88562
(4) + (5)0.70.911450.906510.88195
(5) + (6)0.40.855320.872080.85340

Evaluation on Test set with class weights

ModelPrecisionRecallF1-score
(1) PhoBERT (base) + FeedForward0.928670.926720.92751
(2) PhoBERT (large) + FeedForward0.907560.90240.87796
(3) PhoBERT (base) + LSTM0.924890.923560.92407
(4) PhoBERT (large) + LSTM0.909650.904610.8801
(5) FastText + LSTM0.857270.812070.83015
(6) FastText + SVM0.853760.862290.85561

Ensemble Evaluation on Test set with class weights

ModelRatioPrecisionRecallF1-score
(1) + (4)0.80.928450.929560.92889
(1) + (2)0.90.928990.927980.92837
(1) + (6)0.50.929320.928300.92830
(1) + (5)0.90.929430.926720.92783
(3) + (4)0.80.925070.927040.92584
(3) + (6)0.80.925450.924510.92484
(3) + (5)0.60.926540.923560.92474
bert
bert-fine-tuning
fasttext
fasttext-embeddings
fine-tuning
gensim-word2vec
lstm
mlp-classifier
nlp
phobert
pytorch
pytorch-lightning
sentiment-analysis
sentiment-classification
svm-classifier
text-classification