Partially Shuffling the Training Data to Improve Language Models

Ofir PressarXiv 2019 · OpenReview

Abstract

Although SGD requires shuffling the training data between epochs, currently none of the word-level language modeling systems do this. Naively shuffling all sentences in the training data would not permit the model to learn inter-sentence dependencies. Here we present a method that partially shuffles the training data between epochs. This method makes each batch random, while keeping most sentence ordering intact. It achieves new state of the art results on word-level language modeling on both the Penn Treebank and WikiText-2 datasets.

Introduction

In most machine learning tasks, shuffling training data at the start of every epoch is a standard practice. This randomization prevents the model from memorizing data order and assists Stochastic Gradient Descent (SGD) in converging toward a superior solution. However, word-level language models (LMs) present a unique challenge. To capture long-term dependencies—such as a subject at the beginning of a paragraph influencing a verb several sentences later—LMs are typically trained on long, concatenated sequences of text. Naive sentence shuffling would destroy these critical inter-sentence relationships. Consequently, many state-of-the-art LMs have traditionally reused the exact same sequence order in every training epoch, sacrificing the benefits of SGD randomness to maintain context.

Methodology: Partial Shuffle

This paper introduces the Partial Shuffle method to reconcile the need for optimization randomness with the necessity of preserving context.

Standard Batching vs. Cyclic Shift

In standard training, a long sequence is divided into $s$ rows (the batch size), which are then chopped into sub-sequences of length $b$ (the Backpropagation Through Time, or BPTT, length).

The proposed method introduces a "cyclic shift" before chopping the rows into BPTT segments. For each row, the algorithm selects a random index and moves all words preceding that index to the end of the row. This ensures that the starting point of each batch varies across epochs. While the internal word order remains 99% intact—preserving local context—the specific combinations of sequences appearing together in a single GPU batch change every epoch. This "partial" shuffling randomizes batch composition while keeping local ordering mostly untouched.

Experimental Setup

The method was evaluated using two primary word-level language modeling benchmarks:

  • Penn Treebank (PTB): A classic dataset of Wall Street Journal articles.
  • WikiText-2: A larger dataset sourced from high-quality Wikipedia articles.

The Partial Shuffle technique was applied to two high-performing architectures: Mixture of Softmaxes (MoS) and Direct Output Connection (DOC).

Key Results

The Partial Shuffle method yielded consistent improvements in perplexity across all tested configurations.

Perplexity results on the WikiText-2 dataset.

On the WikiText-2 dataset, adding Partial Shuffle to the DOC model with finetuning reduced test perplexity from 58.03 to 57.85.

Perplexity results on the Penn Treebank dataset.

On the Penn Treebank dataset, the method improved the DOC model's test perplexity from 52.38 to 52.00, establishing a new state-of-the-art at the time of publication. These gains were consistent across both base models and those using additional finetuning steps.

Discussion and Insights

The core insight of this work is that full randomization is not required to reap the benefits of shuffling; simply varying the starting point of the "deal" is sufficient. By shifting the starting point, the model encounters different "edges" of BPTT segments in every epoch.

Furthermore, the method is computationally efficient, adding negligible overhead (less than 1/100th of a second per epoch on PTB). While the cyclic shift breaks exactly one dependency per row, this loss is statistically insignificant compared to the optimization benefits provided by the injected randomness.

Limitations and Future Work

While effective for recurrent models (RNNs/LSTMs) where hidden states are passed between sub-sequences, further research is needed to evaluate the impact on Transformer architectures. Additionally, since hyperparameters were not re-tuned for the shuffled data, even greater performance gains may be possible with optimized settings.

Summary updated

Abstract

Although SGD requires shuffling the training data between epochs, currently none of the word-level language modeling systems do this. Naively shuffling all sentences in the training data would not permit the model to learn inter-sentence dependencies. Here we present a method that partially shuffles the training data between epochs. This method makes each batch random, while keeping most sentence ordering intact. It achieves new state of the art results on word-level language modeling on both the Penn Treebank and WikiText-2 datasets.
BibTeX
@misc{press2019partially,
  author = {Ofir Press},
  title = {{Partially Shuffling the Training Data to Improve Language Models}},
  year = {2019},
  eprint = {1903.04167},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1903.04167},
}
Figure