Abstract
Standard recurrent neural network language models (RNNLMs) excel at capturing local sentence structure but often fail to maintain document-wide coherence. We present Document-Context Language Models (DCLMs), which utilize multi-level recurrent architectures and attention mechanisms to bridge long-range dependencies. By incorporating context from previous sentences, DCLMs significantly improve word prediction accuracy and document-level logical flow.
Introduction
Language modeling involves predicting the next word in a sequence given its preceding context. While n-gram models use local windows and standard RNNLMs process entire sentences, both typically ignore broader document context. In natural language, word choice is driven by both local syntax and global discourse or topic.
Scaling standard RNNs to handle entire documents presents two primary challenges: information decay, where early context is lost over long sequences, and learning instability during backpropagation through hundreds of tokens. DCLMs address these by explicitly conditioning the current sentence generation on the context of the preceding sentence.
Methodology
The authors propose three architectural variations to integrate context from the previous sentence ($t-1$) into the current sentence ($t$):
- Context-to-Context (ccDCLM): The final hidden state of the previous sentence is concatenated with the input word embedding at every time step of the current sentence. This "short-circuits" document-level information directly to each word.
- Context-to-Output (coDCLM): The previous sentence's context is fed directly into the final softmax layer, decoupling the hidden states of different sentences for computational efficiency.
- Attentional DCLM (aDCLM): An attention mechanism allows the model to dynamically attend to all hidden states of the previous sentence, rather than just the final state, creating a specific context vector for each generated word.
Experimental Setup
The models were evaluated on two corpora: the Penn Treebank (PTB), a standard benchmark, and the North American News Text (NANT) corpus, which contains significantly longer documents. NANT documents average over 30 sentences and 780 tokens, providing a more rigorous test for document-level modeling.
Results and Discussion
DCLMs demonstrated improvements in both perplexity and local coherence. On the PTB test set, ccDCLM achieved a perplexity of 66.42, compared to the baseline RNNLM's 71.88. On the larger NANT dataset, the Attentional DCLM reached a perplexity of 170.99, significantly lower than the baseline's 194.43.
Beyond word prediction, the models showed substantial gains in local coherence. In a "shuffle test" requiring the model to identify original sentence orderings, ccDCLM achieved 83.26% accuracy, a marked improvement over the baseline's 72.54%. This indicates that injecting previous sentence summaries helps the model maintain a consistent "thread" throughout the document.
Conclusion
DCLMs effectively mitigate the vanishing gradient problem in long-range document modeling by providing direct paths for context. While current models focus on the immediately preceding sentence, future work will explore expanding this context window and applying these architectures to downstream tasks like machine translation and summarization.
Summary updated