cairoHy / RC-experiments

Reading Comprehension Experiments repository.
GNU General Public License v3.0
61 stars 27 forks source link
aoa-reader attention-sum-reader cbt natural-language-processing reading-comprehension tensorflow

Reading Comprehension Experiments

About

This is the tensorflow version implementation/reproduce of some reading comprehension models in some reading comprehension datasets including the following:

Models:

Datasets:

Start To Use

1.Clone the code

git clone https://github.com/zhanghaoyu1993/RC-experiments.git

2.Get needed data

cd data
./prepare-all.sh

3.Environment Preparation

pip install -r requirements.txt
pip install tensorflow-gpu --upgrade
python -m nltk.downloader punkt

4.Set model, dataset and other command parameters

The main.py file in root directory.

Type a command like above, the model_class is the class name of model, usually named in cambak-style:

python main.py [model_class]

For example, if you want to use AttentionSumReader:

python main.py AttentionSumReader

Type a command like above, the dataset_class is the class name of dataset:

python main.py [model_class] --dataset [dataset_class]

For example, if you want to use CBT:

python main.py [model_class] --dataset CBT

You don't need to specify the data_root and train valid test file name in most cases, just specify the dataset.

The program use argparse to deal with parameters, you can type the following command to get help:

python main.py --help

or:

python main.py -h

The parameters will be stored into a file named args.json when executed, so next time you can type the following simplified command:

python main.py [model_class] --args_file [args.json]

5.Train and test the model

First, modify the parameters in the args.json.

You can now train and test the model by entering the following commands. The params in [] should be determined by the real situation.

python main.py [model_class] --args_file [args.json] --train 1 --test 0 

After train, the parameters are stored in weight_path/args.json and the model checkpoints are stored in weight_path.

python main.py [model_class] --args_file [args.json] --train 0 --test 1 

After test, the performance of model are stored in weight_path/result.json.

6.model performance

All the trained results and corresponding config params are saved in sub directories of weight_path(by default the weight folder) named args.json and result.json.

You should know that the implementation of some models are slightly different from the original, but the basic ideas are same, so the results are for reference only.

The best results of implemented models are listed below:

CBT-NE CBT-CN
AS-Reader 69.88(68.6) 65.0(63.4)
AoA-Reader 71.0(72.0) 68.12(69.4)

7.FAQ

Once you enter a command in the shell(maybe a long one), the config will be stored in weight_path/args.json where weight_path is defined by another argument, after the command execute you can use --args.json to simplify the following command:

python main.py [model_class] --args_file [args.json]

And the priorities of arguments typed in the command line is higher than those stored in args.json, so you can change some arguments.