SPBERT: an Efficient Pre-training BERT on SPARQL Queries for Question Answering over Knowledge Graphs

Hieu Tran, Long Phan, James T. Anibal, Binh T. Nguyen, Truong-Son Nguyen

Abstract

Knowledge-Based Question Answering (KBQA) systems bridge the gap between natural language (NL) and structured Knowledge Graphs (KGs). However, standard language models often struggle with the precise syntax and complex entity relationships of query languages like SPARQL. This paper introduces SPBERT, a transformer-based model pre-trained specifically on a large corpus of SPARQL queries. By integrating a novel Word Structural Objective (WSO) with standard Masked Language Modeling (MLM), SPBERT learns to navigate the structural constraints of SPARQL. Our evaluation shows that SPBERT sets new state-of-the-art benchmarks for both NL-to-SPARQL translation and SPARQL-to-NL answer verbalization.

Introduction

The primary goal of KBQA is to allow users to interact with vast repositories of structured data using natural language. This process typically involves two critical translation steps: Query Construction, where an NL question is converted into a SPARQL query, and Answer Verbalization, where the query results are translated back into a human-readable format.

Traditional approaches to these tasks often rely on word embeddings that require massive vocabularies to accommodate every possible entity in a Knowledge Graph, leading to computational inefficiency. Furthermore, general-purpose models like BERT, while proficient in natural language, lack the specialized training required to handle the rigid syntax and schema-specific structures of SPARQL. SPBERT addresses these limitations by providing a pre-trained foundation specifically tailored for structured query understanding.

Methodology

The authors adapt the BERT_BASE architecture to the domain of structured queries through specialized pre-training data and objectives.

Pre-training Data and Tokenization

The model was pre-trained on 6.8 million real-world SPARQL query logs extracted from DBpedia. To handle the diverse range of entities and properties without an oversized vocabulary, the authors utilized the standard cased BERT WordPiece tokenizer. This choice allows the model to decompose complex URIs and camelCase strings into manageable subword units, ensuring high coverage and efficiency.

Example of how original SPARQL queries are encoded for processing.

Pre-training Objectives

SPBERT employs two primary training objectives to master the nuances of structured queries:

  1. Masked Language Modeling (MLM): Following the standard BERT protocol, 15% of tokens are masked, and the model is tasked with predicting them based on context.
  2. Word Structural Objective (WSO): To account for the strict sequential nature of SPARQL, the authors introduced WSO. In this objective, 10% of n-grams within a query are randomly permuted. The model must then predict the original, correct sequence. This forces the model to learn the underlying syntax and structural dependencies of the query language.
The SPBERT architecture illustrating the combination of Masked Language Modeling and the Word Structural Objective.

Fine-tuning Architecture

For downstream KBQA tasks, SPBERT is integrated into a Transformer-based encoder-decoder framework:

  • NL to SPARQL (Query Construction): A BERT2SPBERT configuration is used, where the encoder is initialized with standard BERT and the decoder with SPBERT.
  • SPARQL to NL (Answer Verbalization): A SPBERT2BERT configuration is used, reversing the roles to leverage SPBERT's query understanding for natural language generation.

Experimental Results

SPBERT demonstrated significant performance gains over existing baselines in both translation directions across several benchmark datasets, including QALD-9, LC-QuAD, and VQuAnDa.

SPARQL Query Construction

In the NL-to-SPARQL task, the BERT2SPBERT model achieved a BLEU score of 69.03% on the LC-QuAD dataset, a substantial improvement over the previous state-of-the-art of approximately 59%. On the QALD-9 dataset, it reached 37.58% BLEU. These results highlight the benefit of the Word Structural Objective in capturing the nuances of query syntax.

Answer Verbalization

For the SPARQL-to-NL task, the SPBERT2BERT pipeline achieved a 42.39% BLEU score on the VQuAnDa test set when entities were preserved. This performance far exceeded traditional RNN and CNN-based models, which typically scored between 21% and 32%. The model's ability to utilize entity context during verbalization suggests it learns more than just templates; it understands the relationships between specific KG components.

Conclusion and Future Work

SPBERT represents a significant step forward in specialized pre-training for KBQA. By combining MLM with a structural permutation objective, the model effectively bridges the gap between natural and structured languages.

Despite its success, some limitations remain. The random initialization of cross-attention weights in the encoder-decoder setup may act as a performance bottleneck. Additionally, while 6.8 million queries is a significant dataset, it represents only a fraction of the information available in large-scale Knowledge Graphs. Future research will focus on expanding the pre-training corpus and developing a unified end-to-end architecture to handle both translation tasks within a single model.

Summary updated

Abstract

Knowledge Graph is becoming increasingly popular and necessary during the past years. In order to address the lack of structural information of SPARQL query language, we propose SPBERT, a transformer-based language model pre-trained on massive SPARQL query logs. By incorporating masked language modeling objectives and the word structural objective, SPBERT can learn general-purpose representations in both natural language and SPARQL query language. We investigate how SPBERT and encoder-decoder architecture can be adapted for Knowledge-based QA corpora. We conduct exhaustive experiments on two additional tasks, including SPARQL Query Construction and Answer Verbalization Generation. The experimental results show that SPBERT can obtain promising results, achieving state-of-the-art BLEU scores on several of these tasks.
BibTeX
@inproceedings{tran2021spbert,
  author = {Hieu Tran and Long Phan and James T. Anibal and Binh T. Nguyen and Truong-Son Nguyen},
  title = {{SPBERT: an Efficient Pre-training BERT on SPARQL Queries for Question Answering over Knowledge Graphs}},
  booktitle = {ICONIP},
  year = {2021},
  url = {https://openreview.net/forum?id=TAyuZrHPXWD},
}
Figure