Why do we need a Knowledge Graph?

By Nicky Wang

Nickyjiaxiwang
Trusted Data Science @ Haleon
10 min readNov 20, 2023

--

What is a Knowledge Graph?

While the final goal for an industry-level Knowledge Graph is to be a single source of industry knowledge and to serve multiple applications, it is currently laid as a foundation for many projects. While data scientists question the necessity of building such a Knowledge Graph rather than directly analysing the traditional structured data format, we may need to understand the Knowledge Graph first.

If we ask OpenAI ChatGPT (v3.5 turbo) what is a knowledge graph, the following paragraph is shown:

“A knowledge graph is a type of database that stores information in a way that allows for connections and relationships to be easily identified and analysed. It is a structured representation of knowledge that captures the relationships between different entities, concepts, and ideas. Knowledge graphs are often used in artificial intelligence and machine learning applications to help computers understand and interpret complex information. They are also used in search engines to provide more accurate and relevant results to users.”

A Famous search engine used Knowledge Graph to provide more accurate search results.
A Famous search engine used Knowledge Graph to provide more accurate search results. A screenshot of Google search result of “did Google include Knowledge Graph answer into search”.
The graph is presented to demo the elements of knowledge graph — entities, relations, and attributes.
The graph is presented to demo the elements of knowledge graph — entities, relations, and attributes. A screenshot of Google search result of “when was haleon formed”.

The basic elements of a knowledge graph are entities, relations, and attributes. It is a unique type of graph database, and the relation is often single-directional. It is the relation that distinguishes Knowledge Graphs from the traditional structured data formats as the relation provides proximity and remoteness, the path to reach a final target, and similarities between entities not only based on attributes/features but also on their surrounding neighbours. Another important difference lies in the attributes associated with the entities. These relations and attributes make a Knowledge Graph a graph: the entities are nodes, and relations are the edges connecting the nodes.

Three basic elements of Knowledge Graph entities, relations and attributes. They can be also called as triples.
Three basic elements of Knowledge Graph entities, relations and attributes. They can be also called as triples. Image by author.

The benefits of Knowledge Graph

Introducing the Knowledge Graph into the picture is important for the following reasons:

1Flexible integration of different knowledge, and concepts into one single unified graph: Suppose we are empowering a project with knowledge related to nutrition and health, we may also want to include knowledge about consumers, lifestyles, products, and articles. This knowledge can be perfectly embedded into a Knowledge Graph. Relations among these domains are interesting and can be a base to support search functions, rule-based algorithms, or Machine Learning models.

2Facilitate transfer learning and explainability[1]: The Knowledge Graph would contain different domains of knowledge but possibly structure similarly in these domains, including similar relations. Therefore, algorithms or analysis on one domain/graph cluster can be transferred to other domains/graph clusters through transfer learning. In the previous example, we can expand the Knowledge Graph related to nutrition and health to other domains such as pain relief, and oral health. Another benefit is that Machine Learning models are easier to explain due to intuitive graph data structure through visualization, including node proximity, paths, clusters, etc.

3Controlled outputs from Machine Learning models with high consistency: A common impression of LLM is that generated answers may create a hallucination. However, the output of a Machine Learning model based on a Knowledge Graph is only limited to triples (entities, relations, attributes), paths, or subgraphs. In the previous example, the output of search, recommendation, or predictions may include consumers, products, or nutrients. These elements can be internally audited and can help alleviate the problem inherited from the generative models, which will be explained later.

4Helps identify semantics information from the connection, and hidden relationship for faster decision making: The data format of Knowledge Graph would help drill down causal relationships and represent nodes through node embeddings trained from these connections and relations. It also benefits the relation inference (causal inference). In the previous example, we can use the proximity and remoteness, along with the attributes to infer if Consumer A is associated with Product B through relation to Interest C.

5Potential better Machine Learning model performance: Some Machine Learning models based on Knowledge Graph outperformed in certain tasks. For example, RippleNet, which is based on Knowledge Graph, outperformed in CTR prediction. On top of embedding-based and path-based knowledge-graph-aware recommendations, RippleNet proposes the propagation of user preferences over subgraphs, including entities, and extended relations. In the previous example, algorithms like RippleNet will be beneficial to promote article recommendations for consumer health. [2]

A demo of potential machine learning task performance uplift due to the structure nature of Knowledge Graph.
Potential machine learning task performance uplift due to the structure nature of Knowledge Graph [2].

LLM for KG

While LLM is getting more and more popular, it is wise to leverage LLM to help automate the process of building and maintaining a Knowledge Graph, making it easier to extract insights and knowledge from large amounts of data.

  1. Entity Recognition: LLM can be used to identify entities in text. This information can be used to create nodes in the Knowledge Graph. In the previous example, LLM can help identify relevant nutrients contained in certain foods, or the entities in an article.
  2. Relationship Extraction: LLM can also be used to extract relationships between entities in text. In the previous example, if a sentence mentions that “Apples contain a high amount of vitamin C.”, LLM can identify that entity “Apple” and entity “Vitamin C” may exist in a certain type of relation as defined. This information can be used to create a Knowledge Graph.
  3. Attribute Extraction: LLM can be used to extract attributes of entities in text. For example, if a sentence mentions that “An apple is a round, edible fruit produced by an apple tree (Malus domestica)”, LLM can recognize that this sentence may contain the attribute “shape” of the entity “apple” to be “round”.
  4. Natural Language Processing: LLM can be used to process natural language queries and then help provide relevant information from the Knowledge Graph. This can help users to explore and navigate the graph more easily. An example would be to transform a question from consumers to a search query in the Knowledge Graph database. It requires the above three extraction models’ capability and also the ability to match the triples based on semantics. In the previous example, if a question is “What does an apple look like?”, LLM can help match the sentence to a Knowledge Graph query to search for the attribute “shape” of an entity “apple”.
  5. Data Integration: LLM can be used to integrate data from multiple sources into the Knowledge Graph. For example, in data integration, we need to identify if two entities are duplicates in semantics, and LLM is good at this task. In the previous example, if 2 sentences both refer to the same fruit “apple” but with different names, LLM can help identify they are inserting the knowledge to the same entity “apple”.

KG for LLM

Knowledge Graph can improve the output of LLM in different ways:

  1. Before processing prompts: Knowledge Graph can help LLM to understand better the context of the text they are processing, including entity standardization and entity linkage. It can also supplement more information, including relations with entities, to the prompts. In the previous example, the nutrients and other information about a certain product can be added to the prompt.
  2. In processing prompts: Knowledge Graph QnA can also be used as a few shots in the prompts. In addition, if the prompts mainly come from certain domains where LLM is not good, Knowledge Graph can be used to provide extra data sources for fine-tuning. In the previous example, a Knowledge Graph related to nutrition and health can serve a data source for fine-tuning.
  3. After processing prompts: After LLM processes the prompts, the Knowledge Graph can be leveraged to perform knowledge correction to help stabilize the output by matching entities, relations, and attributes. Hallucinations and incorrect linkage may be alleviated if there are no obvious relations in the Knowledge Graph. In the previous example, if the output of LLM claims entity “apple” belongs to “vegetables”, we can deprioritize this answer with a more accurate search result “fruit” from the Knowledge Graph. Sourcing is also an important task and if a source appears in attributes/entities in the Knowledge Graph, it can be merged to the answer.

Integrations between LLM and Knowledge Graph

Other integrations between LLM and Knowledge Graph can be summarised into the following 3 main areas. [3] KG-enhanced LLMs aim to leverage Knowledge Graphs to better LLM during the phase of pre-training, inference, and interpretability. LLM-augmented KGs serve as a powerful tool to represent graphs or triples with embeddings, to complete or construct a Knowledge Graph, to generate text, and to enhance question answering. Synergized LLMs + KGs “aims to integrate LLMs and KGs into a unified framework to mutually enhance each other.” [3] The details are listed below. [3]

A brief graph shows how LLM can integrate KGs in terms of training, inference, completion, etc.
A brief graph shows how LLM can integrate KGs in terms of training, inference, completion, etc.

1) “KG-enhanced LLM pre-training includes works that apply KGs during the pre-training stage and improve the knowledge expression of LLMs.” It includes incorporating KG into the training objective, into inputs, and by additional fusion modules. For example, the model ERNIE concatenated token embedding and entity embedding in the model architecture [4]. Another example shows that by incorporating entity tokens and word tokens and by predicting the correct word and correct entity, the model KALM outperforms in knowledge-sensitive tasks and improves the exact match accuracy of downstream tasks [5].

2) “KG-enhanced LLM inference includes research that utilizes KGs during the inference stage of LLMs, which enables LLMs to access the latest knowledge without retraining.” That echoes the previous 3 ways identified to help prompt engineering. Rather than a two-tower architecture that separated text and KG inputs processing without interaction, many papers introduced the deep and rich interactions between them such as single-direction interaction, pooling, dot product, and bi-directional attention mechanism. It also includes the graph Retrieval Augmented Generation method where subgraphs or triples function as a part of the context in prompts.

3) “KG-enhanced LLM interpretability includes works that use KGs to understand the knowledge learned by LLMs and interpret the reasoning process of LLMs.” It splits into two parts. The LLM probing tries to understand the knowledge stored in LLM by converting a KG into natural language and using LLM to predict the missing entity. The LLM analysis tries to answer how LLM generates results. For example, QA-GNN grounds each reasoning step in LLM by a KG.[6]

4) “LLM-augmented KG embedding includes studies that apply LLMs to enrich representations of KGs by encoding the textual descriptions of entities and relations.” LLM can function as a text encoder to complement KG Embedding representations. In addition, it can incorporate both KGs and text into the same embedding space.

5) LLM-augmented KG completion includes papers that utilize LLMs to encode text or generate facts for better Knowledge Graph Completion performance. Knowledge Graph Completion refers to “the task of inferring missing facts in a given knowledge graph”. It uses LLM to encode a KG and text and then leverages these encoded representations to predict the triples. Apart from being encoders, LLM can also directly predict the triples as decoders.

6) “LLM-augmented KG construction includes works that apply LLMs to address the entity discovery, coreference resolution, and relation extraction tasks for KG construction.” In entity discovery, LLM can function as Named Entity Recognition to identify entities in text, Entity Typing to extract fine-grained type for a given entity in text, and Entity Linking to link entities identified in text to entities in a KG. Coreference resolution refers to identifying all expressions that refer to the same entity and LLM can function as encoders for a prediction architecture. At the last, LLM improves the performance of both sentence-level relation extraction and document-level relation extraction.

7) “LLM-augmented KG-to-text Generation includes research that utilizes LLMs to generate natural language that describes the facts from KGs.” A lot of research address the unseen concept sets and the different training objective compared against the pre-training LLM in KG-to-text by fine-tuning.

8) “LLM-augmented KG question answering includes studies that apply LLMs to bridge the gap between natural language questions and retrieve answers from KGs.” LLM can function as entity/relation extractors or answer reasoners, which reason over the extracted context and generate answers. It can also guide LLM reason through a KG along the paths.

How does Knowledge Graph help Haleon?

A Knowledge Graph about nutrition and health, as a foundation, was built at Haleon to assist consumers with QnA, graph search, and content recommendation for education purposes. In the future, the Knowledge Graph will be integrated with LLM to empower nutritionists for better consumer experience.

How does Knowledge Graph help Haleon?

A Knowledge Graph about nutrition and health, as a foundation, was built at Haleon to assist consumers with QnA, graph search, and content recommendation for education purposes. In the future, the Knowledge Graph will be integrated with LLM to empower nutritionists for better consumer experience.

Conclusion

The blog starts from the definition of a Knowledge Graph, the elements inside a Knowledge Graph, to explaining the difference between a Knowledge Graph to traditional structural data. It helps to answer why we need a Knowledge Graph with numerous advantages. With the explosion of LLMs, more and more researchers tend to synergize the power of Knowledge Graph and LLMs. In the future, there is still a lot of work to do, including constructing a Knowledge Graph with little human intervention, more advanced machine learning algorithms on Knowledge Graphs with superior graph computation methods, etc. “In a world of infinite content, [reliable] knowledge becomes very, very valuable.” — Denny Vrandečić

References

[1]Dr Jeff Pan, Dr ErnestoJiménez-Ruiz, Professor IanHorrocks, Dr Valentina Tamma. Knowledge Graphs. URL https://www.turing.ac.uk/research/interest-groups/knowledge-graphs

[2] Hongwei Wang, Fuzheng Zhang, Jialin Wang, Miao Zhao, Wenjie Li, Xing Xie, Minyi Guo, “RippleNet: Propagating User Preferences on the Knowledge Graph for Recommender Systems,” arXiv preprint arXiv: 1803.03467, 2018

[3] Shirui Pan, Senior Member, IEEE, Linhao Luo, Yufei Wang, Chen Chen, Jiapu Wang, Xindong Wu, Fellow, IEEE arXiv preprint arXiv: 2306.08302, 2023

[4] Zhengyan Zhang, Xu Han, Zhiyuan Liu, Xin Jiang, Maosong Sun, Qun Liu, “ERNIE: Enhanced language representation with informative entities,” in Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics. Florence, Italy: Association for Computational Linguistics, Jul. 2019, pp. 1441–1451. [Online]. Available: https://aclanthology.org/P19-1139

[5] Corby Rosset, Chenyan Xiong, Minh Phan, Xia Song, Paul Bennett, Saurabh Tiwary, “Knowledge-aware language model pretraining,” arXiv preprint arXiv:2007.00655, 2020.

[6] Michihiro Yasunaga, Hongyu Ren, Antoine Bosselut, Percy Liang, Jure Leskovec, “QAGNN: Reasoning with language models and knowledge graphs for question answering,” in Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies. Online: Association for Computational Linguistics, Jun. 2021, pp. 535–546. [Online]. Available: https://aclanthology.org/2021.naacl-main.45

--

--