SPARQLing Database Queries from Intermediate Question Decompositions

This repo is the implementation of the following paper:

SPARQLing Database Queries from Intermediate Question Decompositions
Irina Saparina and Anton Osokin
To appear in proceedings of EMNLP’21


This software is released under the MIT license, which means that you can use the code in any way you want.


Conda env with pytorch 1.9

Create conda env with pytorch 1.9 and many other packages upgraded: conda_env_with_pytorch1.9.yaml:

conda env create -n env-torch1.9 -f conda_env_with_pytorch1.9.yaml
conda activate env-torch1.9

Download some nltk resourses, Bert and GraPPa:

python -c "import nltk;'stopwords');'punkt')"
python -c "from transformers import AutoModel; AutoModel.from_pretrained('bert-large-uncased-whole-word-masking'); AutoModel.from_pretrained('Salesforce/grappa_large_jnt')"

mkdir -p third_party && \
cd third_party && \
curl | jar xv


We currently provide both Spider and Break inside our repos. Note that datasets differ from original ones as we fixed some annotation errors. Download databases:

bash ./utils/ 11icoH_EA-NYb0OrPTdehRWm_d7-DIzWX
unzip -d spider_temp
cp -r spider_temp/spider/database ./data/spider
rm -rf spider_temp/
python ./qdmr2sparql/ --spider_path ./data/spider

To reproduce our annotation procedure see qdmr2sparql/

For testing qdmr2sparql translator run qdmr2sparql/


Every experiment has its own config file in text2qdmr/configs/experiments. The pipeline of working with any model version or dataset is:

python preprocess experiment_config_file  # preprocess the data
python train experiment_config_file       # train a model
python eval experiment_config_file        # evaluate the results

# multiple GPUs on one machine:
export NGPUS=4 # set $NGPUS manually
python -m torch.distributed.launch --nproc_per_node=$NGPUS --use_env --master_port `./utils/` train experiment_config_file

Note that preprocessing and evaluation use execution and take some time. To speed up the evaluation, you can install Virtuoso server (see qdmr2sparql/

Checkpoints and samples

The dev and test examples of model output are model_samples/.

Checkpoints of our best models:

Model name Dev Test Link
grappa-aug 80.4 62.0
grappa-full_break 74.6 62.6


Text2qdmr module is based on RAT-SQL code, the implementation of ACL’20 paper “RAT-SQL: Relation-Aware Schema Encoding and Linking for Text-to-SQL Parsers” by Wang et al.

Spider dataset was proposed by Yi et al. in EMNLP’18 paper “Spider: A Large-Scale Human-Labeled Dataset for Complex and Cross-Domain Semantic Parsing and Text-to-SQL Task”.

was proposed by Wolfson et al. in TACL paper “Break It Down: A Question Understanding Benchmark”.


GitHub - yandex-research/sparqling-queries: This repo in the implementation of EMNLP′21 paper “SPARQLing Database Queries from Intermediate Question Decompositions” by Irina Saparina, Anton Osokin
This repo in the implementation of EMNLP'21 paper "SPARQLing Database Queries from Intermediate Question Decompositions" by Irina Saparina, Anton Osokin - GitHub - yandex-research/spa...