Abstract
Autoregressive large language models (LLMs) pre-trained by next token prediction are inherently proficient in generative tasks. However, their performance on knowledge-driven tasks such as factual knowledge querying remains unsatisfactory. Knowledge graphs (KGs), as high-quality structured knowledge bases, can provide reliable knowledge for LLMs, potentially compensating for their knowledge deficiencies. Aligning LLMs with explicit, structured knowledge from KGs has been a challenge; previous attempts either failed to effectively align knowledge representations or compromised the generative capabilities of LLMs, leading to less-than-optimal outcomes. This paper proposes KaLM, a Knowledge-aligned Language Modeling approach, which fine-tunes autoregressive LLMs to align with KG knowledge via the joint objective of explicit knowledge alignment and implicit knowledge alignment. The explicit knowledge alignment objective aims to directly optimize the knowledge representation of LLMs through dual-view knowledge graph contrastive learning. The implicit knowledge alignment objective focuses on incorporating textual patterns of knowledge into LLMs through triple completion language modeling. Notably, our method achieves a significant performance boost in evaluations of knowledge-driven tasks, specifically embedding-based knowledge graph completion and generation-based knowledge graph question answering.
1. Introduction
While Large Language Models (LLMs) excel at generating fluent text, they often struggle with knowledge-driven tasks requiring precise factual recall. They function as parametric knowledge bases where information is implicit and occasionally imprecise. In contrast, Knowledge Graphs (KGs) provide structured, explicit, and deterministic knowledge.
Merging these two paradigms faces two primary hurdles:
- Representation Anisotropy: LLM embeddings tend to cluster in a narrow "cone" in vector space, making it difficult for the model to distinguish between distinct pieces of knowledge.
- The Alignment Trade-off: Previous alignment attempts often degraded the model's natural language generation capabilities or failed to improve internal representations effectively.
2. Methodology
KaLM introduces a joint training objective that addresses alignment through two complementary views: explicit and implicit.
2.1 Explicit Knowledge Alignment
This approach utilizes Dual-view Knowledge Graph Contrastive Learning. A KG triple (Head, Relation, Tail) is treated as two views of the same fact: View A (Head description + Relation) and View B (Tail description). The model is trained to align these views in the embedding space while maximizing distance from unrelated triples using an InfoNCE loss with an additive margin.
2.2 Implicit Knowledge Alignment
To preserve generative proficiency, KaLM employs standard autoregressive fine-tuning via Triple Completion. The model is prompted to complete a triple given a head entity and relation, reinforcing factual textual patterns without sacrificing next-token prediction fluency.
3. Experimental Results
3.1 Knowledge Graph Completion (KGC) and QA
Evaluation on the WN18RR and FB15k-237 datasets demonstrated substantial improvements. For KGC on WN18RR, KaLM (based on Llama-2-7B) achieved a Mean Rank (MR) of 19, compared to the base model's MR of 15,969. In Question Answering tasks, KaLM saw an average accuracy increase of 14.1% in tail entity prediction.
3.2 Mitigation of Representation Anisotropy
A key contribution of KaLM is the resolution of representation anisotropy. By forcing the model to distinguish between thousands of negative triples, the vector space "unfolds," becoming more discriminative. Sentence-level anisotropy on Wikitext-103 dropped from 0.83 to 0.21.
4. Discussion and Conclusion
KaLM successfully bridges the gap between generative LLMs and structured KGs. Analysis indicates that fine-tuning Feed-Forward Network (FFN) layers via LoRA is particularly effective for storing factual patterns. The synergy between explicit embedding alignment and implicit generative alignment is crucial; without the latter, the model's linguistic fluency (perplexity) degrades. Future work will explore scaling these gains to larger models and integrating KaLM representations into Retrieval-Augmented Generation (RAG) pipelines for more precise retrieval.
Summary updated