Sentiment Analysis

[Download]

Through Fine-tuning Word Language Model

This script can be used to train a sentiment analysis model from scratch, or fine-tune a pre-trained language model. The pre-trained language models are loaded from Gluon NLP Toolkit model zoo. It also showcases how to use different bucketing strategies to speed up training.

Use the following command to run without using pre-trained model (log)

$ python finetune_lm.py --gpu 0 --batch_size 16 --bucket_type fixed --epochs 3 --dropout 0 --no_pretrained --lr 0.005 --valid_ratio 0.1 --save-prefix imdb_lstm_200  # Test Accuracy 85.60

Use the following command to run with pre-trained model (log)

$ python finetune_lm.py --gpu 0 --batch_size 16 --bucket_type fixed --epochs 3 --dropout 0 --lr 0.005 --valid_ratio 0.1 --save-prefix imdb_lstm_200  # Test Accuracy 86.46

TextCNN

This script can be used to train a sentiment analysis model with convolutional neural networks, i.e., textCNN:

Kim, Y. (2014). Convolutional neural networks for sentence classification. arXiv preprint arXiv:1408.5882.

epoch:

  MR SST-1 SST-2 Subj TREC
rand 60 40 40 40 40
static 60 40 40 40 40
non-static 60 40 40 40 40
multichannel 60 40 40 40 40

log:

  MR SST-1 SST-2 Subj TREC
rand [1]/log [5]/log [9]/log [13]/log [17]/log
static [2]/log [6]/log [10]/log [14]/log [18]/log
non-static [3]/log [7]/log [11]/log [15]/log [19]/log
multichannel [4]/log [8]/log [12]/log [16]/log [20]/log

test accuracy (SST-1, SST-2, and TREC) or cross-validation accuracy (MR and Subj):

  MR SST-1 SST-2 Subj TREC
rand 0.7683 0.5412 0.9358 0.8984 0.9780
static 0.7927 0.5421 0.9450 0.9226 0.9840
non-static 0.7960 0.5534 0.9387 0.9206 0.9800
multichannel 0.7999 0.5581 0.9393 0.9249 0.9900

[1]:

$ python sentiment_analysis_cnn.py --gpu 0 --batch_size 50 --epochs 60 --dropout 0.5 --lr 0.0001 --model_mode rand --data_name MR

[2]:

$ python sentiment_analysis_cnn.py --gpu 0 --batch_size 50 --epochs 60 --dropout 0.5 --lr 0.0001 --model_mode static --data_name MR

[3]:

$ python sentiment_analysis_cnn.py --gpu 0 --batch_size 50 --epochs 60 --dropout 0.5 --lr 0.0001 --model_mode non-static --data_name MR

[4]:

$ python sentiment_analysis_cnn.py --gpu 0 --batch_size 50 --epochs 60 --dropout 0.5 --lr 0.0001 --model_mode multichannel --data_name MR

[5]:

$ python sentiment_analysis_cnn.py --gpu 0 --batch_size 50 --epochs 40 --dropout 0.5 --lr 0.0001 --model_mode rand --data_name SST-1

[6]:

$ python sentiment_analysis_cnn.py --gpu 0 --batch_size 50 --epochs 40 --dropout 0.5 --lr 0.0001 --model_mode static --data_name SST-1

[7]:

$ python sentiment_analysis_cnn.py --gpu 0 --batch_size 50 --epochs 40 --dropout 0.5 --lr 0.0001 --model_mode non-static --data_name SST-1

[8]:

$ python sentiment_analysis_cnn.py --gpu 0 --batch_size 50 --epochs 40 --dropout 0.5 --lr 0.0001 --model_mode multichannel --data_name SST-1

[9]:

$ python sentiment_analysis_cnn.py --gpu 0 --batch_size 50 --epochs 40 --dropout 0.5 --lr 0.0001 --model_mode rand --data_name SST-2

[10]:

$ python sentiment_analysis_cnn.py --gpu 0 --batch_size 50 --epochs 40 --dropout 0.5 --lr 0.0001 --model_mode static --data_name SST-2

[11]:

$ python sentiment_analysis_cnn.py --gpu 0 --batch_size 50 --epochs 40 --dropout 0.5 --lr 0.0001 --model_mode non-static --data_name SST-2

[12]:

$ python sentiment_analysis_cnn.py --gpu 0 --batch_size 50 --epochs 40 --dropout 0.5 --lr 0.0001 --model_mode multichannel --data_name SST-2

[13]:

$ python sentiment_analysis_cnn.py --gpu 0 --batch_size 50 --epochs 40 --dropout 0.5 --lr 0.0001 --model_mode rand --data_name Subj

[14]:

$ python sentiment_analysis_cnn.py --gpu 0 --batch_size 50 --epochs 40 --dropout 0.5 --lr 0.0001 --model_mode static --data_name Subj

[15]:

$ python sentiment_analysis_cnn.py --gpu 0 --batch_size 50 --epochs 40 --dropout 0.5 --lr 0.0001 --model_mode non-static --data_name Subj

[16]:

$ python sentiment_analysis_cnn.py --gpu 0 --batch_size 50 --epochs 40 --dropout 0.5 --lr 0.0001 --model_mode multichannel --data_name Subj

[17]:

$ python sentiment_analysis_cnn.py --gpu 0 --batch_size 50 --epochs 40 --dropout 0.5 --lr 0.0001 --model_mode rand --data_name TREC

[18]:

$ python sentiment_analysis_cnn.py --gpu 0 --batch_size 50 --epochs 40 --dropout 0.5 --lr 0.0001 --model_mode static --data_name TREC

[19]:

$ python sentiment_analysis_cnn.py --gpu 0 --batch_size 50 --epochs 40 --dropout 0.5 --lr 0.0001 --model_mode non-static --data_name TREC

[20]:

$ python sentiment_analysis_cnn.py --gpu 0 --batch_size 50 --epochs 40 --dropout 0.5 --lr 0.0001 --model_mode multichannel --data_name TREC