In the world of Natural Language Processing (NLP), we usually treat language models like students taking a "closed-book" exam. We show them billions of sentences during training, and at test time, we expect them to have memorized every nuance and fact within their internal parameters. But as any student knows, it is much easier to find the right answer if you can look at a reference book.
Presented at ICLR 2022, GNN-LM proposes a shift from memorization to "copying." By allowing a model to reference similar contexts from its training data via a Graph Neural Network (GNN), the authors achieve state-of-the-art results while addressing the inherent limitations of purely parametric models.
TL;DR
GNN-LM enhances standard language models by retrieving semantically similar text snippets from the training corpus and organizing them into a heterogeneous graph. By using a Graph Neural Network to aggregate information from these "global contexts," the model achieves a new state-of-the-art perplexity of 14.8 on WikiText-103.
What Problem Does This Paper Address?
Standard neural language models (LMs) face two major hurdles:
- The Long-Tail Problem: It is incredibly difficult for a model to memorize rare, "long-tail" facts or specific phrasing found only a few times in a massive dataset.
- Memory Efficiency: To store more knowledge, we usually just make models bigger (more parameters), which is computationally expensive and hits diminishing returns.
The authors argue that the current "closed-book" strategy—where the model has no access to the training data during inference—is unnecessarily difficult. If a model is trying to predict the next word in the sentence "J.K. Rowling is best known for writing...", it shouldn't have to rely solely on its weights. It should be able to look up other sentences about Rowling in its "library" to find the word "Harry".
Methods
The GNN-LM pipeline works in four main stages, shifting the paradigm from isolated prediction to graph-based context aggregation:
- Encoding & Retrieval: A base Transformer LM encodes the current input context. The model then uses FAISS (a library for fast similarity search) to find the $k$ most similar contexts in the entire training corpus.
- Graph Construction: Instead of just looking at the single "next word" from those neighbors (as previous methods like $k$NN-LM did), GNN-LM builds a directed heterogeneous graph.
- Nodes: Tokens from the input context and tokens from the retrieved neighbor contexts.
- Edges: "Intra-context" edges (connecting words within the same sentence) and "Inter-context" edges (connecting words in the retrieved neighbors to the current input).
- GNN Processing: The model applies a 3-layer self-attention augmented GNN over this graph. This allows the model to "message pass" information from the retrieved references into the representation of the current word it is trying to predict.
- Final Prediction: The GNN-enhanced representation is used to calculate the probability of the next token. This is often combined with the $k$NN-LM approach for a final boost in accuracy.
Key Insights and Ideas
- "To copy is easier than to memorize": This is the central philosophy. By providing the model with "open-book" access to its training data, it can generalize better to rare sequences without needing billions of extra parameters.
- Context Matters: Unlike previous retrieval-based models that only looked at the labels of the neighbors, GNN-LM looks at the structure of the neighboring sentences. This allows the model to understand why a neighbor is relevant.
- Quantization is Mandatory: Storing the representations of billions of tokens takes terabytes of space. The authors used Product Quantization (PQ) to compress the datastore from 2.3TB down to 96GB, making the approach feasible on modern hardware.
- Data Leakage Prevention: During training, the authors had to carefully ensure the model didn't "cheat" by retrieving the exact sentence it was currently trying to predict.
Key Results
- New SOTA on WikiText-103: GNN-LM achieved a perplexity of 14.8, a massive 3.9-point improvement over the vanilla Transformer baseline.
- Parameter Efficiency: On the One Billion Word dataset, GNN-LM outperformed models with hundreds of millions more parameters by simply using its "open-book" retrieval system.
- Efficiency vs. Accuracy Trade-off: While GNN-LM is significantly more accurate and its perplexity improves as the number of retrieved neighbors ($k$) increases, it is slower. The GNN-LM inference speed is roughly 8 to 20 times slower than a standard Transformer due to the retrieval and graph processing overhead.
Limitations and Future Work
The primary limitation is computational overhead. Building the graph and performing $k$-nearest neighbor searches for every single token prediction adds significant latency.
The authors suggest that future work should focus on improving the efficiency of graph construction, speeding up the retrieval process, and exploring more sophisticated ways to select which "neighbors" are actually helpful, as not all retrieved contexts provide useful information for the current prediction.
Summary updated