Abstract
While pretrained transformer models have revolutionized natural language processing, their ability to capture and utilize factual human knowledge remains a challenge. We present Knowledge-Aware Language Model (KALM) pretraining, a method to enhance the factual density of transformer parameters without altering the underlying architecture or adding external storage. By introducing an entity-extended tokenizer at the input and an auxiliary entity prediction task at the output, KALM signals the existence of real-world entities during pretraining. Our results demonstrate that KALM significantly improves language modeling accuracy, factual correctness in LAMA probing, and semantic representation quality. Notably, KALM serves as a drop-in replacement for GPT-2, delivering substantial gains in zero-shot question-answering tasks.
Introduction
Large pretrained language models (PLMs) like GPT-2 are remarkably adept at modeling syntax and local semantics. However, they often exhibit factual inconsistencies because the standard objective—predicting the next sub-word token—does not explicitly prioritize the relationships between real-world entities. Previous attempts to ground models in factual knowledge typically involve massive scaling or the introduction of complex, specialized knowledge layers and external memory modules.
KALM addresses this by asking whether a standard transformer can be guided to learn more facts simply by highlighting the entities it is already processing. This approach maintains the efficiency and flexibility of the transformer architecture while significantly increasing the "knowledge density" of its parameters.
Methodology
The KALM framework integrates knowledge awareness into the standard pretraining pipeline through two primary mechanisms:
1. Entity-Aware Input
KALM utilizes an entity-extended tokenizer. In addition to standard sub-word tokens, the model receives a parallel "entity channel." Using a frequency-based dictionary, word spans (e.g., "United States") are mapped to unique entity IDs (e.g., Q30). These entity embeddings are learned during pretraining and added to the corresponding word embeddings before they enter the transformer layers. This "fuzzy linking" allows the model to leverage structured entity information without requiring a high-precision, computationally expensive entity linker.
2. Entity Prediction Task
At the output layer, KALM supplements the standard next-token prediction with a "next entity" prediction task. This is implemented using a margin-based contrastive loss, which encourages the model to distinguish the correct entity from a set of distractors. This dual objective forces the transformer to internalize the relationships between entities and their surrounding context more deeply than word-level prediction alone.
Semantic Probing and Accelerated Learning
To understand how these signals affect the model's internal representations, we employed "edge probing" across eight core NLP tasks, including Part-of-Speech (POS) tagging, Coreference resolution, and Relation classification.
As shown in the figure above, while both KALM and the GPT-2 baseline learn basic syntax (like POS) at similar rates, KALM exhibits a distinct advantage in higher-level semantic tasks. Tasks such as Relation classification and Coreference resolution see KALM reaching higher F1 scores much earlier in the training process, suggesting that entity signals accelerate the acquisition of complex linguistic and semantic structures.
Factual Knowledge and Language Modeling Results
The primary goal of KALM is to improve the factual accuracy of the model. We evaluated this using the LAMA (Language Model Analysis) benchmark, which tests a model's ability to complete factual statements (e.g., "Dante was born in [MASK]").
The results in the table above indicate that KALM consistently outperforms GPT-2 baselines across nearly all knowledge-intensive subsets. Most strikingly, the KALM Large model (~300M parameters) frequently matches or exceeds the performance of the GPT-2 1.5B model, and in some relational tasks, it rivals the 17B parameter variant. This suggests that injecting knowledge signals is a highly efficient alternative to "brute force" scaling.
Zero-Shot Question Answering
The practical utility of KALM is further demonstrated in zero-shot question-answering (QA) benchmarks like Trivia QA and WebQuestions. Without any task-specific fine-tuning, KALM models achieved Exact Match (EM) scores 20% to 100% higher than their GPT-2 counterparts. This confirms that the knowledge "packed" during pretraining is readily accessible for downstream reasoning tasks.
Conclusion
KALM demonstrates that explicit entity signaling is a powerful and efficient way to enhance the factual capabilities of pretrained language models. By remaining architecture-agnostic, KALM provides a scalable path forward for developing more reliable and knowledgeable AI systems without the prohibitive costs of massive parameter expansion.
Summary updated