Temporal State and Memory › Recurrent Memory
World Models HandbookAll chapters Temporal State and Memory › Recurrent MemoryOne section · Sections in this chapter4 / 12 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Recurrent networks are a standard learned answer to the compression problem: a fixed-size state updated one step at a time. This section covers how recurrence works, why plain recurrence can struggle over long horizons, and how gated architectures provide a more direct retention path.
Recurrence as Learned Compression
The workhorse solution is a recurrent state: a fixed-size vector updated step by step,
where:
- : the recurrent state at time , a fixed-size vector summarizing the history
- : the previous recurrent state, carrying everything absorbed so far
- : the current observation
- : the action taken at the previous step
- : a neural network, with parameters , that decides how to merge the new observation and the last action into the running summary
Everything the model "knows" about the past lives in ; the history itself is discarded after being absorbed. This is the compression decision in its purest form: one fixed-size vector stands in for an arbitrarily long past, and the network is the sole arbiter of what makes it into the summary. Prediction then proceeds from the recurrent state:
where:
- : the predicted next observation (the hat marks a prediction, as opposed to the observed )
- : the predicted next reward
- : the observation head, a network with parameters mapping the recurrent state and a candidate action to the next-observation prediction
- : the reward head, mapping the same inputs to the predicted reward
- : the recurrent state defined above
- : the action whose consequences are being predicted
Notice that the prediction heads condition on both the recurrent state and the proposed action. They therefore produce action-conditional predictions, and a planner can compare candidate actions by running the heads. Interpreting those predictions as causal consequences additionally requires the data and model to identify the effects of intervening on the action. A policy or planner can operate on the same . This is exactly the structure of the recurrent state-space models we will build in detail in Part V, Chapter 1; here we focus on the memory inside the recurrence, not the full world-model architecture.
Conceptually, a recurrent network is doing online compression: at every step it decides, implicitly, which parts of the new observation to merge into the running summary and which parts of the old summary to discard. The compression is shaped by the training objective and data. When trained for the role, can approximate a belief-like filter, a running integral, or a short-term buffer. The catch is that nothing in the architecture guarantees retention over the task horizon. Gated architectures provide a more direct retention path, but optimization must still learn when to use it.
The Long-Range Gradient Problem
To see why plain recurrence struggles, consider what training demands. If the correct action at step depends on a cue at step , then the loss at step must send gradients back through every intermediate hidden state. Learning to preserve the cue means learning weight values for which the cue's influence survives that chain, and whether such weights are discoverable by gradient descent depends on the geometry of the chain itself. For a simple recurrent update , the derivative of the final state with respect to the initial state is a product of Jacobians:
where:
- : the hidden state at the step where the cue arrives
- : the hidden state at the step where the loss is computed
- : the Jacobian of recurrent step , the matrix of partial derivatives describing how each component of influences each component of
- : the ordered product of these matrices, with the latest step on the left, chaining the cue's influence from step to step
- : the input at step (for a world model, typically the current observation together with the last action)
- : the recurrent weight matrix, multiplying the previous hidden state
- : the input weight matrix, multiplying
For matrix-valued, time-varying Jacobians, growth depends on the product's singular directions as well as the norm of each factor. A useful bound is
Thus uniformly contractive factors are sufficient for decay, while factors with norm above one make growth possible but do not force it: directions can rotate, contract, or cancel. The scalar constant-gain model below isolates the basic effect. If every step multiplies a scalar signal by , its magnitude after steps is : it decays when , stays constant when , and grows when . Over 50 steps, , about 0.515 percent of the initial magnitude.
We can make the scalar approximation concrete with a simple computation. The plot shows decay (), constancy (), and growth () over 50 steps. It illustrates repeated scalar gain, not the exact behavior of every recurrent Jacobian product.
import numpy as np
horizons = np.arange(1, 51)
rho_values = [0.9, 1.0, 1.1]
grad_norms = {rho: rho ** horizons.astype(float) for rho in rho_values}
In this scalar illustration, a ten-percent change around one produces orders-of-magnitude differences over a corridor-length span. Gated additive updates are a widely used way to give optimization a controllable near-identity path. They make long-range retention easier to learn, but they are not necessary: other recurrent parameterizations and explicit memory mechanisms can also preserve long dependencies.
Without such a path, the network may need to learn retention through the same long Jacobian chain that attenuates its training signal.
Gating: Additive Memory Channels
Long short-term memory (LSTM) networks and gated recurrent units (GRUs) attack the problem by changing the shape of the update. Instead of always overwriting the state through a squashing nonlinearity, they introduce an additive channel guarded by learned gates. The key insight is that an additive update, one that adds new content to old content rather than replacing it, provides a gradient path whose gain can be held near one, so information can flow across many steps without exponential decay. For an LSTM, the core equations are:
where:
- : the input at step , for a world model typically the current observation together with the last action
- : the previous hidden state, the network's working output
- : the cell state, the protected long-term memory carried across steps
- : the candidate value, a proposal for new information to write into the cell state
- : the input gate, controlling how much of the candidate is written into the cell state
- : the forget gate, controlling how much of the previous cell state survives
- : the output gate, controlling how much of the cell state is exposed as the hidden state (written rather than the conventional to avoid clashing with the observation symbol used elsewhere in this chapter)
- : the new hidden state, the gated readout of the cell state
- : the logistic sigmoid, which maps any real number to so each gate acts as a soft switch
- : elementwise multiplication
- and : weight matrices acting on the input and on the previous hidden state; : their bias vectors
Look at the cell-state update . It is a residual update: when the forget gate is near and the input gate near , information flows through the direct cell-state branch nearly unchanged. Across several such steps, the direct gain is the product of the forget gates, so quantitative retention still depends on how close each gate remains to one. In the corridor, the desired behavior is to write the cue at step 0, preserve it during the featureless walk, and expose it at the decision point. Because the gates depend on the input and hidden state, gradient-based training can learn a write-and-retain policy, provided the objective supplies a useful signal.
The GRU is a streamlined variant with a single update gate and a reset gate :
where:
- : the update gate, blending how much of the old state is kept versus replaced by the candidate
- : the reset gate, controlling how much of the old state the candidate can consult
- : the candidate hidden state, the proposed new content
- and : weight matrices acting on the input and on the previous state (biases omitted for brevity)
- and : the logistic sigmoid and elementwise multiplication, as in the LSTM equations
Notice that the GRU hidden state itself now has the residual form: the update is an interpolation between keeping and replacing, so the direct "keep" branch has gain . The GRU merges the LSTM's separate cell and hidden states into one, using three affine gate/candidate groups where the displayed LSTM uses four. Which architecture performs better is task-dependent. The LSTM's output gate controls how much cell content is exposed as , but it does not isolate the cell completely: feeds the next step's gates and candidate, so noisy exposed state can still influence indirectly.
It is often useful to give the model two coupled recurrent states: a fast state updated every step (carrying recent context) and a slow state updated rarely or with strong damping (carrying cues and integrals). This is the architectural answer to the tension we identified in "What Must Survive the Compression": rather than forcing one vector to serve constancy, accumulation, and turnover simultaneously, give each dynamical role its own compartment and couple them. Hierarchical recurrent models make this split explicit, updating the slow state every steps or on event boundaries, which also shortens the gradient path each timescale must span. The same idea reappears in modern state-space models with multi-timescale dynamics, covered in Part V, Chapter 2.
Training Practicalities That Shape Memory
Two training choices quietly influence how good the learned memory is. They are easy to overlook because they do not appear in the architecture diagram:
- Truncated backpropagation through time (TBPTT). Unrolled gradients are cut at a window of length , so a loss cannot assign credit directly through more than recurrent transitions. This is not a hard bound on forward memory: hidden state can be carried across windows, and shorter-range or auxiliary losses can teach a retention rule that generalizes farther. But a terminal-only 50-step dependency receives no direct cue-to-loss gradient when , which can make it difficult to learn. Treat as a credit-assignment limit and test retention at the horizon the task needs.
- Scheduled or curriculum length. Training first on shorter episodes and then extending the horizon can help optimization. One plausible explanation is that shorter examples first establish useful update behavior, which longer examples then refine. That mechanism is a hypothesis unless an ablation separates it from data ordering, regularization, and other optimization effects.
A related trap: if observations occasionally contain the needed cue deterministically and observably, the model can learn memory. If the cue is buried in noise, or appears only under rare action sequences, the data distribution itself may never teach the gates to open. Memory learning is a joint property of architecture, gradient budget, and data distribution. When a memory model fails, before concluding that the architecture is inadequate, check whether the training signal demanded retention, and check whether the truncation window ever spanned the dependence in question.