Skip to content
/ NSpM Public
forked from LiberAI/NSpM

🤖 Neural SPARQL Machines for Knowledge Graph Question Answering.

License

Notifications You must be signed in to change notification settings

weiyang22/NSpM

 
 

Repository files navigation

🤖 Neural SPARQL Machines

Python 3.7

A LSTM-based Machine Translation Approach for Question Answering over Knowledge Graphs.

What does a NSpM do?

Code

Install git-lfs in your machine, then fetch all files and submodules.

git lfs fetch
git lfs checkout
git submodule update --init

Python setup

pip install -r requirements.txt

The Generator module

Pre-generated data

You can extract pre-generated data from data/monument_300.zip and data/monument_600.zip in folders having the respective names.

Manual Generation (Alternative to using pre-generated data)

The template used in the paper can be found in a file such as annotations_monument.tsv. data/monument_300 will be the ID of the working dataset used throughout the tutorial. To generate the training data, launch the following command.

mkdir data/monument_300
python generator.py --templates data/annotations_monument.csv --output data/monument_300

Launch the command to build the vocabularies for the two languages (i.e., English and SPARQL) and split into train, dev, and test sets.

./generate.sh data/monument_300

The Learner module

Now go back to the initial directory and launch train.sh to train the model. The first parameter is the prefix of the data directory and the second parameter is the number of training epochs.

./train.sh data/monument_300 12000

This command will create a model directory called data/monument_300_model.

The Interpreter module

Predict the SPARQL query for a given question with a given model.

./ask.sh data/monument_300 "where is edward vii monument located in?"

Unit tests

Tests can be run, but exclusively within the root directory.

py.test *.py

Use cases & integrations

Publications

SPARQL as a Foreign Language (2017)

@inproceedings{soru-marx-2017,
    author = "Tommaso Soru and Edgard Marx and Diego Moussallem and Gustavo Publio and Andr\'e Valdestilhas and Diego Esteves and Ciro Baron Neto",
    title = "{SPARQL} as a Foreign Language",
    year = "2017",
    journal = "13th International Conference on Semantic Systems (SEMANTiCS 2017) - Posters and Demos",
    url = "https://arxiv.org/abs/1708.07624",
}

Neural Machine Translation for Query Construction and Composition (2018)

@inproceedings{soru-marx-nampi2018,
    author = "Tommaso Soru and Edgard Marx and Andr\'e Valdestilhas and Diego Esteves and Diego Moussallem and Gustavo Publio",
    title = "Neural Machine Translation for Query Construction and Composition",
    year = "2018",
    journal = "ICML Workshop on Neural Abstract Machines \& Program Induction (NAMPI v2)",
    url = "https://arxiv.org/abs/1806.10478",
}

Exploring Sequence-to-Sequence Models for SPARQL Pattern Composition (2020)

@inproceedings{panchbhai-2020,
    author = "Anand Panchbhai and Tommaso Soru and Edgard Marx",
    title = "Exploring Sequence-to-Sequence Models for {SPARQL} Pattern Composition",
    year = "2020",
    journal = "First Indo-American Knowledge Graph and Semantic Web Conference",
    url = "https://arxiv.org/abs/2010.10900",
}

Liber AI on Medium (2020)

Contact

Questions?

Follow us

Liber AI logo

About

🤖 Neural SPARQL Machines for Knowledge Graph Question Answering.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 97.9%
  • Shell 1.3%
  • C++ 0.8%