Counting 3,463 Big Data & Machine Learning Frameworks, Toolsets, and Examples...
Suggestion? Feedback? Tweet @stkim1

Last Commit
Jan. 4, 2019
Apr. 25, 2018



I'm very busy these months. I'll return to this repo in about 10 days.


An implementation of QANet with PyTorch.

Any contributions are welcome!

Current performance

F1 EM Got by
66 ? InitialBug
64 50 BangLiu


  1. Install pytorch 0.4 for Python 3.6+
  2. Run pip install -r requirements.txt to install python dependencies.
  3. Run to download the dataset.
  4. Run python --mode data to build tensors from the raw dataset.
  5. Run python --mode train to train the model. After training, log/ will be generated.
  6. Run python --mode test to test an pretrained model. Default model file is log/

Structure downloads dataset and builds input tensors. program entry; functions about training and testing. QANet structure. configurations.

Differences from the paper

  1. The paper doesn't mention which activation function they used. I use relu.
  2. I don't set the embedding of <UNK> trainable.
  3. The connector between embedding layers and embedding encoders may be different from the implementation of Google, since the description in the paper is inconsistent (residual block can't be used because the dimensions of input and output are different) and they don't say how they implemented it.


  • Reduce memory usage
  • Improve converging speed (to reach 60 F1 scores in 1000 iterations)
  • Reach state-of-art scroes of the original paper
  • Performance analysis
  • Test on SQuAD 2.0


  1. InitialBug: found two bugs: (1) positional encodings require gradients; (2) wrong weight sharing among encoders.
  2. linthieda: fixed one issue about dependencies and offered computing resources.
  3. BangLiu: tested the model.
  4. wlhgtc: (1) improved the calculation of Context-Question Attention; (2) fixed a bug that is compacting embeddings before highway nets.