Pointer Networks
- Paper: Pointer Networks
- Authors: Oriol Vinyals, Meire Fortunato, Navdeep Jaitly
- Lab, year: Google Brain and UC Berkeley, 2015 (NIPS 2015, now NeurIPS)
- Video: YouTube Short coming on 19 Dec 2026 on Backprop Daily
Summary
A Pointer Network (Ptr-Net) is an encoder-decoder model whose outputs are positions in its input. At each decoding step the attention distribution over the input positions is used directly as the output distribution, instead of being blended into a context vector (Section 2.3). The output “vocabulary” therefore has exactly as many entries as the input, whatever its length. The paper trains Ptr-Nets from input-output examples on three geometric problems: planar convex hulls, Delaunay triangulations and the planar Travelling Salesman Problem (TSP). On 50-point convex hulls it found the exact hull in 72.6% of cases, against 38.9% for an LSTM (long short-term memory, a recurrent network) sequence-to-sequence model with attention and 1.9% for a plain LSTM (Section 4.2, Table 1).
What Problem Does It Solve
Sequence-to-sequence models “require the size of the output dictionary to be fixed a priori” (Section 1). For many problems the answer is a list of input positions: the points on a convex hull, the order of cities in a tour, the indices that sort a list. The number of possible outputs then changes with every input, so an ordinary model needs a separate output layer, and a separate trained model, for each input length n (Section 2.1). Pointer Networks remove that limit by pointing at input elements instead of choosing from a fixed dictionary.
Core Idea
An LSTM encoder reads the input elements (for example 2D points) and produces states e_1, …, e_n. An LSTM decoder produces one output per step. At step i it scores every input position with u_j = vᵀ tanh(W₁ e_j + W₂ d_i) and takes a softmax over the scores; that softmax is the probability of pointing at input j (Section 2.3). Because the scores are computed for whatever positions exist, the same model works for any n.
Key Method Details
- Output order: a convex hull is written as the hull indices starting “from the point with the lowest index” and going counter-clockwise, followed by an end token (Section 3.1).
- Training: a single-layer LSTM with 256 or 512 hidden units, SGD with learning rate 1.0, batch size 128, uniform initialisation in [−0.08, 0.08], gradient clipping at 2.0 and 1M training examples (Section 4.1). Decoding uses beam search (Section 2.1).
- Convex hull results: a model trained on 5–50 points scored 92.0% at n = 5, 69.6% at n = 50, 50.3% at n = 100, 22.1% at n = 200 and 1.3% at n = 500, with area coverage of 99.2% or more (Table 1).
- Delaunay and TSP: Delaunay accuracy was 80.7% at n = 5 and 22.6% at n = 10, with 52.8% triangle coverage at n = 50 (Section 4.3). A TSP model trained on 5–20 cities gave tours close to the best algorithm up to n = 30 (4.72 against 4.60) but much longer at n = 50 (7.66 against 5.79; Section 4.4, Table 2).
Simplifications in This Notebook
- Convex hull only, plus a sorting task as a bonus (not one of the paper’s experiments); no Delaunay or TSP.
- Smaller training: 50,000 hull examples with 5–50 points, hidden size 128, Adam (learning rate 10⁻³) for 50 epochs on a CPU, one seed; the paper used 1M examples and SGD.
- Greedy decoding instead of beam search, and no constraint against choosing the same point twice.
- Test sets: 500 sets with 5–50 points (sizes mixed) and 100 sets each with 55–65 and 75–85 points, instead of fixed n from 5 to 500.
- Bug fixed: the earlier notebook set the end-of-sequence target to a masked padding position, so its loss was
infin every epoch and sorting accuracy was 0.00%.
What the Notebook Result Shows
| Test set | Exact hull (sequence accuracy) | Hull points found (point accuracy) |
|---|---|---|
| 5–50 points (500 sets) | 43.40% | 94.47% |
| 55–65 points (100 sets) | 20.00% | 93.73% |
| 75–85 points (100 sets) | 14.00% | 89.65% |
- Training works now: the loss is finite and falls from 3.0035 after epoch 1 to 0.2411 after epoch 50.
- Extrapolation is partial: exact-hull accuracy drops on point sets larger than any seen in training, as in the paper’s Table 1, while most hull points are still found.
- Typical mistake: repeating a point and missing another; one shown example predicts
[0, 7, 7, 8, 8, 4, 6]for the true hull[0, 7, 8, 4, 1, 6]. - Not the paper’s numbers: the paper’s 69.6% at n = 50 used 1M examples, SGD and beam search; this run is much smaller and its test sets mix sizes, so the numbers are not directly comparable.
- The sorting bonus mostly failed: only 5.20% of 500 test lists were sorted exactly after 30 epochs (loss 0.7007); the shown example repeats indices and outputs 29 indices for 15 numbers.
Influence
The pointer idea was reused to copy words from the input text: the pointer-generator network of See, Liu and Manning (2017) mixes a pointer over the source with a normal vocabulary for summarisation. Bello et al. (2016) trained pointer networks for TSP with reinforcement learning instead of supervised targets, starting a line of work on learned heuristics for combinatorial optimisation.
Resources
| File | Description |
|---|---|
| README.md | This overview — a 5-minute read covering the paper’s summary, core idea, key method details, influence, and a plain-English explanation of the problem it solves |
| solution.ipynb | From-scratch PyTorch Pointer Network trained on planar convex hulls, tested on larger point sets, with pointer paths, attention heatmaps and a sorting bonus |
| CODE_ARCHITECTURE.md | Section-by-section breakdown of the notebook — what each cell does, data flow, tensor shapes, and key design decisions |
| TALK.md | Press coverage, Q&A (answers from the paper), and common misconceptions about the paper |