Abstract
While recurrent neural networks have found success in a variety of natural language processing applications, they are general models of sequential data. We investigate how the properties of natural language data affect an LSTM's ability to learn a nonlinguistic task: recalling elements from its input. We find that models trained on natural language data are able to recall tokens from much longer sequences than models trained on non-language sequential data. Furthermore, we show that the LSTM learns to solve the memorization task by explicitly using a subset of its neurons to count timesteps in the input. We hypothesize that the patterns and structure in natural language data enable LSTMs to learn by providing approximate ways of reducing loss, but understanding the effect of different training data on the learnability of LSTMs remains an open question.
Introduction
Recurrent Neural Networks (RNNs), specifically LSTMs, are the workhorses of natural language processing. While they are designed to handle sequential data, they are general mathematical models not specifically "hard-coded" for language. This raises a fundamental question: Does the nature of the data itself make the model easier to train? This research investigates whether the inherent properties of natural language—such as Zipfian distributions and structural patterns—help LSTMs learn a fundamental, non-linguistic operation: memorization.
Methodology
The researchers designed a "Memorization Task" where a model is given a sequence of tokens and must output the identity of the middle token. To ensure the LSTM was responsible for the learning, the authors froze the weights of the embedding matrix and the output projection, forcing the model to rely entirely on the LSTM’s internal parameters.
Performance was compared across several synthetic and real-world data distributions:
- Uniform: Tokens sampled randomly.
- Unigram: Tokens follow a Zipfian distribution but are otherwise independent.
- n-gram (5, 10, 50): Markovian dependencies added by grouping and permuting tokens.
- Language: Real sequences from the Penn Treebank (PTB).
Results and Analysis
Data Distribution and Learnability
The most striking finding is that LSTMs trained on uniform data fail to memorize sequences longer than 10 tokens. However, when trained on natural language, they can memorize sequences up to 300 tokens long.
As shown in Figure 1, even without complex syntax, just having a Zipfian distribution (the Unigram setup) significantly improved the model's ability to learn the task compared to a uniform distribution. The authors hypothesize that linguistic patterns provide "approximate pathways" to minimize loss early in training, which eventually guides the model toward the correct memorization strategy.
The Counting Mechanism
LSTMs solve the memorization task by developing "counting neurons." By using linear regression on the hidden unit activations, the researchers identified specific units whose activations increase linearly with each timestep until the target token is reached.
Figure 3 illustrates this mechanism with Neuron 77 and Neuron 61. Their activations scale with the input sequence length and reset once the target is identified. The internal state of the LSTM was found to be a near-perfect predictor of the current timestep, with an $R^2$ value of 0.998.
Capacity vs. Learnability
The study found that simply adding more hidden units (increasing model capacity) does not help the model learn on uniform data. This suggests that the difficulty of the task on random data is a learnability issue—a failure of the optimization process to find a solution—rather than a lack of parameters.
Conclusion
This research demonstrates that linguistic structure acts as a form of "training wheels" for LSTMs. By exploiting patterns inherent in language, these models are able to learn internal mechanisms like counting that are necessary for long-range memorization. These findings suggest that artificially introducing linguistic-like structures into non-language sequential data (such as in chemistry or music) could potentially improve the trainability of sequence models in those fields.
Summary updated