Deep Learning (DEEP-0001)�
Prof. André E. Lazzaretti
https://sites.google.com/site/andrelazzaretti/graduate-courses/deep-learning-cpgei/2025
13 – Transformers
Transformers
Motivation
Design neural network to encode and process text:
The word their must “attend to” the word restaurant.
Motivation
The word their must “attend to” the word restaurant.
Conclusions:�
Design neural network to encode and process text:
Motivation
Architecture
Input Embedding
Positional encoding
Order is important in language:
The man ate the fish
vs.
The fish ate the man
Positional Encoding
Positional Encoding
Problem: the scale of these numbers may limit optimization!
Problem: for length 5, 0.8=4/5, meaning it would be the 4th element. For sequence length 20, 0.8=16/20 means 0.8 represents the 16th element!
Positional Encoding
Positional Encoding
Positional Encoding
Transformers
Dot product = measure of similarity
Self Attention
Query, Key, and Value
Query, Key, and Value
Search request
Possible similar videos (e.g., same title)
Content of a video
Similarity: proxy to attention!
Derive key, query, and value
Attention scores (filter)
All the inputs
Multi-head
Instead of one single attention head, Q, K, and V are split into multiple heads. It allows the model to jointly attend to information from different representation subspaces at different positions.
As we encode the word "it", one attention head is focusing most on "the animal", while another is focusing on "tired" - in a sense, the model's representation of the word "it" bakes in some of the representation of both "animal" and "tired".
General overview
Residual Connections
Add and Norm
Transformers
Matrix form
Matrix form
Transformers
Encoder/Decoder
Encoder/Decoder
Decoder
Output from encoder:
split into two copies
Decoder
Logits
Training
Training
Training
Training
softmax
Masked Attention
Masked Attention
Masked Attention
Masked Attention
Transformers
GPT3 (Brown et al. 2020)