<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Ranking Approach to Monolingual Question Answering over Knowledge Graphs</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Nikita Baramiia</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Alina Rogulina</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Sergey Petrakov</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Valerii Kornilov</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Anton Razzhigaev</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Nikita.Baramiia</institution>
          ,
          <addr-line>Alina.Rogulina, Sergey.Petrakov, Valerii.Kornilov, Anton.Razzhigaev</addr-line>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Skolkovo Institute of Science and Technology (Skoltech) Bolshoy Boulevard 30, bld. 1</institution>
          ,
          <addr-line>121205, Moscow</addr-line>
          ,
          <country country="RU">Russia</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>In this paper we describe our solution to the task 1 of Question Answering over Linked Data (QALD) challenge: multilingual QALD over Wikidata. We propose the method where we learn to rank items and properties to find suitable SPARQL query. With our approach we achieve 0.4281 Macro F1-score in QALD system.</p>
      </abstract>
      <kwd-group>
        <kwd>Question answering</kwd>
        <kwd>transformers</kwd>
        <kwd>approximate nearest neighbors</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <sec id="sec-1-1">
        <title>Question Answering (QA) is one of rapidly developed fields in natural language</title>
        <p>processing (NLP), covering many diferent problems from search engines to
dialogue systems. One of the most common tasks is to answer a question by making
a query to an RDF data repository (an RDF dataset is the unit that is queried
by a SPARQL query). In our case, we should train the model to make right</p>
      </sec>
      <sec id="sec-1-2">
        <title>SPARQL queries to retrieve answers from Wikidata.</title>
      </sec>
    </sec>
    <sec id="sec-2">
      <title>Data description</title>
      <sec id="sec-2-1">
        <title>In this challenge Wikidata was chosen as the main RDF dataset for answers</title>
        <p>search. Our preprocessing procedure of the training data consists of the parsing
queries which have the form shown in the example 1. As a result, our train data
is reduced from 412 to 145 samples with items (Q) and properties (P).</p>
      </sec>
      <sec id="sec-2-2">
        <title>We also have embeddings for items (4 106 847) and properties (5 927) from</title>
        <sec id="sec-2-2-1">
          <title>Wikidata1. Then SPARQL queries are generated from this pool.</title>
          <p>We use only one language (English) for all samples, both train and test. The
choice of this approach is justified by the fact that each question is represented
by its own set of languages necessarily included English.
1 These embeddings were prepared via TransE algorithm from PyTorch-BigGraph
(PGD) system from Facebook
{
}
"id": "99",
"question": [...],
"query": {
"sparql": "SELECT DISTINCT
?o1 WHERE {
&lt;http://www.wikidata.org/
entity/Q23337&gt;
&lt;http://www.wikidata.org/
prop/direct/P421&gt; ?o1 . }"
},
"answers": [...]</p>
        </sec>
      </sec>
      <sec id="sec-2-3">
        <title>Listing 1: QALD JSON format</title>
        <p>3</p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>Description of the approach</title>
      <sec id="sec-3-1">
        <title>Our approach consists of several parts which we describe step-by-step in the</title>
      </sec>
      <sec id="sec-3-2">
        <title>Sections 3.1, 3.2, 3.3. Then we discuss training process of the proposed model and its usage on inference step.</title>
        <p>3.1</p>
        <p>Learning to rank
Our solution is closely connected with a task of ranking: in traditional statement
we want our model to give a score for each observation according to which we can
sort them from the most relevant to the least. Our core idea is that our model
predicts embeddings of Q and P which are as close as possible to the relevant
ones (connected with correct query) and as far as possible to the others. We use
triplet margin loss and transformer language model BART for this purpose.
3.2</p>
        <p>BART model</p>
        <sec id="sec-3-2-1">
          <title>We use pre-trained BART [3] model from Hugging Face Hub2. Basically, BART</title>
          <p>is a transformer sequence-to-sequence model with a bidirectional encoder and an
autoregressive decoder. This model performs well in such tasks as summarizing,
translation, classification, and what is especially important for us, a task of
answering a question (after fine-tuning). For this reason, BART is the basis for
our research.</p>
        </sec>
      </sec>
      <sec id="sec-3-3">
        <title>The authors of [5] demonstrate that BART and RoBERTa [4] are the best models according to F1-score at the task of extractive question answering. Since our target metric is F1-score it is additional argument to work with these models.</title>
        <p>2 https://huggingface.co/facebook/bart-base</p>
      </sec>
      <sec id="sec-3-4">
        <title>We compare the performance of RoBERTa and BART and we do not receive any</title>
        <p>improvements from RoBERTa, that is why we concentrate on BART.</p>
      </sec>
      <sec id="sec-3-5">
        <title>Moreover, we compare BART model to other models like DistilBERT [6], and</title>
        <p>
          even with XLM-RoBERTa [
          <xref ref-type="bibr" rid="ref1">1</xref>
          ]. Also, we conducted experiments with
multilingual BART, BERT, multilingual BERT, and multilingual XLM-RoBERTa. The
comparison of DistilBERT and BART shows that BART has lower loss within
all process of training. Theoretically, DistilBERT has faster inference, however,
in practice, duration of training did not difer a lot.
        </p>
      </sec>
      <sec id="sec-3-6">
        <title>We made one modification of the model to adapt it to our task: we av</title>
        <p>erage last hidden state embeddings getting output final embedding with size
(batch size, 768), to which we apply a linear map R768 → RQ embed size+P embed size.</p>
      </sec>
      <sec id="sec-3-7">
        <title>This final model was fine-tuned to predict embeddings for Q and P. In our approach we use batch size equals to 128.</title>
        <p>3.3</p>
        <p>Approximate neighbours search with ScaNN</p>
      </sec>
      <sec id="sec-3-8">
        <title>Scalable Nearest Neighbors (ScaNN) – one of the latest methods for eficient</title>
        <p>
          neighbours search achieved by using the new score-aware quantization loss
function proposed in the paper [
          <xref ref-type="bibr" rid="ref2">2</xref>
          ]. It lets the authors to achieve state-of-the-art
results in most of benchmarks3: on Fig. 1 you can see one of prime examples on
the glove-100-angular dataset.
        </p>
        <p>In the Section 3.2 we explain how we get embeddings for P and Q, but with
high probability we will never get exact matches, so the idea is to find nearest
ones from the prepared pool of Q-items and P-properties via ScaNN approach
with the dot product distance metric. In the Section 1 we describe how it works
during training and model inference.
3 http://ann-benchmarks.com</p>
        <p>Train and inference procedures</p>
      </sec>
      <sec id="sec-3-9">
        <title>Training process is presented in Algorithm 1 below:</title>
      </sec>
      <sec id="sec-3-10">
        <title>Algorithm 1 Training process</title>
        <p>Require: pool of Q and P, samples, model fw
for epoch in num of epochs do
shufled samples ← shuf f le(samples)
batches ← split(shufled samples)
for (sentences batch, queries batch) in batches do
queries anchor = fw(sentences batch)
queries positive = true queries values
queries negative = nearest to anchor false queries
L = triplet loss(queries anchor, queries positive, queries negative)
w ← w − ∇ wL
end for
end for=0</p>
      </sec>
      <sec id="sec-3-11">
        <title>It is a typical metric learning procedure with hard negative mining strategy.</title>
      </sec>
      <sec id="sec-3-12">
        <title>Within training procedure we use Adam optimizer. There is a widespread</title>
        <p>practice of changing learning rate using scheduler since it is worth changing
learning rate value during training. The main idea is to decrease it while training
because we need smaller steps of the gradient when we come closer to optimum.</p>
      </sec>
      <sec id="sec-3-13">
        <title>In our case, we implement StepLR with warm-up during the first two epochs,</title>
        <p>initial and minimal learning rates 10− 5, step size 13, gamma 0.9 (every 13 epochs
current learning rate multiplied by 0.9, and it could not be less than 10− 5). Initial
learning rate equals to minimal learning rate since we use warm-up technique.</p>
      </sec>
      <sec id="sec-3-14">
        <title>This mean that first two epochs has minimal learning rate. This is a good practice</title>
        <p>that allows adaptive optimizers such as Adam to better calculate loss function
gradients. Thus, it helps the optimizer to choose a more optimal and stable
direction of optimization. Batch size of the final model equals 128 since it is a
power of 2 and it is big enough to represent data in one iteration.</p>
      </sec>
      <sec id="sec-3-15">
        <title>We additionally use early stopping as a useful method of regularization, which</title>
        <p>prevents overfitting of the model. Also, it gives signicfiant reduction of training
time in case when there is a large number of training epochs. We set the
parameter patience to 6 (if current loss higher than minimal previously achieved loss
within 6 epochs then training stops). Thus, we use only 40 epochs out of 100
originally declared.</p>
      </sec>
      <sec id="sec-3-16">
        <title>Furthermore, we use triplet loss with default margin. It is a good idea to take this type of loss because we want to generate a vector that will be close to the vector of correct answers, and far from the vectors of wrong answers. This is exactly what triple loss does.</title>
      </sec>
      <sec id="sec-3-17">
        <title>In the Algorithm 2 we provide steps for getting response with our model:</title>
      </sec>
      <sec id="sec-3-18">
        <title>Algorithm 2 Inference procedure</title>
        <p>Require: pool of Q and P, trained model fw, test sentence
0: predicted query = fw (test sentence)
0: 3 nearest Qs and Ps = f ind nearest(predicted query)
for Q in 3 nearest Qs and Ps do
for P in 3 nearest Qs and Ps do
if exist query(Q, P) == True then
success = True
return Q, P
else</p>
        <p>success = False
end for
end for
if success == False then</p>
        <p>return None</p>
      </sec>
      <sec id="sec-3-19">
        <title>We decided to consider more than one nearest neighbour (exactly 3) because not all queries are able to get a response from Wikidata, but probably some combinations of the nearest neighbours can. In our opinion, it is better than not to provide the answer at all.</title>
        <p>4</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>Results and discussion</title>
      <sec id="sec-4-1">
        <title>After iterations of our experiments we received that fine-tuned BART with</title>
      </sec>
      <sec id="sec-4-2">
        <title>ScaNN showed the best result. We could reach 0.4281 Macro F1 QALD score.</title>
      </sec>
      <sec id="sec-4-3">
        <title>We achieved this score on 3 millions of embeddings. Additionally, we tried 4 millions of embeddings, however, the results were comparable. Thus, we can claim that results are robust to the number of embeddings.</title>
      </sec>
      <sec id="sec-4-4">
        <title>Speaking about extensions to the multilingual case, it is possible with using</title>
        <p>transformers trained on several languages. Then, the pipeline is the same but we
get num of languages times more data where we have the same answers (queries)
for num of languages samples. Another way is to rotate embeddings: it is a
wellknown method when we train the rotation matrix to translate embeddings from
one language to another. In this case, the main model will be trainable (probably</p>
      </sec>
      <sec id="sec-4-5">
        <title>English variant is the most suitable) and models for other languages will be used as is, without fine-tuning. For the last case we can utilize our trained model and we will need only to train rotation matrices: it is a rough but relatively fast way to get baseline extension for multilingual case.</title>
      </sec>
      <sec id="sec-4-6">
        <title>After the deadline of QALD competition submission we conducted one more experiment to understand the quality of current result. We used only 500 000 embeddings of queries and 2 epochs of train. This leads to increase of quality up to 0.5133.</title>
        <p>Baramiia et al.</p>
      </sec>
    </sec>
    <sec id="sec-5">
      <title>Acknowledgment</title>
      <sec id="sec-5-1">
        <title>We express our deep gratitude to Skoltech NLP Lab headed by Professor Alexan</title>
        <p>der Panchenko for embeddings prepared via TransE algorithm from
PyTorch</p>
      </sec>
      <sec id="sec-5-2">
        <title>BigGraph (PGD) system from Facebook. Also, we thank organizers of the competition for the opportunity to work on this interesting problem and conduct this research Professor Ricardo Usbeck, Xi Yan, QALD and NLIWOD team.</title>
      </sec>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <surname>Conneau</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Khandelwal</surname>
            ,
            <given-names>K.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Goyal</surname>
            ,
            <given-names>N.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Chaudhary</surname>
            ,
            <given-names>V.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Wenzek</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          , Guzma´n,
          <string-name>
            <given-names>F.</given-names>
            ,
            <surname>Grave</surname>
          </string-name>
          ,
          <string-name>
            <given-names>E.</given-names>
            ,
            <surname>Ott</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            ,
            <surname>Zettlemoyer</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L.</given-names>
            ,
            <surname>Stoyanov</surname>
          </string-name>
          ,
          <string-name>
            <surname>V.</surname>
          </string-name>
          :
          <article-title>Unsupervised cross-lingual representation learning at scale</article-title>
          . arXiv preprint arXiv:
          <year>1911</year>
          .
          <volume>02116</volume>
          (
          <year>2019</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Guo</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Sun</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lindgren</surname>
            ,
            <given-names>E.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Geng</surname>
            ,
            <given-names>Q.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Simcha</surname>
            ,
            <given-names>D.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Chern</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Kumar</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          :
          <article-title>Accelerating large-scale inference with anisotropic vector quantization</article-title>
          .
          <source>In: International Conference on Machine Learning</source>
          (
          <year>2020</year>
          ), https://arxiv.org/abs/
          <year>1908</year>
          .10396
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>Lewis</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Liu</surname>
            ,
            <given-names>Y.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Goyal</surname>
            ,
            <given-names>N.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ghazvininejad</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Mohamed</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Levy</surname>
            ,
            <given-names>O.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Stoyanov</surname>
            ,
            <given-names>V.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Zettlemoyer</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          :
          <article-title>Bart: Denoising sequence-to-sequence pre-training for natural language generation, translation, and comprehension</article-title>
          . arXiv preprint arXiv:
          <year>1910</year>
          .
          <volume>13461</volume>
          (
          <year>2019</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <surname>Liu</surname>
            ,
            <given-names>Y.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ott</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Goyal</surname>
            ,
            <given-names>N.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Du</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Joshi</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Chen</surname>
            ,
            <given-names>D.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Levy</surname>
            ,
            <given-names>O.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lewis</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Zettlemoyer</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Stoyanov</surname>
            ,
            <given-names>V.</given-names>
          </string-name>
          :
          <article-title>Roberta: A robustly optimized bert pretraining approach</article-title>
          . arXiv preprint arXiv:
          <year>1907</year>
          .
          <volume>11692</volume>
          (
          <year>2019</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>Pearce</surname>
            ,
            <given-names>K.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Zhan</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Komanduri</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Zhan</surname>
            ,
            <given-names>J.:</given-names>
          </string-name>
          <article-title>A comparative study of transformer-based language models on extractive question answering</article-title>
          .
          <source>arXiv preprint arXiv:2110.03142</source>
          (
          <year>2021</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <surname>Sanh</surname>
            ,
            <given-names>V.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Debut</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Chaumond</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Wolf</surname>
            ,
            <given-names>T.</given-names>
          </string-name>
          :
          <article-title>Distilbert, a distilled version of bert: smaller, faster, cheaper and lighter</article-title>
          . arXiv preprint arXiv:
          <year>1910</year>
          .
          <volume>01108</volume>
          (
          <year>2019</year>
          )
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>