This is the implementation for the "BERT + History Answer Embedding" model proposed in the SIGIR'19 paper BERT with History Answer Embedding for Conversational Question Answering. This model incorporates history turns with history answer embedding (HAE) to a BERT based machine comprehension model.
If you use this code for your paper, please cite it as
Chen Qu, Liu Yang, Minghui Qiu, W. Bruce Croft, Yongfeng Zhang and Mohit Iyyer.
BERT with History Answer Embedding for Conversational Question Answering.
In Proceedings of the 42nd International ACM SIGIR Conference on Research & Development
in Information Retrieval (SIGIR 2019).
Bibtext
@inproceedings{bert_hae,
author = {Qu, C. and Yang, L. and Qiu, M. and Croft, W. B. and Zhang, Y. and Iyyer, M.},
title = {BERT with History Answer Embedding for Conversational Question Answering},
booktitle = {SIGIR '19},
year = {2019},
}
- Download the
BERT-base Uncasedmodel here. - Download the QuAC data.
- Configurate the directories for the BERT model and data in
cqa_flags.py. Also, specify a cache directory in it. - Run
python hae.py \
--output_dir=OUTPUT_DIR/ \
--history=6 \
--num_train_epochs=3.0 \
--train_steps=24000 \
--max_considered_history_turns=11 \
--learning_rate=3e-05 \
--warmup_proportion=0.1 \
--evaluation_steps=1000 \
--evaluate_after=18000 \
--load_small_portion=False \
--train_batch_size=12 \
--max_answer_length=40
Setting the max_seq_length to 512 should give better results.
- During training, you can monitor it via tensorboard, the log directory is the
summariesunder the output directory. - After training, the best result is stored in the
results.txtunder the output directory. Also look atstep_results.txtunder the same directory to see at what step we get the best result.
Program arguments can be set in cqa_flgas.py. Alternatively, they could be specified at running by command line arguments. Most of the arguments are self-explanatory. Here are some selected arguments:
-
num_train_epochs,train_steps,learning_rate,warmup_proportion: the learning rate follow a schedule of warming up to the specified larning rate and then decaying. This schedule is described in the transformer paper. Our model trains fortrain_stepsinstead of fullnum_train_epochsepochs. -
load_small_portion. Set toTruefor loading a small portion of the data for testing purpose when we are developing the model. Set toFalseto load all the data when running the model. -
cache_dir. When we run the model for the first time, it preprocesses the data and saves it in a cache directory. After that, the model reads the propocessed data from the cache. -
max_considered_history_turnsandhistory. We only considermax_considered_history_turnsprevious turns when preprocessing the data. This is typically set to 11, meaning that all previous turns are under consideration (for QuAC). We incorporatehistoryprevious turns via history answer embedding. This can be tunned. Current results suggest 5 or 6 give the best performance.
hae.py. Entry code.cqa_supports.py. Utility functions.scorer.py. Official evaluation script for QuAC.
Most other files are for BERT.
Tested with Python 3.6.7 and TensorFlow 1.8.0
HAE with 6 histories gives f1 of 63.1 on validation data.