This article introduces the Pointer Generator Network and Coverage Mechanism. After the seminal paper from Sutzkever in 2014 and Bahdanau in 2015, before Transformer shook the ground in 2017, See et. el. introduced an improvement to the attention mechanism.

Baseline seq2seq with attention

This paper follows the vanilla seq2seq with attention mechanism. On the encoder side the model used bidirectional LSTM. On the decoder side, the model used a unidirectional LSTM.

The attention mechanism is essentally a small linear layer that sits between the encoder hidden states and the decoders states, telling the decoders which part of the input sequence it should look at:

Vector contains the scores of the attention, computed by a linear combination between encoder hidden state and decoder state . , , and are trainable parameters. Normalizing this score yields the attention distribution .

Then we perform a linear combination of encoder hiddent states with the distribution, this yields the context information of the current output. Dubbed as “context vector”

Combine this with the output state, we have the probability distribution over the vocabularies at this time-step .

For given word w, the probability that it will happen at time-step t is .

The loss at time-step t is negative log likelihood of target word :

The total loss is the summation loss of all time-steps:

Pointer Generator Network

One problem of such model is that these models does not generate words that’s not in the dictionary, even though it exists in the source sequence. In old models, they are often treated as <UNK> tokens, decoders will spit <UNK> if that word should be in the output sequence. This happens frequently, especially when the text is about a subject of rare name.

For one thing, regular vocabularies often has embeddings pretrained from a much larger database. They make up the main block of the sentence. On the other hand, special words do take up an important position in the output sequence, especially if they are the subjects. To determine when to generate words from the dictionary as opposed to when to use source tokens, the authors designed a “generation probability” :

We see this takes into account of the context, the decoder state, as well as the input token of current time-step. Next the distribution of vocabularies is augmented as:

The distribution is now defined on “extended vocabularies”. Which is the union of words in the original dictionary and the input tokens. The first part defines the distribution of generation, the second part is the distribution on input tokens. Notice if some token does not show up in the dictionary, is 0. Similarly, if some token does not show up in source text, is 0.

Coverage Mechanism

Another problem with seq2seq is that the outputs tends to repeat itself. To take that into account, the author proposed the converage vector :

This is the accumulated attention probability distribution of input sequence over all previous time-steps. Coverage vector shows if some part of the input sequence is not being attended to in the output. This will affect the attention distribution:

Besides, a penalize term for repetition, “coverage loss” is defined:

If the current output of attention distribution is the same as history accumulated distribution, this loss is at maximal. The final loss is a weighted combination:

Paper and Code

[1] Abigail See, Peter J.Liu, Christopher D. Manning, Get To The Point: Summarization with Pointer-Generator Networks https://arxiv.org/abs/1704.04368

[2] Clean re-production code: https://github.com/lipiji/neural-summ-cnndm-pytorch