Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Answer by pointing
Some answers are not words from a fixed list but items from the question itself: “put these numbers in order”, “which cities, in what order, should the drone visit?”, “which words of the article belong in the summary?”. A pointer network answers by pointing at input positions. Each step it attends over the inputs and simply picks the one it attends to most. Because it points rather than names, it works for inputs of any length, even longer than any it trained on. The demo’s attention mode shows such a distribution over positions.
Ordering waypoints, choosing which sensors to read or selecting targets are pointing problems. Learned pointer models are used as fast heuristics for routing and scheduling.
- 1. A pointer network outputs…
- 2. Its output vocabulary size…
- 3. A natural pointer task:
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Pointer attention:
- uⱼ = vᵀ tanh(W sₜ + U hⱼ) for each input position j;
- p(yₜ = j | …) = softmax over j of uⱼ;
- unlike Bahdanau attention (E11-9), there is no context vector: the distribution is the prediction.
- Masking: for permutations, set the scores of already-chosen positions to −∞. The number of choices then falls L, L − 1, …, 1.
- Decoder input: the encoder’s state (or value) at the position chosen at the previous step.
- Sorting target: argsort of the input. For [0.3, 0.1, 0.2] it is [1, 2, 0].
- Output space:
- there are L! possible permutations, log₂(5!) = 6.9 bits for L = 5;
- a random guess is fully sorted with probability 1/120 for L = 5, and below 3 × 10⁻⁷ for L = 10.
- Combinatorial tasks from the paper: convex hull, Delaunay triangulation and the planar travelling-salesman problem. For TSP the output is a tour. The unit square visited in order has length 4, and crossing it diagonally gives 2 + 2√2 = 4.83.
- 1. Pointer networks use the attention distribution as…
- 2. Choices at step 3 (1-based) of a masked 5-element permutation:
- 3. Bits to specify a permutation of 5:
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Pointer networks in code
Exercise 1.
- The pointer distribution summed to 1, had exactly one entry per input position (3 for a 3-element input), and gave zero probability to masked positions.
- Greedy pointing produced a valid permutation.
Practice.
- Implement pointing as attention whose logits are trained with cross-entropy against target indices, and mask chosen positions.
- Feed the chosen element’s embedding as the next decoder input.
- For combinatorial optimisation without labels, train with reinforcement learning on tour length (Bello et al., 2016; Kool et al., 2019 used attention models).
- Pointer-generator networks (See, Liu and Manning, 2017) mix a vocabulary softmax with pointing, weighted by a learned p_gen. This lets summarisers copy rare names from the source.
e = v(torch.tanh(Wq(s).unsqueeze(1) + Wk(enc_out))).squeeze(-1) # (B, L)
e = e.masked_fill(chosen, float("-inf"))
loss = F.cross_entropy(e, target_index) # point at the correct input position
chosen[torch.arange(B), target_index] = True- 1. Without labels, pointer models for TSP are trained with…
- 2. Pointer-generator networks mix pointing with…
- 3. Masking prevents…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Why a fixed vocabulary fails here.
- A standard decoder’s softmax has a fixed number of classes. To output positions it would need one class per possible index, and could never output an index beyond its training range.
- Pointing defines the classes by the input. The same parameters score any number of positions, so the model is applicable to any length.
Generalisation in length is not guaranteed.
- Applicable is not the same as accurate. The recurrent states and the decoder’s sense of progress were tuned on training lengths.
- Per-step accuracy degrades slowly, but whole-output accuracy degrades faster, since one mistake ruins a permutation: with per-position accuracy q, a rough independence estimate of full success is q^L.
Order matters. For set-to-sequence problems the input order is arbitrary. Vinyals et al.’s follow-up “Order matters” (2016) showed that the order of inputs and outputs affects learning, and proposed set encoders.
- 1. Pointing makes a model applicable to…
- 2. Whole-sequence accuracy degrades faster because…
- 3. 'Order matters' studied…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Does pointing generalise to longer inputs?
History.
- O. Vinyals, M. Fortunato and N. Jaitly introduced pointer networks (NeurIPS 2015) for convex hulls, Delaunay triangulation and small TSPs.
- I. Bello et al. (2016) trained them with reinforcement learning for TSP.
- A. See, P. Liu and C. Manning’s pointer-generator (2017) became a standard summariser.
- W. Kool, H. van Hoof and M. Welling (2019) used attention-based pointing for routing problems.
Exercise 2.
- Model: a pointer network with tanh RNNs (32 units) and additive pointer attention with a bias.
- Training: sort 5 random numbers, 800 Adam steps, teacher forcing, 2 seeds.
- Test: greedy decoding with masking on 500 sequences of length 5, 8 and 10, mean over the 2 seeds.
| test length | position accuracy | fully sorted | (seed 0 / seed 1, fully sorted) |
|---|---|---|---|
| 5 (trained) | 0.968 | 0.923 | 0.962 / 0.884 |
| 8 | 0.941 | 0.783 | 0.904 / 0.662 |
| 10 | 0.921 | 0.669 | 0.842 / 0.496 |
- Pointing transfers to lengths never seen. Position accuracy stays above 0.92 at twice the training length. A fixed-vocabulary decoder could not even express position 9.
- Whole outputs suffer more, since a single misplaced element fails the sequence. Full sorting falls from 0.92 to 0.67.
- Seeds differ noticeably (0.84 against 0.50 fully sorted at length 10): generalisation beyond the training range is less stable than in-range accuracy.
Pointer networks in AI, robotics and aerospace
- Routing and inspection: learned pointer policies give fast approximate tours for drones and inspection robots, with classical solvers used to verify or refine them.
- Scheduling: ordering tasks or observation targets for satellites is a pointing problem over the candidate list.
- Copying in language: pointer-generators copy part numbers and names from maintenance logs into summaries.
References
- O. Vinyals, M. Fortunato, N. Jaitly (2015). “Pointer networks.” Proc. NeurIPS.
- I. Bello, H. Pham, Q. V. Le, M. Norouzi, S. Bengio (2016). “Neural combinatorial optimization with reinforcement learning.” arXiv:1611.09940.
- A. See, P. J. Liu, C. D. Manning (2017). “Get to the point: summarization with pointer-generator networks.” Proc. ACL.
- W. Kool, H. van Hoof, M. Welling (2019). “Attention, learn to solve routing problems!” Proc. ICLR.