Skip to content
Source code and dataset for ACL 2019 paper "Cognitive Graph for Multi-Hop Reading Comprehension at Scale"
Branch: master
Clone or download
Latest commit 217f0f1 Jul 26, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples intermediate Jul 14, 2019
LICENSE Initial commit May 29, 2019 detailed codes Jul 14, 2019 detailed codes Jul 14, 2019 detailed codes Jul 14, 2019 detailed codes Jul 14, 2019 Update Jul 16, 2019 fix typos Jul 26, 2019
requirements.txt detailed codes Jul 14, 2019 detailed codes Jul 14, 2019 detailed codes Jul 14, 2019


Project | arXiv

Source codes for the paper Cognitive Graph for Multi-Hop Reading Comprehension at Scale. (ACL 2019 Oral)

We also have a Chinese blog about CogQA on Zhihu (知乎) besides the paper.


CogQA is a novel framework for multi-hop question answering in web-scale documents. Founded on the dual process theory in cognitive science, CogQA gradually builds a cognitive graph in an iterative process by coordinating an implicit extraction module (System 1) and an explicit reasoning module (System 2). While giving accurate answers, our framework further provides explainable reasoning paths.


  1. Download and setup Redis database following
  2. Download the dataset, evalute script and fullwiki data (enwiki-20171001-pages-meta-current-withlinks-abstracts) from Unzip in this repo.
  3. pip install -r requirements.txt
  4. Run python to load wikipedia documents to redis (check the size of dump.pkl is about 2.4GB).
  5. Run python to generate hotpot_train_v1.1_refined.json, which contains edges in gold-only cognitive graphs.
  6. mkdir models


The codes automatic assign tasks on all available devices, each handling batch_size / num_gpu samples. We recommend that each gpu has at least 11GB memory to hold 2 batch.

  1. Run python to train Task #1(span extraction).
  2. Run python --load=True --mode='bundle' to train Task #2(answer prediction).


The is the algorithm to answer questions with a trained model. We split the 1-hop nodes found by another similar model into for reuse in other algorithm. It can directly improve your result on fullwiki setting by just replacing the original input.

  1. unzip

  2. python --data_file='hotpot_dev_fullwiki_v1_merge.json'

  3. python hotpot_dev_fullwiki_v1_merge_pred.json hotpot_dev_fullwiki_v1_merge.json

  4. You can check the cognitive graph (reasoning process) in the cg part of the predicted json file.


  1. The changes of this version from the preview version is mainly about detailed comments.
  2. The relatively sensetive hyperparameters includes the number of negative samples, top K, learning rate of task #2, scale factors between different parts...
  3. If our work is useful to you, please cite our paper or star 🌟 our repo~~
You can’t perform that action at this time.