Language models and knowledge graphs
Open reasoning with the combined strengths of text and symbols
Background
Language models (LMs) like the GPT and LLaMA variety are still upending the knowledge economy. On the other hand, knowledge graphs (KGs) are decades-old data systems that I’ve written about previously.
LMs are approximate knowledge stores and reasoning engines that can store a representation of massive amounts of information and efficiently output predictions. They’re also extremely versatile and can generalise to many tasks, like writing and coding.
On the other hand, knowledge graphs use nodes and edges to represent concepts and their relations. This makes them intuitive representations of structured domain knowledge, like mind maps.
So LMs and KGs both store information, but they work pretty differently.
Roughly:
- LMs represent implicit knowledge
- KGs represent explicit knowledge
Let’s look at how combining both approaches can improve LM-powered systems by reducing hallucinations and improving the observability of their decisions.
The recent paper Unifying Large Language Models and Knowledge Graphs: A Roadmap gives us a framework for using these tools.
Combining implicit and explicit knowledge
At a high level, there are three ways to integrate knowledge graphs and language models:
- use KGs to provide context to LMs
- use LMs to improve KGs
- reason using a combination of both
Benefits of adding knowledge graphs
The paper discusses two ways to leverage KGs to enhance LMs:
1. Provide explicit knowledge during pre-training
The first stage of training foundational models like GPT-4 is feeding the model large corpora of information, like large chunks of the Internet(!).
Supplying knowledge graphs at pre-training would give language models deterministic ways to disambiguate the information it stores.
2. Ground language model responses during inference
LMs can also use KGs to inform their outputs by accessing domain-specific knowledge during usage.
Chatbots often use similarity search to find relevant information from company knowledge bases. This data is usually stored in vector embeddings, frequently in a vector database.
Credit: the classic Word2Vec image from Google (https://cloud.google.com/blog/topics/developers-practitioners/meet-ais-multitool-vector-embeddings).
This kind of reasoning could be augmented by verifying facts using KGs.
Connections in a graph can also be represented using vectors, similar to words. These graph embeddings are easy to use and can be used to develop efficient algorithms for retrieving useful knowledge in conjunction with LMs.
Credit: Representation Learning on Graphs: Methods and Applications (https://arxiv.org/pdf/1709.05584.pdf)
Using language models to improve graphs
So, how can language models improve knowledge graphs?
Well, there are at least five approaches:
- Embedding
LMs can embed entities and relations into a continuous vector space, enabling efficient similarity search and clustering. Other research suggests ways to measure the likelihood of an embedding’s accuracy, which can improve the pretraining of language models.
- Completion
We can also use LMs to add new information to KGs, improving their completeness and accuracy.
- Construction
LMs don’t have to start with an existing KG. They can be used to construct new KGs from unstructured text data, automating the process of extracting and representing a given domain.
- Graph-to-text generation
LMs can generate natural language descriptions of KGs, making them more accessible and interpretable to humans. For example, I had GPT translate some of my open banking KG into plain English, as shown below.
GPT-4: The country of Brazil standardises on the standards maintained by Banco Central. One such standard is the Open Finance Brasil specification, which supports the product "transaction account".
- Question answering
LMs can answer questions based on the knowledge stored in KGs, giving users a super efficient and intuitive way to retrieve specific knowledge.
Language models + knowledge graphs = System 1 and 2?
This final framework discusses integrating KGs and LMs to enhance each other's capabilities through two lenses:
- Knowledge representation
Could KGs and LMs allow us to have our cake and eat it, too? I don’t know, but together, these systems could let us access information efficiently and accurately.
- Reasoning
KGs might help us to interpret the reasoning process of LMs, turning inscrutable black boxes into reasoning systems we can better understand.
The boxes are still black, but the arrows are white. Tweet here.
Challenges
The LM and KG combo sounds great. What’s the catch?
Scalability
Large models and complex graphs = BIG computation and BIG storage
Using both technologies in the ways we’ve discussed feels like fresh territory, but scaling issues aren’t new.
Overall, I’d be surprised if this became a significant problem. It seems worth understanding the systems we build better.
Interpretability
LMs are built with maths but are basically doing magic.
KGs often have their own mess of noisy, ambiguous or incomplete information.
Maybe we need the AI to teach us.
Catastrophic forgetting
Imagine learning to drive a car while forgetting how to ride a bike.
LMs can sometimes forget previously learned knowledge when trained on new data.
Between using KGs in pre-training and using LMs for graph construction, I wonder how ceding more control to the AI will affect prior knowledge.
Bad knowledge
The addition of bad knowledge is perhaps even worse than catastrophic forgetting.
LMs still get things wrong and could put incorrect information in KGs, leading to inaccuracies and potentially generating misinformation.
What’s next?
I don’t know what the future of AI is, but the possibilities seem endless.
Imagine an era where AI doesn't just assist us with mundane tasks or answer simple questions but truly understands us and can contribute to conversations, offer informed opinions, make nuanced predictions, and provide insights on a level that even surpasses human capability in specific domains.
AI that can process and reason about all forms of data - not just text, but images, audio, video, and maybe even sensory and emotional data… personalised AI that's deeply integrated into our daily lives.
For example, let’s think about education. Customised AI tutors could provide one-on-one student support, adapting teaching strategies based on each individual's unique learning style for literally any topic. They could provide detailed explanations that draw from vast knowledge graphs, engaging with students in a meaningful and personal way.
These broader applications are just the beginning. The combination of LMs and KGs offers a powerful new approach to knowledge representation and reasoning that could transform many industries and sectors.
We're still in the early stages of exploring how these technologies can be used together. But who knows, pushing the synergies between LMs and KGs might push the boundaries of AI itself.
This kind of stretches the term ‘catastrophic forgetting’ to include the removal of knowledge from graphs beyond conventional usage, which usually refers to neural nets.