• Stars
    star
    173
  • Rank 220,124 (Top 5 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 5 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Code & data accompanying the NAACL 2019 paper "Bidirectional Attentive Memory Networks for Question Answering over Knowledge Bases"

BAMnet

Code & data accompanying the NAACL2019 paper "Bidirectional Attentive Memory Networks for Question Answering over Knowledge Bases"

Get started

Prerequisites

This code is written in python 3. You will need to install a few python packages in order to run the code. We recommend you to use virtualenv to manage your python packages and environments. Please take the following steps to create a python virtual environment.

  • If you have not installed virtualenv, install it with pip install virtualenv.
  • Create a virtual environment with virtualenv venv.
  • Activate the virtual environment with source venv/bin/activate.
  • Install the package requirements with pip install -r requirements.txt.

Run the KBQA system

  • Download the preprocessed data from here and put the data folder under the root directory.

  • Create a folder (e.g., runs/WebQ/) to save model checkpoint. You can download the pretrained models from here. (Note: if you cannot access the above data and pretrained models, please download from here.)

  • Please modify the config files in the src/config/ folder to suit your needs. Note that you can start with modifying only the data folder (e.g., data_dir, model_file, pre_word2vec) and vocab size (e.g., vocab_size, num_ent_types, num_relations), and leave other hyperparameters as they are.

  • Go to the BAMnet/src folder, train the BAMnet model

     python train.py -config config/bamnet_webq.yml
    
  • Test the BAMnet model (with ground-truth topic entity)

    python test.py -config config/bamnet_webq.yml
    
  • Train the topic entity predictor

    python train_entnet.py -config config/entnet_webq.yml
    
  • Test the topic entity predictor

    python test_entnet.py -config config/entnet_webq.yml
    
  • Test the whole system (BAMnet + topic entity predictor)

    python joint_test.py -bamnet_config config/bamnet_webq.yml -entnet_config config/entnet_webq.yml -raw_data ../data/WebQ
    

Preprocess the dataset on your own

  • Go to the BAMnet/src folder, to prepare data for the BAMnet model, run the following cmd:

     python build_all_data.py -data_dir ../data/WebQ -fb_dir ../data/WebQ -out_dir ../data/WebQ
    
  • To prepare data for the topic entity predictor model, run the following cmd:

     python build_all_data.py -dtype ent -data_dir ../data/WebQ -fb_dir ../data/WebQ -out_dir ../data/WebQ
    

Note that in the message printed out, your will see some data statistics such as vocab_size, num_ent_types , num_relations. These numbers will be used later when modifying the config files.

  • Download the pretrained Glove word ebeddings glove.840B.300d.zip.

  • Unzip the file and convert glove format to word2vec format using the following cmd:

     python -m gensim.scripts.glove2word2vec --input glove.840B.300d.txt --output glove.840B.300d.w2v
    
  • Fetch the pretrained Glove vectors for our vocabulary.

     python build_pretrained_w2v.py -emb glove.840B.300d.w2v -data_dir ../data/WebQ -out ../data/WebQ/glove_pretrained_300d_w2v.npy -emb_size 300
    

Architecture

Experiment results on WebQuestions

Results on WebQuestions test set. Bold: best in-category performance.

Predicted answers of BAMnet w/ and w/o bidirectional attention on the WebQuestions test set

pred_examples

Attention heatmap generated by the reasoning module

attn_heatmap

Reference

If you found this code useful, please consider citing the following paper:

Yu Chen, Lingfei Wu, Mohammed J. Zaki. "Bidirectional Attentive Memory Networks for Question Answering over Knowledge Bases." In Proc. 2019 Annual Conference of the North American Chapter of the Association for Computational Linguistics (NAACL-HLT2019). June 2019.

@article{chen2019bidirectional,
  title={Bidirectional Attentive Memory Networks for Question Answering over Knowledge Bases},
  author={Chen, Yu and Wu, Lingfei and Zaki, Mohammed J},
  journal={arXiv preprint arXiv:1903.02188},
  year={2019}
}

More Repositories

1

Eye-Tracker

Implemented and improved the iTracker model proposed in the paper "Eye Tracking for Everyone"
Python
199
star
2

IDGL

Code & data accompanying the NeurIPS 2020 paper "Iterative Deep Graph Learning for Graph Neural Networks: Better and Robust Node Embeddings".
Python
198
star
3

KATE

Code & data accompanying the KDD 2017 paper "KATE: K-Competitive Autoencoder for Text"
Python
142
star
4

RL-based-Graph2Seq-for-NQG

Code & data accompanying the ICLR 2020 paper "Reinforcement Learning Based Graph-to-Sequence Model for Natural Question Generation"
Python
119
star
5

PFoodReq

Code & data accompanying the WSDM 2021 paper "Personalized Food Recommendation as Constrained Question Answering over a Large-scale Food Knowledge Graph"
Python
57
star
6

Graph2Seq-for-KGQG

Code & data accompanying the paper "Toward Subgraph Guided Knowledge Graph Question Generation with Graph Neural Networks"
Python
42
star
7

GraphFlow

Code & data accompanying the IJCAI 2020 paper "GraphFlow: Exploiting Conversation Flow with Graph Neural Networks for Conversational Machine Comprehension"
Python
35
star
8

AI-Papers

Favorite AI papers
17
star
9

rUDP

reliable UDP
C++
9
star
10

KDDCUP2016

Python
8
star
11

CourseNow

一个用python实现的针对电子科技大学网上选课系统的选课脚本,可实现cookie登录,预存课程,多线程选课功能……(项目来源于YaodongZhao,目前只对通信学院开放,不断完善中)
Python
7
star
12

WirelessShow

一个用python实现的图形绘制软件,可接收串口传递的加速度数据并通过计算绘制出图形轨迹。
Python
5
star
13

RenrenDataRepo

a renren.com website based user datas capture and analysis project using python 2.7
Python
4
star
14

winHook

a windows-based hook script for logging your mouse and keyboard events
Python
3
star
15

AcademicWeb

Hugo's academic homepage.
HTML
2
star
16

denoiser

Code accompanying the paper “Fast Voxel-based Surface Propagation Method for Outlier Removal”
C++
2
star
17

DVRouting

stimulating distance vector routing algorithm
C++
2
star
18

BlogWeb

Hugo's personal blog site.
HTML
1
star
19

OS

A simple operating system written in python.
Python
1
star
20

Recommender

realizing algorithms of recommenders. test & exploration...
Python
1
star
21

peoplefinder

Python
1
star
22

algorithms-in-python

Algorithm study notes in python
Python
1
star
23

TTE

C++
1
star
24

Programming-Language

Java
1
star
25

Hugo-CV

Hugo's CV
TeX
1
star
26

wirelessShow_lowerComputer

a lower computer program based on STM32f4 MPU cooperating with WirelessShow repo which is an upper computer program
C
1
star
27

ML-DM-Study-Notes

ML and DM study notes
Python
1
star
28

WebGL-Study-Notes

WebGL study notes
JavaScript
1
star
29

Linux-Programming

Linux programming example codes
C
1
star
30

DataAnalysis

A general framework for analysis of user-item data sets, which may provide suggestions for recommendation systems.
Python
1
star
31

Freeland

Hugo's personal homepage.
CSS
1
star
32

authentication

a realization of OICQ based on MFC directly communicating between server and client.
C++
1
star