Improve Long-term Memory Learning Through Rescaling the Error Temporally

Shida Wang, Zhanglu YanarXiv 2023

Abstract

This paper studies the error metric selection for long-term memory learning in sequence modelling. We examine the bias towards short-term memory in commonly used errors, including mean absolute/squared error. Our findings show that all temporally positive-weighted errors are biased towards short-term memory in learning linear functionals. To reduce this bias and improve long-term memory learning, we propose the use of a temporally rescaled error. In addition to reducing the bias towards short-term memory, this approach can also alleviate the vanishing gradient issue. We conduct numerical experiments on different long-memory tasks and sequence models to validate our claims. Numerical results confirm the importance of appropriate temporally rescaled error for effective long-term memory learning. To the best of our knowledge, this is the first work that quantitatively analyzes different errors' memory bias towards short-term memory in sequence modelling.

Introduction

In sequence modeling tasks such as speech recognition or time-series prediction, "memory" refers to a model's capacity to leverage information from the distant past to inform future predictions. Historically, the failure to capture long-term dependencies has been attributed to architectural limitations, such as the vanishing gradient problem in Recurrent Neural Networks (RNNs). This has led to the development of complex units like LSTMs or the adoption of Attention mechanisms.

However, this research identifies a more fundamental culprit: the error metric itself. Standard metrics like Mean Absolute Error (MAE) and Mean Squared Error (MSE) are mathematically biased toward short-term memory. By summing errors over time, these losses inherently assign greater weight to recent inputs than to distant ones, making it fundamentally difficult for any architecture to retain long-term information.

Methodology: Temporally Rescaled Error

To address this inherent bias, we propose a Temporally Rescaled Error (TPE).

Quantifying Memory Bias

We define a memory function $\rho(t)$ to represent the influence of an input at time $t$ on the output. For standard MAE, the "memory bias" $b(s)$ follows a decay of $T - s$, where $T$ is the total sequence length and $s$ is the lag. This confirms that the loss function prioritizes recent events over the start of the sequence.

Memory bias $b(s)$ across different temporal weighting parameters $p$.

The $t^p$ Weighting Scheme

We introduce a polynomial weight function $w(t) = t^p$ into the loss calculation: $$Error^{TPE} = \frac{1}{T} \sum_{t=1}^{T} t^p |y(t) - \hat{y}(t)|$$

By adjusting the parameter $p$, we can control the memory bias:

  • $p=0$: Equivalent to standard MAE, exhibiting high short-term bias.
  • $p \to \infty$: Approaches a "last-term-only" error, which is proven to be the only truly "memory-unbiased" error for linear functionals.
  • Intermediate $p$: Allows practitioners to balance unbiased long-term memory against the training stability provided by multiple data points.

Experimental Results

The proposed method was validated across synthetic tasks, the classic Copying Problem, and real-world NLP datasets.

Synthetic Linear Functionals

In experiments with linear RNNs, increasing $p$ consistently reduced the "memory difference"—the discrepancy between the target and learned memory functions. As shown in the table below, for a 64-dimension hidden state, the error significantly decreases as $p$ increases.

Memory difference results for linear RNNs across various hidden dimensions and $p$ values.

Copying Problem and Text Summarization

Using State Space Models (S4) on the Copying Problem, higher $p$ values (e.g., $p=10$) achieved significantly higher validation accuracy compared to standard cross-entropy ($p=0$).

On the LCSTS (Large-scale Chinese Short Text Summarization) dataset, the ROUGE-1 scores for the CPT model improved from 0.4535 at $p=0$ to 0.7354 at $p=10$, demonstrating that temporal rescaling scales effectively to complex, non-linear language tasks.

Conclusion

Temporal rescaling offers an architecture-agnostic approach to improving long-term memory. By simply modifying the loss function, researchers can alleviate memory bias and mitigate vanishing gradients in RNNs, TCNs, and Transformers alike. While higher $p$ values can increase optimization difficulty early in training, the resulting gains in long-term dependency retention are substantial.

Summary updated

BibTeX
@misc{wang2023improve,
  author = {Shida Wang and Zhanglu Yan},
  title = {{Improve Long-term Memory Learning Through Rescaling the Error Temporally}},
  year = {2023},
  eprint = {2307.11462},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2307.11462},
}
Figure