Algorithm Search⌘K

Modeladvanced

Pointer-generator network

Also called copy mechanism, CopyNet.

An encoder-decoder that at each step mixes generating a word from the vocabulary with copying a source word through its attention weights.

A pointer-generator network is an encoder-decoder model with attention that can either generate a word from a fixed vocabulary or copy a word from the source text. At each output step it computes a number pgenp_{\mathrm{gen}} between 0 and 1, and its output distribution is pgenp_{\mathrm{gen}} times the vocabulary distribution plus 1−pgen1 - p_{\mathrm{gen}} times the attention distribution over the source positions. So it can write rare names and numbers that are not in the vocabulary, by pointing at them. Abigail See, Peter Liu and Christopher Manning introduced it in 2017 for abstractive summarization, together with a coverage mechanism that discourages the model from attending to the same source words again, which reduces repetition. The aliases name the general idea: "copy mechanism" is the family of methods, and CopyNet (Gu, Lu, Li and Li 2016) is a different model of the same family, with its own copy and generate scores.

The machine

The source is a sequence of tokens w1,…,wnw_1, \ldots, w_n. A bidirectional LSTM encoder gives hidden states h1,…,hnh_1, \ldots, h_n. At output step tt, the decoder LSTM has state sts_t and reads the embedding xtx_t of the previous output word. The parts of the model, in the notation of the paper:

  • Attention (Section 2.1). eit=vTtanh⁡(Whhi+Wsst+battn)e_i^t = v^{\mathsf T} \tanh(W_h h_i + W_s s_t + b_{\mathrm{attn}}) and at=softmax(et)a^t = \mathrm{softmax}(e^t), a distribution over the nn source positions. The context vector is ht∗=∑iaithih_t^* = \sum_i a_i^t h_i.
  • Vocabulary distribution. Pvocab=softmax(V′(V[st;ht∗]+b)+b′)P_{\mathrm{vocab}} = \mathrm{softmax}(V'(V[s_t; h_t^*] + b) + b'), over a fixed vocabulary.
  • Generation probability (equation 8). pgen=σ(wh∗Tht∗+wsTst+wxTxt+bptr)p_{\mathrm{gen}} = \sigma(w_{h^*}^{\mathsf T} h_t^* + w_s^{\mathsf T} s_t + w_x^{\mathsf T} x_t + b_{\mathrm{ptr}}), where σ\sigma is the logistic function.
  • Final distribution (equation 9). Over the extended vocabulary, the fixed vocabulary together with the words of this source,
P(w)=pgen Pvocab(w)+(1−pgen)∑i:wi=wait,P(w) = p_{\mathrm{gen}}\, P_{\mathrm{vocab}}(w) + (1 - p_{\mathrm{gen}}) \sum_{i : w_i = w} a_i^t,

with Pvocab(w)=0P_{\mathrm{vocab}}(w) = 0 for a word outside the vocabulary and an empty sum for a word not in the source.

  • Coverage (equations 10 and 11). The coverage vector ct=∑t′<tat′c^t = \sum_{t' < t} a^{t'} is the sum of the earlier attention distributions, and the attention score gets an extra term: eit=vTtanh⁡(Whhi+Wsst+wccit+battn)e_i^t = v^{\mathsf T}\tanh(W_h h_i + W_s s_t + w_c c_i^t + b_{\mathrm{attn}}).
  • Loss (equations 12 and 13). With the reference word wt∗w_t^*, the loss at step tt is
losst=−log⁡P(wt∗)+λ∑imin⁡(ait,cit),\mathrm{loss}_t = -\log P(w_t^*) + \lambda \sum_i \min(a_i^t, c_i^t),

and the loss of a sequence is the mean over its steps. The paper uses λ=1\lambda = 1.

Training uses teacher forcing on pairs of articles and summaries. At test time the summary is decoded with beam search on P(w)P(w). A word copied from the source and outside the vocabulary is fed back to the decoder as the unknown word token.

What it counts

One decoding step costs the LSTM update, O(nh)O(nh) for the attention over nn source positions with hidden size hh, O(Vh)O(Vh) for the vocabulary softmax with VV words, and O(n)O(n) more to add the copy probabilities into the extended vocabulary. The copy part adds only O(n+h)O(n + h) to a step of the attention model, and its parameters are the vectors wh∗w_{h^*}, wsw_s, wxw_x, the scalar bptrb_{\mathrm{ptr}}, and wcw_c for coverage.

Two small facts follow from the definitions; they are theorems.

  • The output is a distribution. PvocabP_{\mathrm{vocab}} and ata^t are distributions, so ∑wP(w)=pgen⋅1+(1−pgen)∑iait=1\sum_w P(w) = p_{\mathrm{gen}} \cdot 1 + (1 - p_{\mathrm{gen}}) \sum_i a_i^t = 1. A word that is both in the vocabulary and in the source gets probability from both parts, and a word that occurs several times in the source gets the attention of all its positions.
  • The coverage loss is bounded. At each step 0≤∑imin⁡(ait,cit)≤∑iait=10 \le \sum_i \min(a_i^t, c_i^t) \le \sum_i a_i^t = 1. It is 0 exactly when step tt puts no attention on a position that earlier steps attended to. So the sum of the coverage loss over a summary is 0 exactly when the attention distributions of all steps have disjoint supports, and it is at most the number of steps.

Relation to other models

  • Encoder-decoder with attention. With pgen=1p_{\mathrm{gen}} = 1 the model is the attention baseline of Section 2.1.
  • Pointer networks. Vinyals, Fortunato and Jaitly (2015) used the attention distribution itself as the output distribution over input positions, for problems such as convex hulls and the traveling salesman problem, where the output is a sequence of input positions. With pgen=0p_{\mathrm{gen}} = 0 the pointer-generator network is a pointer network.
  • CopyNet. Gu, Lu, Li and Li (2016) give scores to a generate mode and a copy mode and normalize them together in one softmax, so there is no explicit switch. It is a different model, listed here as an alias because the two are often named together.
  • Other switches. Gulcehre and colleagues (2016) and Nallapati and colleagues (2016) used a hard switch between pointing and generating, trained with labels that say when the word was copied. The pointer-generator network uses a soft switch, learned end to end, and needs no such labels.
  • Coverage. Tu and colleagues (2016) introduced coverage for machine translation. The pointer-generator network adds the coverage loss, which penalizes attention that overlaps with the coverage vector.
  • Extractive methods. TextRank and LexRank select whole sentences. The pointer-generator network writes new text, but in practice it copies much of it.

Known results in the model

These are measurements on the non-anonymized CNN and Daily Mail data set, scored with ROUGE F1 (Table 1 of the paper).

model ROUGE-1 ROUGE-2 ROUGE-L
pointer-generator 36.44 15.66 33.42
pointer-generator with coverage 39.53 17.28 36.38
lead-3 baseline (the first three sentences) 40.34 17.70 36.57
  • Coverage helps. Adding coverage raised all three scores by about 3 points, and the paper reports that it removed most of the repetition of the models without it.
  • Lead-3 is hard to beat. The simple baseline of the first three sentences scores higher than the model on ROUGE. The paper attributes this to the structure of news articles, where the main facts come first.
  • Training schedule. The model was trained for about 230,000 iterations, and coverage was added for a further 3,000 iterations at the end. The paper reports that training with coverage from the start did not work as well.
  • The model copies a lot. On the test set the mean of pgenp_{\mathrm{gen}} was 0.17, so most of the probability goes to copying. The summaries contain fewer new n-grams than the reference summaries.
  • Later work. Transformer based pretrained models such as BART and PEGASUS score higher on the same data. Copy mechanisms remain in use for data-to-text generation, dialogue and code, where exact names must be reproduced.

References

  1. Abigail See, Peter J. Liu and Christopher D. Manning, Get To The Point, Summarization with Pointer-Generator Networks, ACL 2017, pages 1073 to 1083, Section 2.1 (the attention baseline), Section 2.2 (equations 8 and 9, the generation probability and the final distribution), Section 2.3 (equations 10 to 13, coverage and the coverage loss), Table 1 (ROUGE on CNN and Daily Mail)
  2. Vinyals, Fortunato and Jaitly 2015, the attention distribution used as the output distribution over input positions
  3. Gu, Lu, Li and Li 2016 (CopyNet), the copy mode and the generate mode with a shared normalization

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/3JXDQW/text.yaml