N-gram Language Modeling using Recurrent Neural Network Estimation

Ciprian Chelba, Mohammad Norouzi, Samy BengioarXiv 2017

Abstract

We investigate the effective memory depth of RNN models by using them for $n$-gram language model (LM) smoothing. Experiments on a small corpus (UPenn Treebank) found the LSTM cell with dropout to be the best model for encoding the $n$-gram state. When preserving sentence independence, the LSTM $n$-gram matches the LSTM LM performance for $n=9$ and slightly outperforms it for $n=13$. On the One Billion Words benchmark, results hold at larger scale: while LSTM smoothing for short contexts is not significantly better than classic models, it becomes effective with long contexts ($n > 5$), matching fully recurrent models at $n=13$. This suggests practical benefits for parallel processing and succinct state representation in production systems.

Introduction

Language modeling (LM) is a cornerstone of natural language processing, traditionally dominated by $n$-gram models. While $n$-gram models are scalable, they suffer from data sparsity as the context window $n$ increases. Recurrent Neural Networks (RNNs), particularly LSTMs, addressed this by maintaining a hidden state representing a theoretically unlimited history. However, RNNs are difficult to parallelize and their large hidden states are cumbersome for real-time decoders. This research explores the "effective memory depth" of LSTMs by using them as smoothing functions for fixed-length $n$-gram windows, aiming to combine the benefits of both approaches.

Methodology

The authors propose LSTM $n$-gram models, where an LSTM encodes a fixed window of $n-1$ words to predict the next token. This approach treats the LSTM as a sophisticated estimator for $n$-gram probabilities. Several variations were explored:

  • Architecture Comparison: Evaluating Feed-Forward, "Vanilla" RNN, and LSTM cells for context encoding.
  • Context Encoding: Testing forward, reverse, and bidirectional encodings.
  • Training Targets: Comparing standard "one-hot" targets with multinomial targets, where the model learns the full distribution of words observed in a specific context across the training set.

Experimental Results

Small-Scale Evaluation: UPenn Treebank

Initial experiments on the UPenn Treebank (PTB) dataset (~1M words) focused on architecture selection. The results indicated that LSTMs are superior to feed-forward and vanilla RNNs for this task. Notably, performance improved consistently as the $n$-gram order increased, a departure from traditional smoothing methods like Kneser-Ney which often plateau.

Comparison of different RNN architectures and n-gram orders on the PTB dataset. Performance improves as the context window 'n' increases, with LSTMs leading.

As shown in Figure 2, the LSTM $n$-gram models significantly outperform simpler neural architectures. At $n=13$, the LSTM $n$-gram achieves a perplexity (PPL) of 91, surpassing the standard LSTM baseline of 95 when sentence boundaries are respected.

Large-Scale Evaluation: One Billion Words Benchmark

To verify these findings at scale, the models were tested on the One Billion Words benchmark. The results confirmed that the advantages of LSTM smoothing become pronounced with longer contexts ($n > 5$).

Results on the One Billion Words benchmark, demonstrating that LSTM n-grams approach baseline performance as n increases to 13.

Figure 4 illustrates that as $n$ reaches 13, the LSTM $n$-gram model (PPL 49) nearly matches the performance of the fully recurrent LSTM baseline (PPL 48). This suggests that for many practical tasks, a history of 13 words captures the vast majority of useful information for next-word prediction.

Discussion and Conclusion

The study identifies a "13-word horizon" for LSTM memory in language modeling. Beyond this window, the benefits of an unlimited history are marginal. This finding has significant practical implications:

  1. Parallelization: Fixed-length $n$-gram contexts allow for massive parallelization during training and inference, as dependencies across long sequences are broken.
  2. State Representation: The state of an LSTM $n$-gram can be represented succinctly by the identities of the context words, rather than a high-dimensional hidden vector. This is particularly beneficial for high-speed ASR decoders.
  3. Robustness: LSTM $n$-grams scale gracefully with higher orders, avoiding the sparsity issues of traditional back-off estimators.

While the computational cost per word is higher due to recomputing states, the architectural advantages make LSTM $n$-grams a compelling alternative for production environments, especially for short-format text like voice search queries.

Summary updated

BibTeX
@misc{chelba2017n,
  author = {Ciprian Chelba and Mohammad Norouzi and Samy Bengio},
  title = {{N-gram Language Modeling using Recurrent Neural Network Estimation}},
  year = {2017},
  eprint = {1703.10724},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1703.10724},
}
Figure