/Capsule4TextClassification

Sequence Encoding via Dynamic Routing for Text Classification

Primary LanguagePython

Capsule4TextClassification

Implementation of our paper "Information Aggregation via Dynamic Routing for Sequence Encoding"

Sytem Requirements

OS: Linux (Ubuntu 14.04+)

Python: v3.6

Tensorflow: v1.4.0

Numpy: v1.14

CUDA : v8.0

CUDNN: v6.0

Data Dowload

Refer to downloadDataset for data download instructions

Quick start

Please first refer to Data Dowload and download all the data needed, Go to root of this project Capsule4TextClassification, then type the following command to start training process on correspoding dataset.

#for sentence level datasets, more specifically for SST-1 and SST-2 datasets
python ./caps_attn_flatten/train_test.py --load-config --weight-path ./savings/sst01 
python ./caps_attn_flatten/train_test.py --load-config --weight-path ./savings/sst02

#for document level datasets, more specifically for imdb, yelp-2013 and yelp-2014
python ./caps_attn_hierarchical/train_test.py --load-config --weight-path ./savings/imdb
python ./caps_attn_hierarchical/train_test.py --load-config --weight-path ./savings/yelp2013
python ./caps_attn_hierarchical/train_test.py --load-config --weight-path ./savings/yelp2014

further explanation of the comamnd:

Note that we provide a sentence level model (caps_attn_flatten) and a document level model (caps_attn_hierarchical)

Take first command for example --load-config indicates that before construction of the computational graph we will load a config file from a directory which ever --weight-path specifies, in this case ./savings/sst01. There is a ./savings/sst01/config file that controls the configuration of the model, if you ever want to run another configuration, you should simply copy the ./savings/sst01 directory and modify the config file, and then run a command similar to those specified as above.

--weight-path specifies in which directory we want to store our config file, and most importantly the model checkpoint. Also a status file, which is originally used to avoid conflict. note that if you ever encountered "process running or finished" error, you should remove status file.