Coder Social home page Coder Social logo

embedkgqa's Introduction

UPDATE: This repository is no longer being maintained. Checkpoints/data might not be available.

EmbedKGQA

This is the code for our ACL 2020 paper Improving Multi-hop Question Answering over Knowledge Graphs using Knowledge Base Embeddings (Slides)

UPDATE: Code for relation matching has been added. Please see the Readme for details on how to use it.

Instructions

Data and pre-trained models

In order to run the code, first download data.zip and pretrained_model.zip from here. Unzip these files in the main directory.

UPDATE: There was an issue with the WebQSP test set containing 43 fewer questions (issue #86). This has been fixed, and the file qa_test_webqsp_fixed.txt should be placed in the directory data/QA_data/WebQuestionsSP

MetaQA

Change to directory ./KGQA/LSTM. Following is an example command to run the QA training code

python3 main.py --mode train --relation_dim 200 --hidden_dim 256 \
--gpu 2 --freeze 0 --batch_size 128 --validate_every 5 --hops 2 --lr 0.0005 --entdrop 0.1 --reldrop 0.2  --scoredrop 0.2 \
--decay 1.0 --model ComplEx --patience 5 --ls 0.0 --kg_type half

WebQuestionsSP

Change to directory ./KGQA/RoBERTa. Following is an example command to run the QA training code

python3 main.py --mode train --relation_dim 200 --do_batch_norm 1 \
--gpu 2 --freeze 1 --batch_size 16 --validate_every 10 --hops webqsp_half --lr 0.00002 --entdrop 0.0 --reldrop 0.0 --scoredrop 0.0 \
--decay 1.0 --model ComplEx --patience 20 --ls 0.05 --l3_reg 0.001 --nb_epochs 200 --outfile half_fbwq

Note: This will run the code in vanilla setting without relation matching, relation matching will have to be done separately. Details on relation matching can be found here. The numbers in Table 3 are after relation matching.

Also, please note that this implementation uses embeddings created through libkge (https://github.com/uma-pi1/kge). This is a very helpful library and I would suggest that you train embeddings through it since it supports sparse embeddings + shared negative sampling to speed up learning for large KGs like Freebase.

Dataset creation

MetaQA

KG dataset

There are 2 datasets: MetaQA_full and MetaQA_half. Full dataset contains the original kb.txt as train.txt with duplicate triples removed. Half contains only 50% of the triples (randomly selected without replacement).

There are some lines like 'entity NOOP entity' in the train.txt for half dataset. This is because when removing the triples, all triples for that entity were removed, hence any KG embedding implementation would not find any embedding vector for them using the train.txt file. By including such 'NOOP' triples we are not including any additional information regarding them from the KG, it is there just so that we can directly use any embedding implementation to generate some random vector for them.

QA Dataset

There are 5 files for each dataset (1, 2 and 3 hop)

  • qa_train_{n}hop_train.txt
  • qa_train_{n}hop_train_half.txt
  • qa_train_{n}hop_train_old.txt
  • qa_dev_{n}hop.txt
  • qa_test_{n}hop.txt

Out of these, qa_dev, qa_test and qa_train_{n}hop_old are exactly the same as the MetaQA original dev, test and train files respectively.

For qa_train_{n}hop_train and qa_train_{n}hop_train_half, we have added triple (h, r, t) in the form of (head entity, question, answer). This is to prevent the model from 'forgetting' the entity embeddings when it is training the QA model using the QA dataset. qa_train.txt contains all triples, while qa_train_half.txt contains only triples from MetaQA_half.

WebQuestionsSP

KG dataset

There are 2 datasets: fbwq_full and fbwq_half

Creating fbwq_full: We restrict the KB to be a subset of Freebase which contains all facts that are within 2-hops of any entity mentioned in the questions of WebQuestionsSP. We further prune it to contain only those relations that are mentioned in the dataset. This smaller KB has 1.8 million entities and 5.7 million triples.

Creating fbwq_half: We randomly sample 50% of the edges from fbwq_full.

QA Dataset

Same as the original WebQuestionsSP QA dataset.

How to cite

If you used our work or found it helpful, please use the following citation:

@inproceedings{saxena2020improving,
  title={Improving multi-hop question answering over knowledge graphs using knowledge base embeddings},
  author={Saxena, Apoorv and Tripathi, Aditay and Talukdar, Partha},
  booktitle={Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics},
  pages={4498--4507},
  year={2020}
}

embedkgqa's People

Contributors

albert-jin avatar apoorvumang avatar iiscaditaytripathi avatar parthatalukdar avatar raresraf 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  avatar  avatar

embedkgqa's Issues

WebQuestionsSP code

When will the code for the 'WebQuestionsSP' dataset be updated?

Best Regards

experiment

Did the experiment on MetaQA in the paper use LSTM?

What are valid.txt and test.txt for KG data?

You've described that "Full dataset contains the original kb.txt as train.txt with duplicate triples removed", but what are valid.txt and test.txt at the same directory? Does KGE need to be verified and tested?

Do you use RoBERTa for only fbwq but not MetaQA?

Hi,

When reading your code I found there is not a part in KGQA/LSTM that you load the transformer and use the pre-trained embeddings for sentences, as what you have done in KGQA/RoBERTa. Is that true, and why?

Best,
Shuang

eval the best model

How to eval the best model on the test set? Could you please give me the command?

Other embeddings except for ComplEx?

Hi, thanks for providing your code!

I was wondering whether you have ever tried any other embeddings like RESCAL like you included in your 'model.py'.
Did you select 'ComplEx' because it achieves the best performance?

Can you provide your websqp kg embedding file?

I found your websqp kg embedding file is None, can you supply it? When I run your training embedding code with your KG (relevant your websqp ) . I found there is an error, CUDA out of memory
Can you suply the relevent embedding file, just like metaqa??

Download data.zip which is destroyed

I clone the project, but the files in it seems not work. In detail, it seems that the data.zip has been destroyed, and can not be open. Could you please help me solve the problem?

question about 3-hop on full KG

I have run the LSTM code for 3-hop on full KG settings, but I got a 0.7271963009667928 score. Do I need to change some parameters when I run the code for 3-hop?
Thanks!

RelScore

Hello Dr. Apoorv,
According to your email, RelScore does not have a gradient. the scoring function S(r,q) has a gradient and that is trained separately. And RelScore is only used in valid and testing phase. I wanna know some details, do you mean S(r,q) induces a part of loss during training or it is trained after all training epoches?

No requirement.txt

Hi,Man
I want to know the exactly environment the code was running !
For exmple,pytorch version? python version 3.4 3.5 or 3.6 ? Developing environment :Ubuntu or Mac ?or Windows ?
Please update a detailed description of the running environment for the code replay ~ Thanks a lot !@apoorvumang

relation maching

i found text "relation matching will have to be done separately."

how can i run relation matching?

I still get 0.677736 in 3hop MetaQA full-KG

I used your command, your data, KG embedding and the bn weights and I still get 0.678. Can you provided the log file or other advice to help me rise the accuracy?

python main.py --mode train --relation_dim 200 --hidden_dim 256
--gpu 2 --freeze 0 --batch_size 128 --validate_every 5 --hops 3 --lr 0.0005 --entdrop 0.1 --reldrop 0.2 --scoredrop 0.2
--decay 1.0 --model ComplEx --patience 5 --ls 0.0 --kg_type full

ps: I have used the LSTM

How to find candidate answers

Hi, thank you for sharing the source code. Could you please explain how does the model find all candidate answers in answer selection module? Thank you.

eval function

I can't find the eval function in roBERTa main.py Can I get this function?

question_embedding in your model

Why you use states[0] to compute the question embedding in a batch_size? the size of states[0] is [batch_size, embedding_dim], can you explain what's the meaning about states[0] ? I think question_embedding should be state not state[0]. Can you help me?

def getQuestionEmbedding(self, question_tokenized, attention_mask):
    roberta_last_hidden_states = self.roberta_model(question_tokenized, attention_mask=attention_mask)[0]
    states = roberta_last_hidden_states.transpose(1,0)#  torch.Size([64, 128, 768])
    cls_embedding = states[0]# torch.Size([128, 768])
    question_embedding = cls_embedding

issues in 2hop/3hop QA

I've trained a 200-dim ComplEx embedding for the knowledge graph of MetaQA.
As the best hyperparameters are not given, I directly use the default parameters.
The EmbedKGQA model works well in 1hop QA and gets 0.957 accuracy which is not too far from the value 0.975 given in the paper.
However when I tried 2hop and 3hop QA, I got 0.09 and 0.326 respectively. It seems to be more than just a issue of hyperparameters.

I find that in the test set of 2hop and 3hop MetaQA, most triples (topic entity, some relation, answer entity) don't appear in the knowledge graph kb.txt ( 4.97MB ), especially 2hop dataset ( 14872 QAs' in test set ). In 2hop set there are only 8 questions which have link between topic entity and answer entity in kb.txt. Also, the overlap (topic entity, some question, answer entity) between test and train set is only a small fraction of test set (less than a half).
Am I using the wrong dataset? Did I miss some important details?

This situation is similar with that described in Section 5.4: there is no link between head entity and answer entity. I dont understand how it could be possible that got 0.299 accuracy in 1hop( Table 4 in your paper) but 0.988 in 2hop( Table 2 in your paper).

What dose "positive_head" mean in line 197 in "KGQA/LSTM/main.py"

for i_batch, a in enumerate(loader):
model.zero_grad()
question = a[0].to(device)
sent_len = a[1].to(device)
positive_head = a[2].to(device)
positive_tail = a[3].to(device)
Since question represents the embedding of questions, sent_len represents the length of questions, positive_tail represents the lables(answers) of questions, what dose "positive_head" represent?

I still get 0.49 in metaQA full KG-hop3.

I still get 0.49 in metaQA full KG-hop3. can you provided the whole project (KG embedding, command), or other advice? 0.49 is too low, I do not know what's wrong with it? I used your command, your data. I hop you can provided the relevant project again or other advice to help me rise the accuracy.

Independent eval function

Add a way to eval a pretrained model, independent from training. This will require auto-saving of a model.

how to run it?

how to run knowledge graph embedding?
how to run KBQA model?

hop1 results in metaQA

Sorry to bother you, I used command you provided in github (metaQA hop1 full-KG), I just get 0.93, while your paper is 0.97, there is a large gap, on the other hand, I found your paper uses ROBERT to obtian the question representation, while in your code, you use BI-LSTM. Can you explain these two questions? expecially one, why I get 0.93 by your parameter?
your command:
python3 main.py --mode train --relation_dim 200 --hidden_dim 256
--gpu 2 --freeze 0 --batch_size 128 --validate_every 5 --hops 2 --lr 0.0005 --entdrop 0.1 --reldrop 0.2 --scoredrop 0.2
--decay 1.0 --model ComplEx --patience 5 --ls 0.0 --kg_type half.
If this command is not the command of metaQA hop1 full-KG, can you supply the all command about (hop1,hop2, hop3) in full KG metaQA, WebQuestionsSP and all command about (hop1,hop2, hop3) in half KG, at last, the training command about how to get entity embedding in these two KGs, two half KGs.
Thanks! I hope your reply can help me!!!

How to get KG embeddings for custom KG

Hi,

We have build KG by extracting entities and relationship between entity from PDF documents. But out KG is not so big, we have around 5k nodes.

Now we wanted to use EmbedKGQA source code to build Natural Language question on custom KG.

I have below 2 questions,

  1. How do i convert my custom KG to embedings
  2. Our KG is not big, do you think still i can use this method to answer natural language questions.

Thanks

The GPU used for training will be as slow as the CPU as long as there are other programs running?

The program only takes up more than 1G of GPU memory, which is very fast when run alone. However, if there are other programs running on this GPU, it will also take up more than 1G of GPU memory, but the speed will become as slow as the CPU, why? If there are other programs that use the GPU's other memory while the program running, the speed will suddenly become very, very slow (about a few hundredths of a percent). What's going on?

do_batch_norm in webQSP

Batch norm greatly improved training speed for MetaQA. Could you explain why you set do_batch_norm to 0 for WebQSP (lead to more training epoches and patience)? What if we set it to 1? And how much can RelScore improve the results?

ModuleNotFoundError: No module named '_Box2D'

In KGQA/RoBERTa/main.py you import kge module. Although I've installed the kge module from pip, it shows "ModuleNotFoundError: No module named '_Box2D'", where there's even no even the same situation on google. Have you encountered it and how did you overcome?

size of tensor mismatch in webqsp_full

image
The command i used is :
'python main.py --mode train --relation_dim 200 --do_batch_norm 0
--gpu 0 --freeze 1 --batch_size 16 --validate_every 10 --hops webqsp_full --lr 0.00002 --entdrop 0.0 --reldrop 0.0 --scoredrop 0.0
--decay 1.0 --model ComplEx --patience 20 --ls 0.0 --l3_reg 0.001 --nb_epochs 200 --outfile full_fbwq'

relation matching

Thanks for opening source !
I have read the code, but I did not find the relation matching module. The current prediction logic seems to be predicting scores for all entities of KG. Will you provide the code for relation matching, because I am not sure how is the shortest path between head entity and candidate answer defined.

Rotate3

Dear authors,
In your code, the model rotate3 refers to Rotate which from "ROTATE: KNOWLEDGE GRAPH EMBEDDING BY RELA- TIONAL ROTATION IN COMPLEX SPACE"?

What's the result about half KG in metaQA?

By using your code without your relation matching in half KG metaQA, I found the result is 0.68 in hop1, 0.51 in hop2, 0.45 in hop3, there is a big gap with your paper report (even without relation matching, relation matching is used to solve: the big distance between topic entity and answers). I do not undertand how to achieve your relation matching in half KG, can you report your result without relation matching? By your describtion, it's not easy to realise the relation matching model.

Consultations on this paper

Hi, I found this paper very enlightening, taking full advantage of the nature of knowledge graph embedding to complete multi-hop QA.
However, I have some doubts while reading the paper on ACL 2020.

How are the head entities in a natural language question get extracted, did this paper assumes that there is only one head entity in the question?

Thanks.

KG embedding

Could you provide the setting of KG embedding modulo? i.e. how can I get E.py&R.py with your train_embedding code.
I cannot train it properly with default setting.

WebQuestionsSP Data

Hello
Thanks for the material update.
However, it is not possible to decompress data.zip
I need 'WebQuestionsSP Data' in data.zip ​​for the experiment
Could you please check?

Relation Maching

Can you see that the'WebQuestionsSP' executable code is running, but the'relation maching' code cannot be found?

relation score

When would you like to share the codeof relation score?

Best Wishes!

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.