Attention
Get to know Attention, which is one of the most important formulas of deep learning.
Attention was born in order to address the limitations of Seq2Seq models.
The core idea is that the context vector should have access to all parts of the input sequence instead of just the last one.
In other words, we need to form a direct connection with each timestep.
This idea was originally proposed for computer vision. It was initially conceptualized like this: by looking at different parts of the image (glimpses), we can learn to accumulate information about a shape and classify the image accordingly.
The same principle was later extended to sequences. We can look at all the different words at the same time and learn to “pay attention“ to the correct ones depending on the task at hand.
This is what we now call attention. Attention is simply a notion of memory gained from attending at multiple inputs through time.
Let’s see it in action.
Attention in the encoder-decoder example
In the encoder-decoder RNN case, given previous state in the decoder as and the the hidden state , we have something like this:
The index indicates the prediction step. Essentially, we define a score (weighting) between the hidden state of the decoder and all the hidden states of the encoder.
More specifically, for each hidden state (denoted by ) , we will calculate a scalar:
Visually, in our example, we have something like this:
Get hands-on with 1400+ tech skills courses.