All Projects → hugochan → Bamnet

hugochan / Bamnet

Licence: apache-2.0
Code & data accompanying the NAACL 2019 paper "Bidirectional Attentive Memory Networks for Question Answering over Knowledge Bases"

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Bamnet

Caver
Caver: a toolkit for multilabel text classification.
Stars: ✭ 38 (-72.86%)
Mutual labels:  attention-model
Text Classification Pytorch
Text classification using deep learning models in Pytorch
Stars: ✭ 683 (+387.86%)
Mutual labels:  attention-model
Code
ECG Classification
Stars: ✭ 78 (-44.29%)
Mutual labels:  attention-model
Attention ocr.pytorch
This repository implements the the encoder and decoder model with attention model for OCR
Stars: ✭ 278 (+98.57%)
Mutual labels:  attention-model
Structured Self Attention
A Structured Self-attentive Sentence Embedding
Stars: ✭ 459 (+227.86%)
Mutual labels:  attention-model
Sockeye
Sequence-to-sequence framework with a focus on Neural Machine Translation based on Apache MXNet
Stars: ✭ 990 (+607.14%)
Mutual labels:  attention-model
PBAN-PyTorch
A Position-aware Bidirectional Attention Network for Aspect-level Sentiment Analysis, PyTorch implementation.
Stars: ✭ 33 (-76.43%)
Mutual labels:  attention-model
Linear Attention Recurrent Neural Network
A recurrent attention module consisting of an LSTM cell which can query its own past cell states by the means of windowed multi-head attention. The formulas are derived from the BN-LSTM and the Transformer Network. The LARNN cell with attention can be easily used inside a loop on the cell state, just like any other RNN. (LARNN)
Stars: ✭ 119 (-15%)
Mutual labels:  attention-model
Nmt Keras
Neural Machine Translation with Keras
Stars: ✭ 501 (+257.86%)
Mutual labels:  attention-model
Pytorch Attention Guided Cyclegan
Pytorch implementation of Unsupervised Attention-guided Image-to-Image Translation.
Stars: ✭ 67 (-52.14%)
Mutual labels:  attention-model
Attentiongan
AttentionGAN for Unpaired Image-to-Image Translation & Multi-Domain Image-to-Image Translation
Stars: ✭ 341 (+143.57%)
Mutual labels:  attention-model
Attention Ocr Chinese Version
Attention OCR Based On Tensorflow
Stars: ✭ 421 (+200.71%)
Mutual labels:  attention-model
Awesome Attention Mechanism In Cv
计算机视觉中用到的注意力模块和其他即插即用模块PyTorch Implementation Collection of Attention Module and Plug&Play Module
Stars: ✭ 54 (-61.43%)
Mutual labels:  attention-model
SAE-NAD
The implementation of "Point-of-Interest Recommendation: Exploiting Self-Attentive Autoencoders with Neighbor-Aware Influence"
Stars: ✭ 48 (-65.71%)
Mutual labels:  attention-model
Attention Gated Networks
Use of Attention Gates in a Convolutional Neural Network / Medical Image Classification and Segmentation
Stars: ✭ 1,237 (+783.57%)
Mutual labels:  attention-model
attention-mechanism-keras
attention mechanism in keras, like Dense and RNN...
Stars: ✭ 19 (-86.43%)
Mutual labels:  attention-model
Reading comprehension tf
Machine Reading Comprehension in Tensorflow
Stars: ✭ 37 (-73.57%)
Mutual labels:  attention-model
Image Caption Generator
A neural network to generate captions for an image using CNN and RNN with BEAM Search.
Stars: ✭ 126 (-10%)
Mutual labels:  attention-model
Transformer image caption
Image Captioning based on Bottom-Up and Top-Down Attention model
Stars: ✭ 94 (-32.86%)
Mutual labels:  attention-model
Deepattention
Deep Visual Attention Prediction (TIP18)
Stars: ✭ 65 (-53.57%)
Mutual labels:  attention-model

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}
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].