pytorch / pytorch/pytorch.github.io

Citing the source of the attention mechanism that is used in the tutorial: Translation with a Sequence to Sequence Network and Attention

Open
#553 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
285
Forks
317
PR merge metrics
No merged PRs in 30d

Description

📚 Documentation

This is regarding the tutorial of seq2seq with attention. The tutorial states:

To improve upon this model we’ll use an attention mechanism, which lets the decoder learn to focus over a specific range of the input sequence.

Here the link to the paper Neural Machine Translation by Jointly Learning to Align and Translate has been provided. This paper to my knowledge is the paper that introduced attention.
However, the tutorial does not use the attention mechanism that is described in this paper. The attention mechanism used in the tutorial is:


    def forward(self, input, hidden, encoder_outputs):
        embedded = self.embedding(input).view(1, 1, -1)
        embedded = self.dropout(embedded)

        attn_weights = F.softmax(
            self.attn(torch.cat((embedded[0], hidden[0]), 1)), dim=1)

Here the inputs to the attention mechanism are the input and the previous hidden state. However, the paper states the inputs for the attention mechanism as the previous hidden state and the outputs from the encoder. The extract from the paper:

where

e_{ij} = a(s_{i-1},h_i)

is an alignment model which scores how well the inputs around
position j and the output at position i match. The score is based on the
RNN hidden states i−1 (just before emitting yi, Eq. (4))
and the j-th annotation hj of the input sentence.

My guess is that the attention mechanism used here is the one that has been introduced in Effective Approaches to Attention-based Neural Machine Translation. Extract from the paper:

Likewise,  in attentional NMTs, alignment decisions should be
made jointly taking into account past alignment information.
To address that,  we propose an input-feeding approach in
which *attentional vectors ̃ht are concatenated with inputs at the next time* 
steps as illustrated in  Figure  4.

Since there are various architectures of the attention mechanism citing the source which is being used in the tutorial will be of great help.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Translation with a Sequence to Sequence Network and Attention tutorial, especially the shown attention forward method, and compare it with the two cited papers. Determine which source most accurately describes the implementation, then update the tutorial's attribution so the cited attention mechanism is clear and accurate.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation, machine-learning
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.