https://github.com/fa-mc/w266_proj
https://github.com/fa-mc/w266_proj
Last synced: 12 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/fa-mc/w266_proj
- Owner: fa-mc
- Created: 2018-12-09T00:23:02.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-09T01:28:10.000Z (over 7 years ago)
- Last Synced: 2026-06-18T20:19:58.481Z (19 days ago)
- Language: Python
- Size: 12.1 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Chinese Sentiment Analysis with Google BERT
### Instructions
The Bert folder is cloned from Google's official repository (git pull git@github.com:google-research/bert.git). I have edited the run_classifier.py file to make it compatible with our processed ChnSentiCorp data.
#### 1. Download and extract the BERT base Chinese monolanguage model into ./bert/models
```
mkdir $PROJ/bert/models
cd $PROJ/bert/models
wget https://storage.googleapis.com/bert_models/2018_11_03/chinese_L-12_H-768_A-12.zip
unzip chinese_L-12_H-768_A-12.zip
```
#### 2. (skip 2 & 3 if you want to use the processed data) unzip the ChnSentiCorp data
```
cd $PROJ/data/raw/
unzip chnsenticorp.zip ./data/raw/
```
#### 3. (skip 2 & 3 if you want to use the processed data) Run process_csc.ipynb to process the raw files
#### 4. Run the following command to train and evaluate the models
The official document from Google used python2 and TensorFlow 1.11 I ran the code with python3.6 and TensorFlow 1.10 without error.
Increasing the max_seq_length and / or train_batch_size might yield better results. My PC (GTX 1070) is limited to 128 / 20.
```
cd $PROJ/bert
# dangdang
python run_classifier.py --task_name csc --do_train --do_eval \
--data_dir $PROJ/data/processed/csc/dangdang \
--vocab_file $PROJ/bert/models/chinese_L-12_H-768_A-12/vocab.txt \
--bert_config_file $PROJ/bert/models/chinese_L-12_H-768_A-12/bert_config.json \
--init_checkpoint $PROJ/bert/models/chinese_L-12_H-768_A-12/bert_model.ckpt \
--max_seq_length 128 --train_batch_size 20 --learning_rate 2e-5 --num_train_epochs 3.0 \
--output_dir $PROJ/output/dangdang --local_rank 3
# ctrip
python run_classifier.py --task_name csc --do_train --do_eval \
--data_dir $PROJ/data/processed/csc/ctrip \
--vocab_file $PROJ/bert/models/chinese_L-12_H-768_A-12/vocab.txt \
--bert_config_file $PROJ/bert/models/chinese_L-12_H-768_A-12/bert_config.json \
--init_checkpoint $PROJ/bert/models/chinese_L-12_H-768_A-12/bert_model.ckpt \
--max_seq_length 128 --train_batch_size 20 --learning_rate 2e-5 --num_train_epochs 3.0 \
--output_dir $PROJ/output/ctrip --local_rank 3
# jingdong
python run_classifier.py --task_name csc --do_train --do_eval \
--data_dir $PROJ/data/processed/csc/jingdong \
--vocab_file $PROJ/bert/models/chinese_L-12_H-768_A-12/vocab.txt \
--bert_config_file $PROJ/bert/models/chinese_L-12_H-768_A-12/bert_config.json \
--init_checkpoint $PROJ/bert/models/chinese_L-12_H-768_A-12/bert_model.ckpt \
--max_seq_length 128 --train_batch_size 20 --learning_rate 2e-5 --num_train_epochs 3.0 \
--output_dir $PROJ/output/jingdong --local_rank 3
# combined
python run_classifier.py --task_name csc --do_train --do_eval \
--data_dir $PROJ/data/processed/csc/all \
--vocab_file $PROJ/bert/models/chinese_L-12_H-768_A-12/vocab.txt \
--bert_config_file $PROJ/bert/models/chinese_L-12_H-768_A-12/bert_config.json \
--init_checkpoint $PROJ/bert/models/chinese_L-12_H-768_A-12/bert_model.ckpt \
--max_seq_length 128 --train_batch_size 20 --learning_rate 2e-5 --num_train_epochs 3.0 \
--output_dir $PROJ/output/csc_all --local_rank 3
```