Neural Turing Machine — Graves (2014)
N×M Matrix · Content + Location Addressing · Read & Write HeadsOverview
Graves 2014Core idea. External memory is a 2D matrix M of shape N×W (N locations, each a W-dimensional row vector). A controller LSTM emits interface parameters each timestep to position soft attention heads anywhere over the N rows — no constraint to read/write only the top.
Addressing. Two-stage: (1) content addressing — compute cosine similarity between a key vector and every memory row, apply softmax → content weights. (2) location addressing — optionally interpolate with the previous head position, then convolve with a learned shift kernel, then sharpen. Together they allow both associative lookup and sequential scanning.
Reading. The read head returns
r = MTw — a weighted sum of memory rows using the attention
weights w. This is fully differentiable.
Writing. The write head first erases:
M ← M ⊙ (1 − w·eT), then adds:
M ← M + w·aT. Erase vector e and add vector a
are both output by the controller.
Multiple heads. There can be R read heads and W write heads, each with independent addressing. All reads happen before all writes each timestep.
One Forward Pass
N=4 locations · W=3 dims · single read head + single write head| loc | d0 | d1 | d2 | content tag |
|---|---|---|---|---|
| M[0] | 0.8 | 0.2 | 0.5 | ← high attention |
| M[1] | 0.1 | 0.9 | 0.3 | medium |
| M[2] | 0.6 | 0.4 | 0.7 | low |
| M[3] | 0.0 | 0.0 | 0.0 | empty |
| loc | d0 | d1 | d2 | ww | status |
|---|---|---|---|---|---|
| M[0] | 0.646 | 0.690 | 0.430 | 0.70 | rewritten |
| M[1] | 0.182 | 0.970 | 0.312 | 0.20 | lightly touched |
| M[2] | 0.597 | 0.448 | 0.679 | 0.08 | almost unchanged |
| M[3] | 0.010 | 0.016 | 0.006 | 0.02 | nearly unchanged |
Differentiable Neural Computer — Graves (2016)
Usage-based Allocation · Temporal Linkage · Freeness Tracking · Multiple R/W HeadsOverview
Graves 2016Core idea. The DNC extends the NTM with three additional mechanisms: (1) a usage vector u tracking how much each location has been written to, (2) a temporal link matrix L recording the order in which locations were written, and (3) a freeness vector f that releases locations when read-weights dealloc them.
Allocation addressing. Instead of the NTM's shift convolution, the DNC allocates free locations by sorting them by usage. The least-used (most free) location gets the highest allocation weight. This prevents memory fragmentation without needing sequential structure.
Write addressing. A gated blend of content-based
address and allocation address:
ww = gw·(ga·a + (1−ga)·wc)
where gw is write gate and ga is allocation gate.
Temporal links. After each write, the link matrix
L updates: L[i,j] is the degree to which location i was written just after
j. This enables forward and backward traversal through previously written sequences —
the read head can "follow the chain."
Read modes. Each read head blends three orientations: content-based wc, forward link πf·Lwr, and backward link πb·LTwr. Soft mode weights π are output by the controller.
Write before read. Within each timestep the DNC writes first, then reads. This is intentional: the read vector rt is part of the current output yt = Wy[ht; rt], so reading from the already-updated Mt lets the model store a value and immediately reflect it in the same step's output. The temporal link Lt must also be updated before reading so that forward/backward traversal includes the current write. The cost: write and read keys are both derived from the same ht, so the model cannot react to the content it just wrote within the same step.
One Forward Pass
N=4 locations · R=1 read head · W=1 write head · shows allocation + temporal linkage| loc | d0 | d1 | d2 | usage u | free ψ |
|---|---|---|---|---|---|
| M[0] | 0.9 | 0.1 | 0.4 | 0.95 | 0.05 |
| M[1] | 0.3 | 0.7 | 0.2 | 0.70 | 0.30 |
| M[2] | 0.1 | 0.2 | 0.1 | 0.20 | 0.80 |
| M[3] | 0.0 | 0.0 | 0.0 | 0.02 | 0.98 |
| L[i\j] | j=0 | j=1 | j=2 | j=3 |
|---|---|---|---|---|
| i=0 | 0.0 | 0.9 | 0.0 | 0.0 |
| i=1 | 0.9 | 0.0 | 0.0 | 0.0 |
| i=2 | 0.0 | 0.0 | 0.0 | 0.0 |
| i=3 | 0.0 | 0.0 | 0.0 | 0.0 |
Neural RAM — Zaremba & Sutskever (2016)
Discrete Addresses · Hard or Soft Access · Register File · Branching ProgramsOverview
Zaremba 2016Core idea. Neural RAM (nRAM) models a register-based random-access machine. Memory consists of a fixed set of integer-indexed slots. The controller emits a discrete address (argmax or Gumbel-softmax over N locations) rather than a continuous attention distribution — trading differentiability for sharpness.
Registers. A small set of R registers hold working values. Each timestep the controller (1) loads from memory into a register, (2) applies an ALU-like function (add, subtract, copy, compare), and (3) stores a register value back to memory. The program is a sequence of such micro-operations.
Addressing. Content-free — addresses are positional integers, not similarity lookups. The controller directly outputs a distribution over [0…N−1] and selects an address. This means reading a value requires knowing (or learning) where it was stored, not what it contains.
Soft vs hard. Training uses a soft (weighted) relaxation of discrete addressing so gradients flow. At test time, the argmax is used — one location, zero cost. The gap between soft training and hard inference is smaller than in NTM because the distribution is already very sharp.
Use case. Best for learning algorithms that are intrinsically positional: sort by index, random swap, array reversal. Content-based lookup (e.g., find a value equal to a key) is harder without similarity addressing.
One Forward Pass (one micro-operation step)
N=6 memory slots · R=3 registers · instruction: LOAD r2 ← mem[addr] then ADD r0 ← r0 + r2| addr | value | note |
|---|---|---|
| 0 | 12 | M[0] |
| 1 | 7 | M[1] |
| 2 | 23 | target |
| 3 | 0 | M[3] |
| 4 | 5 | M[4] |
| 5 | 0 | M[5] |
| reg | value | role |
|---|---|---|
| R0 | 35 | accumulator |
| R1 | 2 | ptr |
| R2 | 0 | scratch |
Hard (inference): read = M[argmax] = M[2] = 23 exactly.
Gradients flow during training through the weighted sum; inference snaps to one slot.
| addr | value | status |
|---|---|---|
| 0 | 58 | updated ✓ |
| 1 | 7 | unchanged |
| 2 | 23 | unchanged |
| 3 | 0 | unchanged |
| 4 | 5 | unchanged |
| 5 | 0 | unchanged |
Lie-Access NTM — Yang & Rush (2016)
Lie Group Manifold · Geometric Addressing · Group-Action Navigation · SO(2) / SE(2)Overview
Yang & Rush 2016Core idea. Replace the flat integer address space with a Lie group manifold. Each memory cell is pinned to a point on the manifold (a group element gk ∈ G). The read/write head also lives on the manifold. Moving the head means multiplying its current position by a learned group element δ — a group action, not an index increment.
Lie groups used. Typical choices: SO(2) — the circle of rotations in 2D (parameterised by one angle θ); ℝn — translations (recovers NTM-style shift); SE(2) — rotation + translation (richer 2D plane). The group law encodes the geometry: on SO(2), "move by δ" means θ ← θ + δ mod 2π.
Attention. At each timestep, similarity between head position h and each cell address gk is measured by the group metric d(h, gk) = ‖log(h−1gk)‖. A softmax over −β·d(·) gives attention weights wk. Small d → high weight.
Navigation. The controller outputs a "step" δ ∈ G (via a learned map). The head updates: ht+1 = ht · δ. On SO(2) this is just θt+1 = θt + δ. The model can learn complex traversal patterns — e.g., a zigzag (alternating +90°, −90°) to visit odd-indexed cells before even ones (oddFirst task).
Read & write. Once attention weights are computed from geometry, reading and writing are identical to NTM: r = Σ wk·vk; write via erase+add. The only change is how w is computed — geometry replaces cosine similarity.
One Forward Pass
G = SO(2) · K=8 cells equally spaced on circle · head at θ=45° · step δ=+90°| cell k | angle gk | value vk (scalar shown) | d(h, gk) at h=45° |
|---|---|---|---|
| k=0 | 0° | 0.8 | 45° |
| k=1 | 45° | 0.3 | 0° ← head here |
| k=2 | 90° | 0.5 | 45° |
| k=3 | 135° | 0.9 | 90° |
| k=4 | 180° | 0.1 | 135° |
| k=5 | 225° | 0.4 | 180° |
| k=6 | 270° | 0.6 | 135° |
| k=7 | 315° | 0.2 | 90° |
lie_exp converts a Lie algebra vector (tangent
space) into a group element. For SO(2) this is simply exp(iθ), i.e., a rotation
by angle θ. The group element is never stored as Euler angles — it lives on the
manifold.
Comparison
(NTM · DNC · Neural RAM · Lie-Access)Side-by-side property table
Key architectural decisions distinguishing the four matrix-memory (random-access) designs.
| Property | NTM — Graves 2014 | DNC — Graves 2016 | Neural RAM — Zaremba 2016 | Lie-Access NTM — Yang 2016 |
|---|---|---|---|---|
| Memory repr | N×W float matrix fully soft, all locations active |
N×W float matrix + usage u, precedence p, link L |
N integer-indexed slots + R small register file |
K cells on Lie group manifold each pinned to group element gk ∈ G |
| Read addressing | Content (cosine) + Location (shift) 2-stage; soft weighted sum over N |
Content + Forward link + Backward link 3-mode blend via π weights |
Positional (integer address) soft during train, hard at test |
Geometric — group distance d(h,
gk) softmax(−β·d); head lives on manifold |
| Write addressing | Same 2-stage as read (independent head) separate key / shift / gate |
Allocation (freest slot) + Content
blend ga gates between them |
Separate positional address controller outputs store-addr dist |
Same geometric weights as read head single head (read + write share position) |
| Write operation | Erase vector then add vector M ← M⊙(1−w·eT) + w·aT |
Same erase+add also updates usage u, link L, precedence p |
Hard overwrite or soft blend M[addr] ← reg value |
NTM erase+add vk ← vk⊙(1−wk·e) + wk·a |
| Memory management | None — model must learn not to clobber no usage tracking |
Explicit usage tracking + freeness
gates free gate on reads; alloc writes to least-used |
None — positional, no overlap guard model learns not to alias |
None — cells at fixed manifold
addresses geometry prevents unintended overlap if cells spaced far apart |
| Temporal traversal | Location shift (left/right by 1) limited to local neighbours |
Forward / backward link matrix L follows write-order chain, not spatial |
Implicit — controller increments pointer
register INC/DEC on address register |
Group action h ← h·δ on manifold any group element reachable in one step; zigzag, spiral, etc. |
| Attention type | Always soft — weighted sum over all N never argmax |
Always soft — weighted sum never argmax |
Soft train / hard test Gumbel-softmax bridges the gap |
Soft — geometric softmax β controls sharpness; β→∞ = hard nearest cell |
| Best suited for | Copy, sort, associative recall where content lookup matters |
Algorithms with structured access
patterns graph traversal, question answering, replay |
Positional algorithms, arithmetic addition, sorting by index, pointer arithmetic |
Tasks with geometric structure in access
pattern oddFirst, skip-k, spiral traversal, rotation-invariant tasks |
| Controller | LSTM (or FF) output = f(ht, read vectors) |
LSTM richer interface vector (usage gates, mode π) |
LSTM also receives register file as input |
LSTM outputs Lie algebra vector → exp map → δ ∈ G |
| Chomsky class | Context-sensitive & beyond sufficient for Turing-complete tasks |
Context-sensitive & beyond arguably stronger due to link traversal |
Context-sensitive & beyond discrete RAM = Turing machine if T unbounded |
Context-sensitive & beyond same capacity as NTM; group structure aids inductive bias |