22.02.2024 Views

Daniel Voigt Godoy - Deep Learning with PyTorch Step-by-Step A Beginner’s Guide-leanpub

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Encoder + Decoder + Attention

The integration of encoder, decoder, and the attention mechanism, when applied

to our sequence-to-sequence problem, is depicted in the figure below (that’s the

same figure from the "Computing the Context Vector" section).

Figure 9.17 - Encoder + decoder + attention

Take time to visualize the flow of information:

• First, the data points in the source sequence (in red) feed the encoder (in blue)

and generate "keys" (K) and "values" (V) for the attention mechanism (in

black).

• Next, each input of the decoder (in green) generates one "query" (Q) at a time

to produce a context vector (in black).

• Finally, the context vector gets concatenated to the decoder’s current hidden

state (in green) and transformed to predicted coordinates (in green) by the

output layer (in green).

Our former EncoderDecoder class works seamlessly with an instance of

DecoderAttn:

730 | Chapter 9 — Part I: Sequence-to-Sequence

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!