Don't summarize the input — point at it.
A standard attention model uses its attention weights to blend the encoder's hidden states into one context vector, then predicts the next word from a fixed vocabulary. Pointer Networks change one line of that recipe: keep the attention weights, but stop blending. Read the weights directly as a probability distribution over the input positions, and emit the position that scores highest.
That one change has an outsized payoff. The output is no longer a token
from a fixed dictionary — it is an index back into the input itself.
So the answer space can be different on every example: feed in n
points and the model can point to any of those n positions,
for any n it has never seen. Problems whose valid answers
depend on the current input — sorting, convex hulls, routes — suddenly fit.
Attention used to be the glue that summarized the input. Here it becomes the finger that picks pieces of the input out.
The puzzle plain seq2seq can't solve
What is this thing for, and what shape is the problem?
Step 1 · The black box
Points go in, a fence comes out — as a list of indices.
Here is the whole task in one picture, and it is the example that will follow us through every step. We scatter five points on a sheet of paper and ask for their convex hull — the smallest fence (convex polygon) that wraps all of them, like a rubber band snapped around nails. Four points end up on the fence; one sits strictly inside.
Notice what the answer is made of: not new symbols, but the numbers
1 2 3 4 — labels of points we were just handed. The arrows
⇒ and ⇐ are only "start" and
"stop" markers. Everything in the answer is a finger pointing back at
something in the input.
The paper trains the very same architecture, with no task-specific rules, to also produce Delaunay triangulations (carve the points into non-overlapping triangles) and short Travelling Salesman tours (visit every point once and come back). Three classic geometry problems, one model, learned from input–output pairs alone.
Step 2 · Why the obvious approach jams
A fixed output vocabulary can't name a moving target.
We have the task — point at hull vertices. Before the fix, see exactly where the standard recipe breaks.
A 2014-era sequence-to-sequence model (read
an input sequence with one network, write an output sequence with
another) ends each step the same way: a softmax over a
fixed list of output symbols decided before training. For
translation that list is the German vocabulary — large, but it never
changes from sentence to sentence.
Convex hull breaks that assumption. With 5 input points
the answer must choose among 5 labels; with 50
points, 50 labels; with 500, five hundred.
The size of the answer space is the input length, and it differs
on every single example. A softmax sized once, up front, simply has no
slot to point at the 137th input point if it only ever saw 50.
The paper's words: these methods "require the size of the output dictionary to be fixed a priori," so they "cannot directly apply … to combinatorial problems where the size of the output dictionary depends on the length of the input." That is the wall Pointer Networks walk through.
Step 3 · The shape of the machine
Read all the points, then emit one index at a time.
The blocker is the fixed output list. The fix lives in the decoder's final step — but first, the overall shape both models share.
Like ordinary seq2seq, a Pointer Network has two recurrent halves
(the paper uses single-layer LSTMs — a kind of recurrent
cell that carries memory across steps). The encoder reads the
input points one by one, feeding in each point as its raw
(x, y) coordinates, and leaves behind one hidden state
ej per point. The decoder then writes
the answer, producing one hidden state di per
output step.
At every output step the decoder looks back over all the encoder states and scores each input position. In a plain attention model those scores would be turned into one blended summary. The whole twist — coming in Part B — is what the Pointer Network does with the scores instead.
The pointer mechanism
One step changes — and that step is the whole paper.
Step 4 · Blend versus point
Same scores, opposite endings: average them, or pick one.
We have the skeleton and the scores. Here is the fork in the road — the single design choice that separates the two models.
Both models start identically. At decoder step i they
compute a relevance score uj for every input
position j, then run softmax to turn those
scores into weights aj that sum to 1. The
split happens in what comes next.
Standard attention — blend
The weights multiply the states and add them up. The output feeds the next layer.
Pointer Network — point
The same weights are read as a distribution over positions. The argmax is emitted as the output index.
Step 5 · Compute one pointer by hand
Score every point, soften the scores, read off the winner.
"Point at the highest score" is the idea. Now do it for real, on our five points, one decoder step at a time.
We are at decoder step 1. The model has just started writing the fence
and needs its first vertex — by the paper's convention, the hull point
with the lowest index, which here is point 1. For each input position
j the decoder produces a raw score
uj (these are illustrative logits; the real
ones come from the formula in Step 6). Then softmax turns
the five scores into a probability over the five points, and the
biggest probability is the pointer.
Click a point (or a bar) to see the pointer land — Step ▸ walks the whole fence.
softmax over input positions
Decoder step 1 — pointing at the first hull vertex.
What to watch: the pointer is just the tallest bar. As you step, the output grows one index at a time — {⇒, 1, 2, 3, 4, ⇐} — and point 5, sitting inside, is never the winner.
Why does the tallest score win so decisively? Because
softmax turns differences into exponentials. Take just two
of the scores — say point 1 at 3.2 versus point 2 at
1.1. The weight on point 1 is
e3.2 / (e3.2 + e1.1),
and a gap of 2.1 already pushes it to 89%. Drag the two
scores and feel the lever:
Move either score — watch a small lead become a confident pointer.
What to watch: equal scores split 50/50; a lead of about 2 already buys ~88%. The pointer is sharp because softmax is exponential.
Step 6 · The score, written down
The whole mechanism is two short lines — and one of them is just softmax.
You just produced pointers by hand. Here is the formula that produced the scores you used — and you will see you already did it.
The score uj for input position j
at decoder step i is the paper's additive
attention (a small learned network that compares two vectors):
mix the encoder state ej with the decoder
state di through two matrices, squash with
tanh, and project to a single number with a vector
v.
v is a vector; W1, W2 are square matrices (encoder and decoder share one hidden size, typically 512).
That is the entire pointer. The first line is the score you read off
the bars in Step 5; the second line is the softmax you already ran by
hand. Ci is the output at step i —
an index into the input, not a token from a vocabulary.
Standard attention has the exact same first line. It then adds
a third line — d′i = Σj
aij ej — blending the states into
a context vector. Pointer Networks delete that line and keep the
softmax as the output. Same math; the interpretation flips from
weighting to selecting.
Step 7 · From one pointer to a sequence
Feed each chosen point back in, and the fence draws itself.
One step gives one index. A convex hull is a list of indices — so we loop, and each choice conditions the next.
After step 1 points at point 1, the model feeds that choice back into
the decoder, advances to d2, and scores all
positions again — now biased to continue the fence counter-clockwise,
so point 2 wins. Then point 3, then point 4. When the scores favour
the stop marker ⇐, the sequence ends. The hull
{⇒, 1, 2, 3, 4, ⇐} has been written entirely
out of input indices.
Step 8 · Why it stretches to unseen sizes
Nothing in the pointer is tied to a fixed length.
We have a working loop. The quiet superpower is that the very same loop runs on inputs longer than anything it trained on.
Look back at the formula: it scores each input position with
the same little network v⊤tanh(W1ej
+ W2di), then softmaxes over however many
positions there are. Add a sixth point and the loop simply scores six.
There is no fixed-size output layer to retrain — the output layer
is the input.
So a model trained only on point sets of size 5 to 50 still produces
sensible hulls at n = 100, 200, even
500 — far past anything it saw. That is strong evidence
the network learned the geometry of "what makes a fence,"
not a lookup table keyed on length.
A variable-size output dictionary falls out for free: every output is
an index into the current input, so a single trained model handles
n = 5 and n = 500 with identical weights.
This is exactly what blocked plain seq2seq and Neural Turing Machines
on these tasks.
Does it work — and what did it start?
The numbers, the three tasks, and the lineage.
Step 9 · The scorecard
Pointing beats blending — and the fence is right even when the index list isn't perfect.
We understand the mechanism. Now the evidence: on convex hull at n = 50, all three approaches share the encoder — only the last step differs.
"Accuracy" here is strict: the predicted index sequence must match
exactly. "Area" is gentler: how much of the true hull's area the
predicted polygon covers. Watch the gap between a plain
LSTM, an attention-blended LSTM, and the
Pointer Network.
Exact-sequence accuracy
Generalization, in one row: train on point sets of size 5–50, test far
beyond. Exact accuracy fades as expected — 92% at
n = 5, 69.6% at 50,
50.3% at 100, 1.3% at
500 — yet area coverage stays above 99% the
whole way. The fence keeps being nearly right long after naming every
vertex in order becomes hard.
Step 10 · Three problems, one network
The same pointer learns hulls, triangulations and tours.
One task proved the idea. The paper's real flex is that nothing about the architecture is hull-specific.
Change only the training data — same encoder, same decoder, same pointer — and the network learns three different bits of computational geometry, purely from examples:
Convex hullwrap the points
Output = the fence's vertex indices, counter-clockwise. 72.6% exact / 99.9% area at n = 50.
Delaunaytriangulate
Output = triples of indices, one per triangle. 80.7% exact at n = 5; 93.0% of true triangles found.
Planar TSPshortest tour
Output = a permutation of all indices. At n = 5 it matches the optimal tour length 2.12; near-optimal up to n = 50.
A fair caveat the paper is honest about: as a TSP solver it is
not competitive with classical heuristics or later neural methods —
its tours drift longer as n grows past the training
range. The lasting contribution was never the benchmark numbers. It
was the pointer abstraction.
Can you re-explain it now?
Why can't plain seq2seq solve convex hull?
Its output layer is a softmax over a vocabulary fixed before training. Convex hull needs to choose among the input points, and the number of points changes every example — so there is no fixed list of output classes to predict.
What exactly is the "pointer"?
The attention distribution itself. The model scores every input position and softmaxes; instead of blending the states by those weights, it reads the distribution as a choice and emits the argmax position's index.
How does it differ from standard attention, in one line?
Identical scores uj = v⊤tanh(W1ej + W2di). Standard attention then sums ajej into a context vector; Ptr-Net deletes that sum and outputs the softmax. Weighting becomes selecting.
Why does it generalize past its training length?
Because the output dictionary is the input itself. The same small scoring network is applied to however many positions exist, so a model trained on n ≤ 50 still points sensibly at n = 100, 200, even 500 — covering 99%+ of hull area.
What is the running example, end to end?
Five points; four on the hull, one inside. The decoder points one index per step — 1, 2, 3, 4 — counter-clockwise from the lowest index, then stops. Output {⇒, 1, 2, 3, 4, ⇐}. Point 5 is never named.
What's the honest limitation?
As a combinatorial-optimization solver (e.g. TSP) it loses to classical heuristics and later neural methods, and accuracy decays for large n. Its value is the reusable idea of pointing at inputs, not the benchmark scores.
Homework
Re-derive step 5 with your own five points: write down five scores, softmax them by hand, and check the argmax really is a hull vertex and never the interior point. Then imagine adding a sixth point — note that nothing in the formula has to change.
The day attention learned to copy.
Pointing at the input turned out to be useful far beyond geometry. Wherever an output should sometimes be lifted straight from the input, a pointer is the natural tool — and the idea spread fast.
Pointer-generator
Summarizers that copy rare names and numbers verbatim from the source article instead of mangling them — a pointer blended with a vocabulary.
Copy mechanisms
Code generation, table-to-text and dialogue all borrowed copy attention, letting models reproduce exact tokens they were just shown.
Neural combinatorics
Pointer decoders became the standard front-end for learning over sets and routes, seeding a line of neural combinatorial-optimization work.
One deleted line — "stop blending, start pointing" — gave attention a second job it still does in modern systems.