Implicit Memory — RNN, LSTM, GRU
Fixed-size Hidden State · No External Access · O(1) per stepOverview
The Bottleneck. Standard RNNs compress all past history into a single fixed-dimension vector ht. This is "implicit" memory — the model has no way to address specific past events except by what survives the compression.
LSTMs. Use a dedicated cell state ct and gating mechanisms (Input, Forget, Output) to control the flow of information. While better at long-range dependencies than vanilla RNNs, they still fail at tasks requiring structured retrieval (like copying long strings).
Chomsky Hierarchy. RNNs are theoretically equivalent to Finite State Automata (Regular Languages). LSTMs can emulate counters (anbn), but struggle with full Context-Free or Context-Sensitive tasks because their memory cannot grow with input size.
One Forward Pass — LSTM
d_h=2 · forget / input / candidate / output gatesTransformers — Attention as Memory
Fixed Context Window · Key-Value Retrieval · O(N²) TrainingOverview
Soft Memory. Transformers treat the entire context window as a memory. Each token is a memory slot. Attention is the addressing mechanism.
Static vs Dynamic. Unlike NTM/DNC, Transformers do not write to their memory during a forward pass. The "memory" (KV cache) is just the representations of previous tokens. New information cannot be stored in old slots.
Computational Limits. While Transformers excel at Regular and some DCF tasks within their window, they cannot generalize to sequence lengths beyond what they were trained on (Position Encoding limit), unlike Stack-RNNs or Tapes which can theoretically grow.
One Forward Pass — Self-Attention
3-token sequence · d_k=d_v=4 · query token: "cat" (pos 1) attending to all| pos | token | embedding x (d=4) | role |
|---|---|---|---|
| 0 | the | [0.1, 0.9, 0.2, 0.5] | provides K[0], V[0] |
| 1 | cat | [0.7, 0.3, 0.8, 0.4] | ← query token this step |
| 2 | sat | [0.5, 0.6, 0.1, 0.9] | provides K[2], V[2] |
Neural Execution Engine — Yan et al. (2020)
Algorithmic Primitives · Engine Selection · Soft Modular ExecutionOverview
Yan 2020Core idea. Learning to execute algorithms by factoring execution into a small set of primitive engines. Instead of learning a monolithic function, NEE trains a controller that selects and blends pre-specified operations — analogous to a CPU dispatching micro-ops from a fixed instruction set.
Engines. Each engine is a lightweight feedforward net (or learned linear map) that maps the current state to a new state for its specific operation — ADD, SWAP, INC-POINTER, COPY, etc. The engine set is designed by the researcher to match the algorithm family. The networks learn how to execute each primitive; the controller learns which primitive to apply when.
Controller. An LSTM reads the current state and emits a probability distribution over engines at each execution step. During the forward pass, all engines run in parallel and their outputs are blended by these probabilities. Gradient flows through every engine every step — even low-weight engines receive signal — which stabilises early training.
Sharpening toward discrete. The soft blend during training makes controller gradients dense. At test time the distribution can be sharpened (or converted to argmax) to recover an exactly discrete, interpretable program trace. This soft-to-hard curriculum is what allows NEE to generalise to longer sequences than seen during training.
Task fit. Best suited to tasks where the algorithm decomposes into a known fixed primitive set: multi-digit addition and multiplication, pointer-based sorting, and register-machine computation (Yan 2020). The number of execution steps T is fixed; algorithms that need more steps require either increasing T or hierarchically nesting engines within engines.
One Execution Step: Pointer-Based Arithmetic
State S = [A, B, P] · A,B=Registers, P=Pointer[15.0, 5.0, 0.0]
[5.0, 10.0, 0.0]
[10.0, 5.0, 1.0]
Snew = [10.5, 3.5, 0] + [1.0, 2.0, 0] + [1.0, 0.5, 0.1]