Knowledge Graphs in LLMs

Large Language Models (LLMs), as you already know, have grown quite a bit in the past couple of years, more so than supposed and surprising as it may be, they will continue to grow more. When I say grow, I mean improve, in the sense that they have vastly been able to capture the intricacies and nuances of the natural language and model it in a manner that they can use it to solve problems a common person may face everyday.
Even a seven-year old boy appearing for a half-an-hour examination is capable of using an LLM to generate answers for the questions which he feels insufficiently prepared for. An eighty-year old woman can ask ChatGPT what prescription she requires in the morning due to her back pain if she forgets what her doctor told her. Those who lie between these age groups have been extensively using these LLMs for their school, work and personal life as well. LLMs have become such a dominant part of our life that we cannot begin to imagine a life without them. Of course, we could live without it- but it wouldn’t be so comfortable as it is now.
Most of those who use these LLMs have a vague idea of how these work, some couldn’t care less, some might even reject an explanation because they don’t have the time or the patience to listen to it. People with the vague idea of LLM suppose these machines to be trained on large chunks of data using some machine learning model (they might not be aware of the term deep learning), and the same model is used to answer their queries. They would not be wrong in assuming so. This is, after all, a decent definition of how LLMs work. But LLMs are much deeper and much more complex than that! And it is those who understand this part that are truly able to elicit the true potential of LLMs.
To explain how LLMs work would be outside the scope of this blog- I cover only the relevance of knowledge graphs in LLMs.
First, let’s understand what Knowledge Graphs are. Much like any graph, a knowledge graph is a network, connecting different entities in the real-world such as names, places, animals, buildings etc. This information is primarily stored in a graph database and visualized as a graph (hence the name knowledge graph). Three keywords come out to be the most important for knowledge graphs- schema, identity and context. The framework for a knowledge graph is provided by schemas, while identities classify the entities and the setting of the knowledge is done by context. All three, equally important, do the role of assigning the same words with different meanings. For example, they help distinguish between ‘apple’ the fruit and ‘Apple’ the company.
Knowledge graphs have been consistently integrated with daily usage tools such as Google. Google’s knowledge graph contains more than half a billion entities extracted from different datasets and other less known knowledge graphs (Wikipedia, CIA World Factbook and many more).
How does this integration work and why is it necessary?
It is true that the most sophisticated of the neural networks and transformer architectures are able to capture the statistically significant entities in a given text corpus. But when prediction accuracy is of essence, they may require, under normal circumstances, the assistance of a facility that will help establish relationships with different entities. The entities as themselves hold no value during inference if there is nothing to connect them with. For example, the words Shakespeare and Hamlet would bear no connection when spoken without a connection- ‘Shakespeare wrote Hamlet’ (a rather crude phrasing), brings a semantic expression to the words.
Knowledge graphs, through the connections they bring between different entities in a text corpus, enhance the capabilities of an LLM. By bridging the gap among words and phrases, knowledge graphs improve a LLM’s ability to predict an answer that is coherent and semantically sensible. When asked a question, the connecting entities and their relationships are identified using knowledge graphs, ensuring the answer is pertinent to what is being asked.
LLMs, when asked about facts and bits about the real-world, often hallucinate: they tend to offer answers that are not true. When integrated with knowledge graphs, LLMs generate grounded verified facts and not mambo-jumbo that could be contradicted through fact-checkers. Knowledge graphs, due to their structured data format, allow queryable knowledge for the implementation of RAG in numerous LLMs such as ChatGPT, Gemini etc. Python libraries such as Langchain are able to illustrate how this works so that it can be implemented with ease. The usage of knowledge graphs for RAG has helped deliver reliable responses and quick and efficient augmented generation. Google currently uses a knowledge graph of more than 5 billion entities.
Going a step further than the everyday LLMs, domain-specific LLMs (those pertinent to finance, healthcare etc.) are being integrated with domain-specific knowledge graphs to strengthen question answering and entity recognition. Personalized recommendations and domain-specific agent workflows are being developed on this basis- revealing just how advanced and powerful LLMs can be.
But is the integration of knowledge graphs necessary for LLMs? Yes! The existence of noisome and unreliable text in the real-world necessitates the use of reliable knowledge graphs in the reduction of bias of LLMs. Since the data for knowledge graphs is extracted mainly from trustworthy resources and filtered in many iterations through both manual and automated techniques, their incorporation comes with the added advantage of factual accuracy and reduced toxicity in the responses offered by LLMs.
Large Language Models are very capable and brilliant at generating textual output. However, without the understanding of the connections between the entities in the data, bias is introduced and the responses become questionable. Through the provision of a structured memory, LLMs are taught how to talk and think.
Subscribe to my newsletter
Read articles from Ananya Y directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
