---
title: Pointer Sentinel Mixture Model (PSMM)
url: https://www.emergentmind.com/topics/pointer-sentinel-mixture-model-psmm
type: topic
---

# Pointer Sentinel Mixture Model (PSMM)

The Pointer Sentinel Mixture Model (PSMM) is a neural sequence modeling architecture that combines a standard RNN-based language model with a pointer mechanism gated by a learned sentinel vector. The architecture addresses the challenge of predicting rare or previously unseen words in language modeling, which are difficult to generate with conventional softmax classifiers, by enabling the model to either select tokens from recent context or generate new tokens from a global vocabulary distribution [1609.07843].

## 1. Architecture and Intuition

At each time step $t$, PSMM processes an input embedding $x_t$ through an RNN (typically an LSTM), updating its hidden state:
\[
h_t = \mathrm{RNN}(x_t, h_{t-1}) \in \mathbb{R}^H
\]
From $h_{t-1}$, the architecture produces two distinct next-token distributions:
- A standard softmax over a fixed vocabulary ("vocabulary" component).
- A pointer distribution over the $L$ most recent positions in the input ("pointer" component).

The final output distribution is a mixture:
\[
p(w_t) = g_t\,p_{\mathrm{vocab}}(w_t \mid h_{t-1}) + (1 - g_t)\,p_{\mathrm{ptr}}(w_t \mid h_{t-1}, \text{context})
\]
Here, $g_t \in [0,1]$ is a scalar gate computed by introducing a learned "sentinel" into the pointer’s attention mechanism. Intuitively, when $g_t$ is close to 1, the model defers to the softmax; when $g_t$ is 0, it employs the pointer for "copying" from recent context.

## 2. Mathematical Formulation of the Mixture

### Softmax (Vocabulary) Distribution

The vocabulary component derives from the softmax layer:
\[
p_{\mathrm{vocab}}(w \mid h) = \mathrm{softmax}(U h)_w,\quad U \in \mathbb{R}^{V \times H}
\]
with $V$ the vocabulary size.

### Pointer (Attention) Distribution

The pointer distribution is calculated via an attention mechanism as follows:
- Construct a "query" vector:
  \[
  q_t = \tanh(W h_{t-1} + b),\quad W \in \mathbb{R}^{H \times H},\; b \in \mathbb{R}^H
  \]
- Score the last $L$ hidden states:
  \[
  z_i = q_t^\top h_{t-L+i},\quad i=1,\ldots,L
  \]
- Include the sentinel vector $s \in \mathbb{R}^H$ to augment the scores:
  \[
  \tilde{z} = [z_1, \ldots, z_L,\, q_t^\top s] \in \mathbb{R}^{L+1}
  \]
- Normalize with softmax to yield attention weights $a \in \mathbb{R}^{L+1}$:
  \[
  a = \mathrm{softmax}(\tilde{z})
  \]
  The gate $g_t = a_{L+1}$ is the attention on the sentinel; the remainder is distributed among contextual positions.

- The probability of copying word $w$ from the context:
  \[
  p_{\mathrm{ptr}}(w \mid \cdot) = \frac{1}{1-g_t}\sum_{i\in I(w)} a_i
  \]
  where $I(w)$ is the set of positions among the last $L$ steps where word $w$ occurs.

### Final Mixture

\[
p(w_t \mid h_{t-1}, \mathrm{context}) = g_t p_{\mathrm{vocab}}(w_t \mid h_{t-1}) + (1-g_t) p_{\mathrm{ptr}}(w_t \mid h_{t-1}, \mathrm{context})
\]

## 3. Computation of the Sentinel Gate

The sentinel is a learned vector $s \in \mathbb{R}^H$. The attention score for the sentinel, $q_t^\top s$, is appended to the contextual scores before softmax normalization. The gate is given by:
\[
g_t = a_{L+1} = \frac{\exp(q_t^\top s)}{\sum_{i=1}^L \exp(q_t^\top h_{t-L+i}) + \exp(q_t^\top s)}
\]
This computation ensures the mixture weight $g_t$ is always aware of what the pointer branch can retrieve, allowing a context-sensitive balance between pointing and generating.

## 4. Training Objective and Optimization

PSMM minimizes the negative log-likelihood of the true next token $y_t$:
\[
\mathcal{L}_t = -\log p(y_t \mid h_{t-1}, \mathrm{context})
\]
Gradients are distributed naturally throughout both branches—RNN/softmax (via $p_{\mathrm{vocab}}$ and sentinel) and pointer (via $a_i$). In practice, probability is only explicitly evaluated for the target token for computational efficiency:
\[
p(y_t) = g_t\,p_{\mathrm{vocab}}(y_t) + (1-g_t) \sum_{i \in I(y_t)} a_i
\]
Backpropagation through time (BPTT) is extended up to window length $L$ so the pointer can attend sufficiently far back into the hidden state sequence.

## 5. Empirical Results and Parameter Overhead

The pointer sentinel-LSTM (PS-LSTM) demonstrates strong empirical performance:
- On Penn Treebank (20M parameters, 2×650 layers, $L=100$): validation perplexity 72.4, test perplexity 70.9.
- On WikiText-2 (same configuration): validation perplexity ≈ 84.8, test ≈ 80.8.

These results surpass a variational LSTM with significantly more parameters (66M; test ≈ 75.2) and zoneout+variational LSTM baselines. The parameter overhead is modest: in addition to the base LSTM, only $W \in \mathbb{R}^{H \times H}$, $b \in \mathbb{R}^H$, and $s \in \mathbb{R}^H$ are added, a small fraction of a standard LSTM layer’s parameter count [1609.07843].

## 6. Ablation, Analysis, and Contextual Behavior

Ablation experiments reveal a substantial gain in perplexity attributable specifically to the pointer-sentinel mixture. On PTB, adding PSMM to a zoneout+variational LSTM (with $L=100$) reduces test perplexity from 80.6 to 70.9. Detailed breakdown shows the largest improvements on less frequent words, with robust gains observed across token frequency spectrum. Visual analysis demonstrates that the gate $g_t$ is consistently low when copying is advantageous (e.g., rare names, repeated entities), while remaining high for common tokens. The pointer mechanism can reach well beyond standard BPTT horizons, with the sentinel effectively gating access to distant context windows, enabling the model to "copy when it makes sense, otherwise generate" [1609.07843].

Source: https://www.emergentmind.com/topics/pointer-sentinel-mixture-model-psmm