---
title: Dynamic Neural Turing Machine (D-NTM)
url: https://www.emergentmind.com/topics/dynamic-neural-turing-machine-d-ntm
type: topic
---

# Dynamic Neural Turing Machine (D-NTM)

The Dynamic Neural Turing Machine (D-NTM) is an extension of the Neural Turing Machine (NTM), distinguished by its introduction of a trainable memory addressing scheme that enables richer and more flexible manipulation of external memory. D-NTM maintains for each memory slot a pair of vectors—an address vector and a content vector—allowing variable, nonlinear location-based memory access strategies. The architecture supports both continuous (differentiable, "soft") and discrete (non-differentiable, "hard") memory read/write mechanisms. D-NTM exhibits superior empirical performance over prior NTM and LSTM baselines across a range of algorithmic, sequence modeling, and natural language inference tasks [1607.00036].

## 1. Architecture and Operational Principles

D-NTM utilizes an external memory $M_t \in \mathbb{R}^{N \times (d_a + d_c)}$ at each timestep $t$, where $N$ denotes the number of memory slots, $d_a$ is the address vector dimensionality, and $d_c$ is the content vector dimensionality. Each slot $i$ has an address vector $a_i\in\mathbb{R}^{d_a}$, which is trainable and fixed after initialization, and a time-varying content vector $c_{i,t}\in\mathbb{R}^{d_c}$. The overall memory structure is represented as $M_t = [A; C_t]$, with $A$ containing all address vectors and $C_t$ containing all current content vectors.

A controller (either feed-forward or recurrent) processes sequential inputs $\{x_t\}$ and previous readouts $r_t$, producing addressing parameters for read ($w_t^r$) and write ($w_t^w$) heads. Reading proceeds as a weighted sum of slot content via $r_t = M_t^\mathsf{T} w_t^r$, where $w_t^r\in\Delta^N$ is computed via learned addressing. Writing is implemented by computing an erase vector $e_t\in[0,1]^{d_c}$, a candidate add vector $\hat{c}_t$, and applying:

$$
c_{j,t} = (1 - e_t w_t^w[j]) \odot c_{j,t-1} + w_t^w[j] \hat{c}_t
$$

for each slot $j$.

## 2. Memory Addressing Mechanisms

### Continuous (Soft) Addressing

The soft addressing mechanism outputs read and write weights as differentiable distributions over memory slots. The controller computes a content-based key $k_t = (W_k)^\mathsf{T} h_t + b_k$ and a sharpening scalar $\beta_t = \mathrm{softplus}(u_\beta^\mathsf{T} h_t + b_\beta) + 1$. Each slot’s match to $k_t$ is assessed with

$$
z_t[i] = \beta_t \cdot S(k_t, M_t[i])
$$

where $S(u,v)=\frac{u \cdot v}{\|u\|\|v\|+\epsilon}$ is a cosine similarity with smoothing. To enhance locality and minimize repeated use, D-NTM employs a dynamic least-recently-used (LRU) bias. A convex interpolation parameter $\gamma_t = \sigma(u_\gamma^\mathsf{T} h_t + b_\gamma)$ and a running average $v_t$ modulate the addressing logits:

$$
w_t[i] = \mathrm{softmax}(z_t[i] - \gamma_t v_{t-1})
$$

Thus, the model interpolates between content-based retrieval and an adaptive LRU prior.

### Discrete (Hard) Addressing

The discrete addressing ("hard attention") variant samples a one-hot vector $\hat{w}_t$ from the categorical distribution $w_t$ during training, or selects the deterministic argmax at inference. This mechanism enables exact slot selection, beneficial for tasks requiring precise memory access, but introduces non-differentiability and necessitates policy-gradient optimization.

### Hybrid Addressing with Shift

D-NTM optionally supports an interpolation between content and location-based addressing (by shift), as in the original NTM. This addresses particular tasks that benefit from shifts and content addressing combined, although this feature is not central in D-NTM’s empirical analyses.

## 3. Controller Architectures

Both feed-forward and recurrent (GRU-based) controllers are supported. The controller receives the external input and previous memory readout, then emits all addressing and update parameters each timestep. In operational practice, controller hidden sizes are selected based on task complexity (e.g., $d_h\sim180$ for bAbI, $d_h=300$ for SNLI, $\sim100$ for algorithmic tasks). The input to the controller, $x_t$, can be a raw input embedding or an encoded fact vector.

The GRU-based controller offers a learnable hidden state across time, while the feed-forward controller must rely entirely on the external memory to maintain state, a distinction that has practical implications for learning dynamics and reliance on curriculum.

## 4. Training Paradigms

### Continuous D-NTM

Soft attention variants are fully differentiable, optimized end-to-end using Adam on negative log-likelihood loss, with learning rates in the range $3\times 10^{-3}$–$7\times 10^{-3}$ and batch sizes around 160.

### Discrete D-NTM (REINFORCE)

Hard attention variants necessitate REINFORCE, with the reward defined as the log-probability of correct output and normalization by running mean/std. A learned baseline $b(x)$ (trained with Huber loss) and entropy regularization are employed to reduce variance and encourage exploration. During feed-forward training, a curriculum schedule begins with soft heads and gradually anneals to fully discrete heads.

### Regularization

For controllers with recurrent state, read/write consistency penalties and next-input prediction auxiliary losses further stabilize training.

## 5. Empirical Evaluation Across Benchmarks

### bAbI Tasks

On the full set of 20 Facebook bAbI tasks ($10$K training examples per task, GRU controller):

| Model                      | 1-Step Test Error (%) | 3-Step Test Error (%) |
|----------------------------|----------------------|----------------------|
| LSTM-RNN                   | 36.4                 | -                    |
| NTM (CBA+LBA)              | 31.4                 | -                    |
| D-NTM Soft                 | 29.5                 | 24.2                 |
| D-NTM Hard                 | 27.9                 | 21.8                 |

Multi-step addressing (3-step) substantially improves test error. Discrete (hard) addressing consistently yields lower error rates when exact slot retrieval is necessary. Ablation studies confirm that learnable address vectors outperform fixed location shifts and that RNN controllers converge more easily than feed-forward ones [1607.00036].

### Sequential Permuted MNIST

On the 784-step permuted MNIST sequence task, D-NTM achieves $93.4\%$ (soft) and $92.3\%$ (hard) test accuracy, exceeding original NTM ($90.9\%$) and LSTM ($89.8\%$) baselines.

### Stanford Natural Language Inference (SNLI)

With layer normalization and dropout, D-NTM achieves a higher test accuracy ($82.3\%$) than LSTM+LN+dropout ($81.7\%$) and original NTM ($81.8\%$), though still below specialized attention baselines.

### Algorithmic Tasks

On copy and associative recall, soft D-NTM achieves cross-entropy below $0.02$; discrete D-NTM excels on copy but underperforms on associative recall, indicating a trade-off between precision and generalization in the selection mechanism.

## 6. Analysis and Key Insights

Discrete ("hard") attention converges more rapidly and supports crisp, deterministic slot access, but necessitates variance reduction strategies such as entropy regularization and input-dependent baselines. The introduction of trainable address vectors enables complex positional and conjunctive memory addressing, advancing beyond the linear shift mechanism of the original NTM. Multi-hop addressing—multiple successive read/write operations per timestep—further strengthens performance, particularly on reasoning tasks. Recurrent controllers (e.g., GRU) exploit internal state to supplement external memory, whereas feed-forward variants depend entirely on the memory module. Nevertheless, D-NTM’s write operation remains less efficient than networks that store all inputs verbatim (e.g., memory networks) for certain QA applications, indicating a persistent challenge in learning effective memory updates [1607.00036].

## 7. Limitations and Prospective Directions

Learning intricate writing and erasure patterns is challenging within D-NTM’s current architecture. Potential future improvements include the adoption of more structured write operations and stronger regularization. Addressing the high variance in policy-gradient-based discrete attention, variants such as RELAX or REBAR represent promising avenues for optimization stability. The application of D-NTM to large-scale, real-world sequence modeling tasks—such as summarization, vision question answering, and machine translation—remains unexplored and is suggested as a future direction. The model’s design illuminates core trade-offs between attention precision (benefiting hard selection) and gradient-based trainability (facilitated by soft, differentiable attention) [1607.00036].

Source: https://www.emergentmind.com/topics/dynamic-neural-turing-machine-d-ntm