Giter VIP home page Giter VIP logo

bamnet's Introduction

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}
}

bamnet's People

Contributors

hugochan avatar maxbachmann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bamnet's Issues

RuntimeError: CuDNN error: CUDNN_STATUS_INTERNAL_ERROR

when i run train_entnet.py, i met a problem :

Traceback (most recent call last):
  File "train_entnet.py", line 43, in <module>
    [valid_memories, valid_queries, valid_query_lengths], valid_ent_inds)
  File "/home/jzw/NLP/kbqa/BAMnet/src/core/bamnet/entnet.py", line 96, in train
    train_loss += self.train_step(batch_xs, batch_ys) / num_batches
  File "/home/jzw/NLP/kbqa/BAMnet/src/core/bamnet/entnet.py", line 174, in train_step
    loss.backward()
  File "/home/jzw/python3/lib/python3.6/site-packages/torch/tensor.py", line 93, in backward
    torch.autograd.backward(self, gradient, retain_graph, create_graph)
  File "/home/jzw/python3/lib/python3.6/site-packages/torch/autograd/__init__.py", line 90, in backward
    allow_unreachable=True)  # allow_unreachable flag
RuntimeError: CuDNN error: CUDNN_STATUS_INTERNAL_ERROR

i use torch 0.4.1, cuda 8, cudnn 7, how can i fix it?
Thank you.

IDs

Hi! just trying to transfer your model to another dataset and KB, for the file entity2id.json/ entityType2id.json/ relation2id.json, is there any restrictions on assigining their IDs? Or just assigining a distinct ID to each relation/entity is OK?

Inquiries about the code

Hi, I just read your paper and find it very interesting. I want to try running the code but it seems you haven't uploaded it yet. May I know if you have any update plan?

freebaseKeyCands is the entity linking results by using Freebase Search API?

Hello! I download your dataste. The train/test/valid files (raw_train.json/raw_valid.json/raw_test.json) both contain the "freebaseKeyCands" data. Where does the data "freebaseKeyCands" come from? It is the entity linking results by using Freebase Search API ? Could you provide the entity linking results by using Freebase Search API for me ? Thanks a lot.

About the freebase_full.json file

You gave a link of your research data. I downloaded it and I saw a file called freebase_full.json. In this file, each element has its neighbors and paths directing to them. I checked the freebase dump which offered by google with sparql language, the paths that each element connects in your json file are not the all. Which means there are more paths should be connected by each element in freebase_full.json. I’m curious about how did you decide which path or neighbor should be added in each record? How did you build freebase_full.json file?

All the best, appreciate!
Siqi Lai

onedrive

Hello, I can't visit onedrive website. Can you provide data and models in other ways, such as Google drive

Freebase .json.gz

Hi,

Thank you for your great work. I'm trying to run your code on FreebaseQA. Could you provide the freebase key file?

Test on individual questions

Hello! Is there any support for testing the model on new questions after training it? If not, how would you recommend going about building that functionality? Ideally I would like to deploy the model as an API.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.