KGMistral: Towards Boosting the Performance of Large Language Models for Question Answering with Knowledge Graph Integration

Authors: mingze  li
haoran  yang
zhaotai  liu
mirza mohtashim alam
ebrahim  norouzi
harald  sack
genet asefa gesese
Venue: KDD_org_2024_Workshop_DL4KG
Published: 2024-06-08 15:25:22

Abstract: In this paper, a novel question-answering (QA) approach named KGMistral is proposed, based on the Retrieval Augmented Generation (RAG) framework. Given the limitations of Large Language Models (LLMs) in generating accurate answers for domains not adequately covered by their training corpus, this work focuses on leveraging external domain-specific Knowledge Graphs (KGs) to enhance the performance of LLMs. Specifically, the study examines the benefits of using information from a KG to improve the QA performance of the Mistral model in the material science and engineering field. Experimental results indicate that KGMistral significantly enhances Mistral’s QA performance.

Main paper: 
 introduction: 
 Large language models (LLMs) pre-trained on large-scale corpora, have demonstrated powerful capabilities in revolutionalizing various natural language processing (NLP) tasks in different domains such as law [1] , medicine [2] , and education [3] . One major area being revolutionized by LLMs is question answering (QA), as these models enable users to ask questions and retrieve answers in natural language [4] . However, LLMs have faced criticism for generating incorrect answers, known as hallucinations, which pose a significant challenge to their reliability [5] . For example, LLMs could generate inaccurate medical diagnoses or treatment recommendations, leading to potentially catastrophic risks [6] .To mitigate these issues, one potential solution is to integrate information from external sources such as domain specific KGs into LLMs. KGs store vast amounts of information in the form of triples, comprising a head entity, a relation, and a tail entity, offering a structured and comprehensive knowledge representation [7] . Domain-specific KGs tailored to particular fields can provide accurate and reliable information, such as the MSE KG [8] in the materials science and engineering domain.This work aims to answer the following research question:• How to improve the QA performance of LLMs, specifically Mistral, by integrating a domain-specific KG?The key contributions of this work are given as follows:• A novel architecture named KGMistral, based on the Retrieval Augmented Generation (RAG) framework, is proposed.• The use of SPARQL queries to retrieve relevant triples (i.e., context) is examined.• A set of experiments is conducted to evaluate KGMistral using competency questions and a KG in the domain of materials science. The results indicate that using domain-specific KGs as external sources in RAG leads to improved QA performance.To the best of our knowledge, this is the first work leveraging the RAG framework in the material science and engineering domain by integrating domain-specific KG. 
background: 
 Mistral 7B Mistral-7B [9, 10] is a cutting-edge LLM with 7 billion parameters, designed for high performance and efficiency. It surpasses the top open-source 13B model (LLaMA-2-13B [11] ) in all evaluated benchmarks and exceeds the best open-source 34B model (LLaMA-34B [12] ) in reasoning, mathematics, and code generation. Mistral-7B leverages grouped-query attention for faster inference and sliding window attention to manage sequences of any length more effectively, all while reducing inference costs as discussed in detail in [13] .Retrieval Augmented Generation (RAG) RAG [14] is a language generation method that improves the accuracy and reliability of generative AI models by incorporating facts retrieved from external sources. This method is built on a tripartite foundation comprising retrieval, generation, and augmentation techniques. By utilizing external knowledge, RAG significantly mitigates the issue of hallucination in LLMs, leading to its widespread adoption [15] . SPARQL SPARQL [16] is a query language for the Resource Description Framework (RDF) data. As a query language, it can be used to add, remove, and retrieve data.To address hallucinations in LLMs, one emerging solution involves using external knowledge as supplementary information to assist LLMs in generating authoritative outputs [17] . In [18] , LLMs are trained to retrieve relevant knowledge from external KGs to tackle domain-specific questions. The Mistral model with Contextual Position Encoding (CPE) introduced in [19] dynamically encodes positional data based on token context, thereby improving evaluation outcomes. The issue of hallucinations in Mistral is also addressed in [20] by using RAG to integrate information from Wikipedia, enhancing the model's accuracy. In a related but distinct study [21] , an ontology serves as an external knowledge source for developing a Text-to-SPARQL system. In contrast to all these methods, the approach proposed in this paper employs SPARQL queries for retrieving relevant triples from the KG. These triples are then integrated into the prompt for the QA task. 
kgmistral: 
 The general architecture of the proposed approach is given in Figure 1 . The various components of the architecture i.e., entity and relation extraction, similarity matching, extraction of relevant triples using SPARQL, verbalization, and prompt engineering and response generation, are discussed in detail in the subsequent sections. The purpose of this component is to extract entities and relations from the set of questions. The first step in the extraction process involves applying the en_core_web_sm named entity recognition (NER) model from spaCy1 due to its efficiency and customizability. Relations often exhibit varied expressions in natural language questions, as highlighted by Berant et al. [22] . For instance, the predicate "email address" in the question: "What is the email address of 'ParaView'?" could be expressed in multiple ways, such as "What is... 's email address?", "What is... contact point", or "How could... contact...?".To address this challenge, specific regular expressions and part-of-speech analysis are employed to improve the categorization of entities and relations, regardless of their varied expressions. This approach can also enable handling a broad range of questions effectively.After extracting named entities and relations from a given question (see Section 3.1), the next step involves matching them to elements in the KG. This process aims to identify entities and relations in the KG that are relevant to the question. To achieve this, semantic similarity matching is performed for entities using BERT with cosine similarity metric, leveraging the entities' labels and textual descriptions. Similarly, for relations, the Spacy's en_core_web_lg2 model is used. For each question, the top n most similar entities and the top m most similar relations in the KG are identified. In the next step, the identified entities and relations are then utilized to construct SPARQL queries to search for relevant triples from the KG.While some questions are simple, others can be more complex requiring more than one-hop graph traversal. For example, considering Figure 2 , the question "Who is working in the Computational Materials Science field?" would be a simple query that can be answered by looking at the one-hop neighbors of the entity "Computational Materials Science". On the other hand, the question "Who is working in the same field as 'Prof.Dr. Karsten Durst'?", may require two-hope graph traversal to retrieve the correct answers.SPARQL can be utilized to answer straightforward questions involving a single entity and a single relation, as well as to infer more complex multi-hop facts. In this work, once an entity and a relation are identified during the similarity matching phase as discussed in the previous section (see Section3.2), a SPARQL query is constructed using the templates provided in Table 1 . In this table, SPARQL Template 1 provides the query that can be used to extract entities that appear in the head position in triples where the relation and the tail entities are fixed to some given URIs. On the other hand, SPARQL Template 2 is designed to extract entities that appear at the tail position given some head entity and relation. SPARQL Template 3 is created to extract multi-hop facts. Specifically, it is used to extract more relevant information by first taking a tail entity that is returned as part of the results of a query with Template 2, together with a relation, it retrieves new head entities that are different from the original head entity. The answers that are retrieved using the SPARQL queries will then be passed to the verbalization phase where they will be processed and converted to sentences that make proper sense (see Section 3.4).Since the results returned by SPARQL are URIs, it is necessary to verbalize them so that LLMs would be able to make sense of them. Verbalization is performed by replacing the entities and the predicates in the triples with their corresponding human-readable labels.The verbalized triples created using the previous steps are used as context and passed to the prompt engineering and response generation step to generate answers from LLMs Specifically Mistral 7B (without loss of generality) as illustrated in Figure 1 . The prompt consists of three components: instruction, relevant information for enhanced context (verbalized triples), and the user question. The structured prompt is delineated as follows:System Instruction:• Role and Purpose: "You are a helpful assistant. Extract and answer using key information from context. " This instruction sets a clear expectation for the system's function, explaining the idea of boosting LLM performance with relevant contextual information verbalized from triples.• Precision and Brevity: "Ensure the response is concise, without duplicates, focusing solely on crucial details. " This directs the LLM to avoid redundancy and extract only essential details.• Examples: Two examples were provided to clarify the expected response format:-Example 1: (Context: The sun is a star in the center of our solar system. Question: What is the sun? Answer: A star at the center of the solar system.)-Example 2: (Context: Neil Armstrong was the first person to walk on the moon. Question: Who was the first person to walk on the moon? Answer: Neil Armstrong.)• Instructions on Format: "Your answer must be provided in a direct and concise format, without using any lead-in format such as 'Answer:' or similar. Only the answer itself should be included in the response. " This instruction ensures the LLM generates a simplified, correct format response, increasing evaluation performance.• This component utilizes the verbalized relevant triples from the KG as context for each question.User Question:• The user question is also part of the prompt to be fed into the LLM along with the instruction and context to generate responses, which is a key step in RAG.Using this prompt, the proposed architecture efficiently integrates the relevant triples from a KG into LLMs for improved QA. 
experiments: 
 In this section, the experiments conducted to evaluate the performance of the proposed approach are presented. The source code and the datasets are made publicly available at https://github.com/ Mingze101/KGMistral.The MSE-KG3 , representing data from institutions within the NFDI-MatWerk consortium 4 , is used as an external resource for retrieving relevant triples. The KG contains information on (i) relevant community structure: researchers, research projects, universities, and institutions; (ii) infrastructure: software, workflows, controlled vocabularies, instruments, facilities, educational resources, and events; and (iii) data: repositories, databases, scientific publications, published datasets, and reference data. MSE-KG is composed of 8,166 triples, 112 relations, and 1823 entities. The number of competency questions used for the experiments is 37.KGMistral is compared against three baselines:• Mistral: This model operates without utilizing any information from the KG, relying exclusively on the knowledge contained within the Mistral LLM.• Mistral Raw : In this model, the input KG is divided into chunks using a character-based text splitter, with each chunk having a maximum length of 1024 characters. Next, vector similarity is calculated between the question text and these chunks using a pretrained LLM. The top K chunks with the highest similarity scores (nearest neighbors) to the question are then selected as the context. Note that this model does not utilize SPARQL.• Mistral Verbalized : This baseline model is a verbalized version of Mistral Raw , where each triple from the KG is converted into a sequence resembling a natural language sentence, making it easier for the LLM to understand.The hyper-parameters for similarity matching, n and m, are set to 5 and 9 respectively. To prevent the Mistral 7B model [10] from becoming overly creative and deviating from the answer, its perplexity is set to zero. The metrics given in Table 2 are used to evaluate the models. BLEU [23] measures how many words and phrases in the machine-translated text appear in the reference translations, taking into account the order of words through the use of n-grams. ROUGE [24] assesses the quality of a generated summary or translation by comparing it with one or more reference texts. As shown in Table 3 , the models Mistral raw , Mistral verbalized , and KGMistral which utilize the KG as an external information source, outperform the Mistral model that does not leverage the KG. This demonstrates that integrating KGs into QA systems using RAG leads to significant improvements. The results also reveal that verbalization enhances model performance by making the retrieval process more effective. Notably, the proposed KGMistral approach surpasses all baseline models w.r.t all metrics except BLEU, indicating that generating context for user questions by extracting relevant triples with SPARQL queries and then verbalizing these triples is highly promising.In this work, the relation and entity extraction component of the proposed approach is primarily designed for simple user questions that include only one entity and one relation. Consequently, applying it to more complex questions may result in degraded performance. 
conclusion and future work: 
 In this study, the advantages of integrating information from KG to enhance the QA performance of LLMs in the field of materials science and engineering are investigated. A novel RAG-based QA approach named KGMistral is proposed. According to the experimental results, KGMistral outperforms all the baseline models. Despite these promising results, further improvements can still be made. Therefore, the following directions can be investigated in future work:• Improving the relation and entity extraction process to support more complex user question• Enhancing the verbalization process• Experimenting with other LLMs, such as GPT-3.5-turbo and fine-tuned GPT-3.5-turbo.  
 
 Appendix: https://spacy.io/models/en#en_core_web_smhttps://spacy.io/models/en#en_core_web_lghttps://demo.fiz-karlsruhe.de/matwerk/https://nfdi-matwerk.de/ 



Reviews: review: title: title: Relevant paper to the workshop
main_review: main_review: The paper extends Mistral with triples from a KG via RAG and applies the extension in a QA exercise within the domain of Material Sciences.

Comments:
- As the paper focuses on LLMs like Mistral, I was wondering why the steps "Entity and Relation extraction" and "Similarity Matching" do not leverage the power of Mistral. This seems to affect performance in more complex queries as highlighted in Section 4,5
- About the verbalization: what about the cases where the entities may have more than one label/synonym? 
- Mistral_raw: using triples from KG but without SPARQL --> ??  What is the difference here with respect to KGMistral. What is the role of the (results of the) SPARQL queries for KGMistral?
- Scores seem to be low. Moe LLMs should be evaluated in the future and possibly different ways of performing the entity extraction and the similarity matching to understand the impact of the various choices.
- I do not think the RAG-based approach is especially novel, but worth exploring different architectures and application domains.

The following paper is relevant as the authors extract SPARQL directly from a natural language description and an ontology:
- Dean Allemang, Juan Sequeda: Increasing the LLM Accuracy for Question Answering: Ontologies to the Rescue! CoRR abs/2405.11706 (2024)
title: title: review
main_review: main_review: The authors introduce KGMistral, an architecture for Retrieval Augmented Generation (RAG) using the Mistral language model. However, the focus on Mistral seems unnecessary, as the architecture could be adapted for other LLMs.

The paper's format should be CEURART, not LNCS.

The paper is well-written, but evaluating the entire architecture solely based on the final LLM output seems unfair, considering the multiple components involved. An ablation study would help assess the contribution of each component to the overall performance.

Overall, the paper is solid, with a clear research question, extensive evaluation set, and standard metrics.
title: title: The authors introduce the usage of SPARQL for integrating KG facts into LLM prompts for Question Answering to mitigate Hallucinations.
main_review: main_review: The authors describe a method of integrating external Knowledge from KGs in LLM prompts for improved QA performance. Their approach consists of extracting relevant triples from the KG and verbalizing them to add as context to an LLM prompt. The process from KGs to verbalized context is done in three steps. First, the entities and relations from the questions are extracted via pre-trained models. In the next step, the extracted entities and relations are matched with their corresponding KG entries. Based on this, SPARQL queries are built via templates to extract the relevant triples from the KG. The verbalization process consists of replacing the entities and predicates from the triples by their corresponding labels in the KG.
In the prompting step, the extracted and verbalized triple is added as context to the question for the LLM prompt. The main novel contribution is the usage of SPARQL for retrieving the triples from the KG. The authors show that their three step approach performs better than approaches where individual steps are left out. 
Overall, the presented work is a case-study and showcases a certain way of integrating KG context into LLM prompts for QA.
Pros:
-	The proposed usage of SPARQL in the process of context generation leads to an improved performance in the Rouge Scores.
Cons:
-	Presentation quality could be improved (i.e. Fig. 2 appears to be low-res, Table 1 is cut-off at a newpage)
-	Evaluation is done only on one KG in one domain
The topic of hallucination is very important and the paper introduces a way of mitigating this issue, although only in one specific domain. Given the significance of the topic, I tend to accept this paper.