Recurrent Neural Network Language Models (RNNLMs) have become a standard tool in natural language processing due to their ability to capture long-range dependencies. However, they suffer from a fundamental limitation: their architecture makes it difficult to calculate the probability of a phrase in isolation. This paper, presented at EMNLP 2018, introduces a novel training modification that allows RNNs to accurately estimate these "marginal" probabilities.
The Problem: Context-Heavy Models
Standard RNNLMs are inherently "context-heavy." To predict the next word, they rely on a hidden state built from every preceding word in a sequence. While this is effective for sequence completion, it fails when calculating a marginal probability—the likelihood of a phrase like "of the" appearing anywhere in the language, regardless of what came before it.
Mathematically, calculating this for an RNN is intractable because it requires averaging the model's output over every possible preceding context. This limitation hinders several applications:
- Model Inspection: Identifying if a model is biased toward generating offensive phrases.
- Information Extraction: Identifying globally probable patterns (e.g., "cities such as [x]").
- Data Integration: Enhancing a model trained on a small corpus by incorporating $n$-gram statistics from massive datasets like the entire web.
Proposed Methods
The authors explore two primary strategies for approximating these probabilities:
1. Trace-based Approaches (Sampling)
This method involves running the model over a large corpus and saving the resulting hidden states (the "trace"). To estimate a phrase's probability, states are sampled from this trace to serve as starting points. The authors refine this using Importance Sampling, where an encoder is trained to select the most relevant starting states for a specific query.
2. Fixed-point Approaches (The "Zero" Method)
Rather than sampling, the authors attempt to make a single starting state—the zero vector—represent a state of "no context." To achieve this, they modify the training process:
- State-Reset (R): The hidden state is randomly reset to zero during training (with a 5% probability), forcing the model to learn to predict words even when its memory is cleared.
- Unigram Regularization (U): A loss term is added to penalize the model if its prediction from a zero-state deviates from the global unigram distribution of the training data.
The resulting method, $Zero^{(RU)}$, allows marginal probabilities to be calculated in a single forward pass, making it significantly faster than sampling-based alternatives.
Key Results and Evaluation
The researchers evaluated their methods on standard benchmarks, including the Penn Treebank (PTB) and WikiText-2 (WT-2). As shown in the table below, the $Zero^{(RU)}$ method significantly reduces the error in marginal estimation compared to standard RNNs.
On the PTB dataset, $Zero^{(RU)}$ reduced the average error from 3.828 to 0.425. While Importance Sampling (Trace-IW) remains slightly more accurate for very long $n$-grams (4 or 5 words), the training-based "Zero" method is superior for short, common phrases and offers much higher computational efficiency.
Transfer Learning via n-gram Statistics
A major application of this work is improving small-corpus models. By using their marginal estimator to "nudge" a WT-2 model to match the $n$-gram statistics of the much larger WikiText-103 (WT-103) dataset, the authors achieved significant gains in perplexity.
As illustrated in the loss curves, the model trained with both WT-2 text and WT-103 $n$-gram statistics achieves a lower loss than the model trained on WT-2 text alone. Specifically, the model's perplexity improved from 104.08 to 93.95.
Conclusion
By introducing simple modifications like state-resets and unigram regularization, the authors bridge the gap between traditional $n$-gram models (excellent at marginals) and RNNs (excellent at context). This approach provides a fast, accurate way to inspect neural models and integrate external statistical knowledge without requiring the full text of massive datasets.
Summary updated