SlideShare a Scribd company logo
The Transformer
Lecture 20
Xavier Giro-i-Nieto
Associate Professor
Universitat Politecnica de Catalunya
@DocXavi
xavier.giro@upc.edu
2
Video-lecture
3
Acknowledgments
Marta R. Costa-jussà
Associate Professor
Universitat Politècnica de Catalunya
Carlos Escolano
PhD Candidate
Universitat Politècnica de Catalunya
Gerard I. Gállego
PhD Student
Universitat Politècnica de Catalunya
gerard.ion.gallego@upc.edu
@geiongallego
Outline
1. Reminders
4
5
Reminder
Nikhil Sha, “Attention ? An other Perspective!”. 2020.
6
Reminder
Attention is a mechanism to compute a context vector (c) for a query (Q) as a
weighted sum of values (V).
Figure: Nikhil Shah, “Attention? An Other Perspective! [Part 1]” (2020)
7
Reminder
Nikhil Sha, “Attention ? An other Perspective!”. 2020.
8
Reminder: Seq2Seq with Cross-Attention
Slide concept: Abigail See, Matthew Lamm (Stanford CS224N), 2020
In this case, cross-attention
refers to the attention
between the encoder and
decoder states.
9
Nikhil Sha, “Attention ? An other Perspective!”. 2020.
What may the term “self” refer to, as a contrast of “cross”-attention ?
Outline
1. Motivation
2. Self-attention
10
11
Self-Attention (or intra-Attention)
Lin, Z., Feng, M., Santos, C. N. D., Yu, M., Xiang, B., Zhou, B., & Bengio, Y. A structured self-attentive sentence embedding.
ICLR 2017.
Figure:
Jay Alammar,
“The Illustrated Transformer”
Self-attention refers to attending to other elements from the SAME sequence.
12
Self-Attention (or intra-Attention)
Nikhil Sha, “Attention ? An other Perspective!”. 2020.
Query (Q)
g(x) = WQ
x
Key (K)
f(x) = WK
x
Value (V)
h(x) = WV
x
WQ
, WK
and WV
are projection
layers shared across all words.
13
Self-Attention (or intra-Attention)
Which steps are necessary to compute the contextual representation of a word
embedding e2
in a sequences of four words embeddings (e1
, e2
, e3
, e4
) ?
A (scaled) dot-product is computed between each pair of word embeddings
(eg. e1
and e2
)...
#Transformer Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., ... & Polosukhin, I.. Attention
is all you need. NeurIPS 2017.
14
Self-Attention (or intra-Attention)
Which steps are necessary to compute the contextual representation of a word
embedding e2
in a sequences of four words embeddings (e1
, e2
, e3
, e4
) ?
… a softmax layer normalizes the attention scores to obtain the attention
distribution...
15
Self-Attention (or intra-Attention)
Which steps are necessary to compute the contextual representation of a word
embedding e2
in a sequences of four words embeddings (e1
, e2
, e3
, e4
) ?
...the same word
embeddings are combined to
obtain the contextual
representation e2
’.
16
Self-Attention (or intra-Attention)
Figure: Jay Alammar, “The illustrated Transformer” (2018)
17
Self-Attention (or intra-Attention)
Figure: Jay Alammar, “The illustrated Transformer” (2018)
18
Self-Attention (or intra-Attention)
Figure: Jay Alammar, “The illustrated Transformer” (2018)
19
Self-Attention (or intra-Attention)
Figure: Jay Alammar, “The illustrated Transformer” (2018)
20
Self-Attention (or intra-Attention)
Figure: Jay Alammar, “The illustrated Transformer” (2018)
21
Self-Attention (or intra-Attention)
Figure: Jay Alammar, “The illustrated Transformer” (2018)
22
Self-Attention (or intra-Attention)
Figure: Jay Alammar, “The illustrated Transformer” (2018)
23
Self-Attention (or intra-Attention)
Figure: Jay Alammar, “The illustrated Transformer” (2018)
24
Self-Attention (or intra-Attention) Scaled dot-product
attention
Figure: Jay Alammar, “The illustrated Transformer” (2018)
25
Study case: Self-Attention in for image generation
#SAGAN Zhang, Han, Ian Goodfellow, Dimitris Metaxas, and Augustus Odena. "Self-attention generative adversarial
networks." ICML 2019. [video]
Figure:
Frank Xu
Generator (G): Details can be generated using cues from all feature locations.
Discriminator: Can check consistency betweenn features in distant portions of the image.
26
Study case: Self-Attention in for image generation
#SAGAN Zhang, Han, Ian Goodfellow, Dimitris Metaxas, and Augustus Odena. "Self-attention generative adversarial
networks." ICML 2019. [video]
Query locations Attention maps for differet query locations
Outline
1. Motivation
2. Self-attention
3. Multi-head Self-Attention (MHSA)
27
28
Multi-Head Self-Attention (MHSA)
Nikhil Sha, “Attention ? An other Perspective!”. 2020.
In vanilla self-attention, a single set of projection matrices WQ
, WK
, WV
is used.
29
Nikhil Sha, “Attention ? An other Perspective!”. 2020.
In multi-head self-attention, multiple sets of projection matrices are used, and can
provide different contextual representations for the same input token.
Multi-Head Self-Attention (MHSA)
30
The multi-head self-attended E’i
matrixes are concatenated:
Figure: Jay Alammar, “The illustrated Transformer” (2018)
Multi-Head Self-Attention (MHSA)
31
A fully connected layer on top combines everything in a new E’.
Figure: Jay Alammar, “The illustrated Transformer” (2018)
Multi-Head Self-Attention (MHSA)
Multi-head Self-Attention: Visualization
32
#BertViz Vig, Jesse. "A multiscale visualization of attention in the transformer model." ACL 2019. [code] [tweet]
Each colour
corresponds
to a head.
Blue: First
head only.
Multi-color:
Multiple
heads.
33
Self-Attention and Convolutional Layers
Cordonnier, J. B., Loukas, A., & Jaggi, M. On the relationship between self-attention and convolutional layers. ICLR 2020.
[tweet] [code]
Outline
1. Motivation
2. Self-attention
3. Multi-head Attention
4. Positional Encoding
34
Positional Encoding
35
Given that the attention mechanism allows accessing all input (and output)
tokens, we no longer need a memory through recurrent layers.
Positional Encoding
36
Figure: Jay Alammar, “The illustrated Transformer” (2018)
Where is the relative relation in the sequence encoded ?
Positional Encoding
37
Figure: Jay Alammar, “The illustrated Transformer” (2018)
Where is the relative relation in the sequence encoded ?
Positional Encoding
38
Maria Ribalta, Pere-Pau Vàzquez, “Visualization is all you need”. UPC GCED 2020.
Sinusoidal functions are typically used to provide positional encodings.
Positional Encoding
39
Figure: Jay Alammar, “The illustrated Transformer” (2018)
Outline
1. Motivation
2. Self-attention
3. Multi-head Attention
4. Positional Encoding
5. The Transformer
40
The Transformer
41
#Transformer Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., ... & Polosukhin, I.. Attention
is all you need. NeurIPS 2017.
The Transformer removed the recurrency mechanism thanks to self-attention.
The Transformer
42
#Transformer Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., ... & Polosukhin, I.. Attention
is all you need. NeurIPS 2017.
Positional Encoding over the output
sequence.
Positional Encoding
over the input
sequence.
Auto-regressive (at test).
The Transformer
43
#Transformer Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., ... & Polosukhin, I.. Attention
is all you need. NeurIPS 2017.
Cross-Attention (or inter-attention)
between input and output tokens
Self-attention for
the input tokens.
Self-attention for the output tokens.
The Transformer: Layers
44
#Transformer Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., ... & Polosukhin, I.. Attention
is all you need. NeurIPS 2017.
N decoder layers
N encoder
layers
The Transformer: Layers
45
#BertViz Vig, Jesse. "A multiscale visualization of attention in the transformer model." ACL 2019. [code] [tweet]
A birds-eye view of attention across all of the model’s layers and heads
The Transformer: Visualization
46
Maria Ribalta, Pere-Pau Vàzquez, “Visualization is all you need”. UPC GCED 2020.
47
Are Transformers for Language only ? NO !!
#ViT Dosovitskiy, Alexey, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn, Xiaohua Zhai, Thomas Unterthiner, Mostafa
Dehghani et al. "An image is worth 16x16 words: Transformers for image recognition at scale." ICLR 2021. [blog] [code]
Outline
1. Motivation
2. Self-attention
3. Multi-head Attention
4. Positional Encoding
5. The Transformer
48
49
(extra) PyTorch Lab on Google Colab
DL resources from UPC Telecos:
● Lectures (with Slides & Videos)
● Labs
Gerard Gallego
gerard.ion.gallego@upc.edu
Student PhD
Universitat Politecnica de Catalunya
Technical University of Catalonia
50
Software
● Transformers in HuggingFace.
● GPT-Neo by EleutherAI
○ Similar results to GPT-3, but smaller and open source.
● Andrej Karpathy, minGPT (2020).
51
Learn more
Ashish Vaswani, Stanford CS224N 2019.
52
Learn more
● Tutorials
○ Sebastian Ruder, Deep Learning for NLP Best Practices # Attention (2017).
○ Chris Olah, Shan Carter, “Attention and Augmented Recurrent Neural Networks”. distill.pub 2016.
○ Lilian Weg, The Transformer Family. Lil’Log 2020
● Twitter threads
○ Christian Wolf (INSA Lyon)
● Scientific publications
○ #Perceiver Jaegle, Andrew, Felix Gimeno, Andrew Brock, Andrew Zisserman, Oriol Vinyals, and Joao Carreira.
"Perceiver: General perception with iterative attention." arXiv preprint arXiv:2103.03206 (2021).
○ #Longformer Beltagy, Iz, Matthew E. Peters, and Arman Cohan. "Longformer: The long-document transformer." arXiv
preprint arXiv:2004.05150 (2020).
○ Katharopoulos, A., Vyas, A., Pappas, N., & Fleuret, F. Transformers are RNS: Fast autoregressive transformers with linear
attention. ICML 2020.
○ Siddhant M. Jayakumar, Wojciech M. Czarnecki, Jacob Menick, Jonathan Schwarz, Jack Rae, Simon Osindero, Yee Whye
Teh, Tim Harley, Razvan Pascanu, “Multiplicative Interactions and Where to Find Them”. ICLR 2020. [tweet]
○ Self-attention in language
■ Cheng, J., Dong, L., & Lapata, M. (2016). Long short-term memory-networks for machine reading. arXiv preprint
arXiv:1601.06733.
○ Self-attention in images
■ Parmar, N., Vaswani, A., Uszkoreit, J., Kaiser, Ł., Shazeer, N., Ku, A., & Tran, D. (2018). Image transformer. ICML
2018.
■ Wang, Xiaolong, Ross Girshick, Abhinav Gupta, and Kaiming He. "Non-local neural networks." In CVPR 2018.
53
Questions ?

More Related Content

PDF
Multimodal Deep Learning
Universitat Politècnica de Catalunya
 
PDF
Image Translation with GAN
Junho Cho
 
PDF
Emerging Properties in Self-Supervised Vision Transformers
Sungchul Kim
 
PDF
映像を用いた農家間の知識継承
Naoshi Uchihira
 
PDF
The Transformer in Vision | Xavier Giro | Master in Computer Vision Barcelona...
Universitat Politècnica de Catalunya
 
PPT
Medical Image Processing
Pantech ProLabs India Pvt Ltd
 
PPT
Multimedia Data Mining using Deep Learning
Bhagyashree Barde
 
PPTX
Tutorial on Object Detection (Faster R-CNN)
Hwa Pyung Kim
 
Multimodal Deep Learning
Universitat Politècnica de Catalunya
 
Image Translation with GAN
Junho Cho
 
Emerging Properties in Self-Supervised Vision Transformers
Sungchul Kim
 
映像を用いた農家間の知識継承
Naoshi Uchihira
 
The Transformer in Vision | Xavier Giro | Master in Computer Vision Barcelona...
Universitat Politècnica de Catalunya
 
Medical Image Processing
Pantech ProLabs India Pvt Ltd
 
Multimedia Data Mining using Deep Learning
Bhagyashree Barde
 
Tutorial on Object Detection (Faster R-CNN)
Hwa Pyung Kim
 

What's hot (20)

PDF
PR-409: Denoising Diffusion Probabilistic Models
Hyeongmin Lee
 
PDF
ViT (Vision Transformer) Review [CDM]
Dongmin Choi
 
PPTX
Vision Transformer(ViT) / An Image is Worth 16*16 Words: Transformers for Ima...
changedaeoh
 
PDF
シリコンバレー出向報告(ミクシィ社内報告会・公開用)
Kyosuke Inoue
 
PDF
SSII2022 [OS1-01] AI時代のチームビルディング
SSII
 
PPTX
Transformers In Vision From Zero to Hero (DLI).pptx
Deep Learning Italia
 
PDF
3-d interpretation from single 2-d image for autonomous driving II
Yu Huang
 
PPT
3D visualisation of medical images
Shashank
 
PDF
Goodfellow先生おすすめのGAN論文6つを紹介
Katsuya Ito
 
PDF
Deep learning and Healthcare
Thomas da Silva Paula
 
PDF
CV_1 Introduction of Computer Vision and its Application
Khushali Kathiriya
 
PDF
Local binary pattern
International Islamic University
 
PDF
Lecture9 camera calibration
zukun
 
PDF
Pr083 Non-local Neural Networks
Taeoh Kim
 
PDF
3D transformation and viewing
Yogita Jain
 
PDF
PhD Defense
Taehoon Lee
 
PDF
210523 swin transformer v1.5
taeseon ryu
 
PPTX
Line Detection using Hough transform .pptx
shubham loni
 
PPTX
Aahuti PhD Progress Review Presentation_ Apr,2020
Aahuti Dhandhukia
 
PDF
Stable Diffusion path
Vitaly Bondar
 
PR-409: Denoising Diffusion Probabilistic Models
Hyeongmin Lee
 
ViT (Vision Transformer) Review [CDM]
Dongmin Choi
 
Vision Transformer(ViT) / An Image is Worth 16*16 Words: Transformers for Ima...
changedaeoh
 
シリコンバレー出向報告(ミクシィ社内報告会・公開用)
Kyosuke Inoue
 
SSII2022 [OS1-01] AI時代のチームビルディング
SSII
 
Transformers In Vision From Zero to Hero (DLI).pptx
Deep Learning Italia
 
3-d interpretation from single 2-d image for autonomous driving II
Yu Huang
 
3D visualisation of medical images
Shashank
 
Goodfellow先生おすすめのGAN論文6つを紹介
Katsuya Ito
 
Deep learning and Healthcare
Thomas da Silva Paula
 
CV_1 Introduction of Computer Vision and its Application
Khushali Kathiriya
 
Local binary pattern
International Islamic University
 
Lecture9 camera calibration
zukun
 
Pr083 Non-local Neural Networks
Taeoh Kim
 
3D transformation and viewing
Yogita Jain
 
PhD Defense
Taehoon Lee
 
210523 swin transformer v1.5
taeseon ryu
 
Line Detection using Hough transform .pptx
shubham loni
 
Aahuti PhD Progress Review Presentation_ Apr,2020
Aahuti Dhandhukia
 
Stable Diffusion path
Vitaly Bondar
 
Ad

Similar to The Transformer - Xavier Giró - UPC Barcelona 2021 (20)

PDF
Self-supervised Visual Learning 2020 - Xavier Giro-i-Nieto - UPC Barcelona
Universitat Politècnica de Catalunya
 
PDF
Attention for Deep Learning - Xavier Giro - UPC TelecomBCN Barcelona 2020
Universitat Politècnica de Catalunya
 
PDF
alexVAE_New.pdf
sourabhgothe1
 
PDF
Deep Language and Vision by Amaia Salvador (Insight DCU 2018)
Universitat Politècnica de Catalunya
 
PDF
深度学习639页PPT/////////////////////////////
alicejiang7888
 
PDF
Variational Autoencoders VAE - Santiago Pascual - UPC Barcelona 2018
Universitat Politècnica de Catalunya
 
PDF
Striving to Demystify Bayesian Computational Modelling
Marco Wirthlin
 
PPTX
[AIoTLab]attention mechanism.pptx
TuCaoMinh2
 
PDF
Deep Learning Representations for All (a.ka. the AI hype)
Universitat Politècnica de Catalunya
 
PDF
Deep Learning without Annotations - Xavier Giro - UPC Barcelona 2018
Universitat Politècnica de Catalunya
 
PDF
ALASI15 Writing Analytics Workshop
Simon Buckingham Shum
 
PDF
Multimodal Residual Networks for Visual QA
Jin-Hwa Kim
 
PDF
Transformer based approaches for visual representation learning
Ryohei Suzuki
 
PDF
Deep Language and Vision (DLSL D2L4 2018 UPC Deep Learning for Speech and Lan...
Universitat Politècnica de Catalunya
 
PDF
Self-supervised Learning from Video Sequences - Xavier Giro - UPC Barcelona 2019
Universitat Politècnica de Catalunya
 
PDF
ICED 2013 A
victor tang
 
PDF
One Perceptron to Rule them All: Deep Learning for Multimedia #A2IC2018
Universitat Politècnica de Catalunya
 
PDF
Interpretability of machine learning
Daiki Tanaka
 
PDF
Deep Learning Representations for All - Xavier Giro-i-Nieto - IRI Barcelona 2020
Universitat Politècnica de Catalunya
 
PDF
Deep Learning: concepts and use cases (October 2018)
Julien SIMON
 
Self-supervised Visual Learning 2020 - Xavier Giro-i-Nieto - UPC Barcelona
Universitat Politècnica de Catalunya
 
Attention for Deep Learning - Xavier Giro - UPC TelecomBCN Barcelona 2020
Universitat Politècnica de Catalunya
 
alexVAE_New.pdf
sourabhgothe1
 
Deep Language and Vision by Amaia Salvador (Insight DCU 2018)
Universitat Politècnica de Catalunya
 
深度学习639页PPT/////////////////////////////
alicejiang7888
 
Variational Autoencoders VAE - Santiago Pascual - UPC Barcelona 2018
Universitat Politècnica de Catalunya
 
Striving to Demystify Bayesian Computational Modelling
Marco Wirthlin
 
[AIoTLab]attention mechanism.pptx
TuCaoMinh2
 
Deep Learning Representations for All (a.ka. the AI hype)
Universitat Politècnica de Catalunya
 
Deep Learning without Annotations - Xavier Giro - UPC Barcelona 2018
Universitat Politècnica de Catalunya
 
ALASI15 Writing Analytics Workshop
Simon Buckingham Shum
 
Multimodal Residual Networks for Visual QA
Jin-Hwa Kim
 
Transformer based approaches for visual representation learning
Ryohei Suzuki
 
Deep Language and Vision (DLSL D2L4 2018 UPC Deep Learning for Speech and Lan...
Universitat Politècnica de Catalunya
 
Self-supervised Learning from Video Sequences - Xavier Giro - UPC Barcelona 2019
Universitat Politècnica de Catalunya
 
ICED 2013 A
victor tang
 
One Perceptron to Rule them All: Deep Learning for Multimedia #A2IC2018
Universitat Politècnica de Catalunya
 
Interpretability of machine learning
Daiki Tanaka
 
Deep Learning Representations for All - Xavier Giro-i-Nieto - IRI Barcelona 2020
Universitat Politècnica de Catalunya
 
Deep Learning: concepts and use cases (October 2018)
Julien SIMON
 
Ad

More from Universitat Politècnica de Catalunya (20)

PDF
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Universitat Politècnica de Catalunya
 
PDF
Deep Generative Learning for All
Universitat Politècnica de Catalunya
 
PDF
Towards Sign Language Translation & Production | Xavier Giro-i-Nieto
Universitat Politècnica de Catalunya
 
PDF
Learning Representations for Sign Language Videos - Xavier Giro - NIST TRECVI...
Universitat Politècnica de Catalunya
 
PDF
Open challenges in sign language translation and production
Universitat Politècnica de Catalunya
 
PPTX
Generation of Synthetic Referring Expressions for Object Segmentation in Videos
Universitat Politècnica de Catalunya
 
PPTX
Discovery and Learning of Navigation Goals from Pixels in Minecraft
Universitat Politècnica de Catalunya
 
PDF
Learn2Sign : Sign language recognition and translation using human keypoint e...
Universitat Politècnica de Catalunya
 
PDF
Intepretability / Explainable AI for Deep Neural Networks
Universitat Politècnica de Catalunya
 
PDF
Convolutional Neural Networks - Xavier Giro - UPC TelecomBCN Barcelona 2020
Universitat Politècnica de Catalunya
 
PDF
Self-Supervised Audio-Visual Learning - Xavier Giro - UPC TelecomBCN Barcelon...
Universitat Politècnica de Catalunya
 
PDF
Generative Adversarial Networks GAN - Xavier Giro - UPC TelecomBCN Barcelona ...
Universitat Politècnica de Catalunya
 
PDF
Q-Learning with a Neural Network - Xavier Giró - UPC Barcelona 2020
Universitat Politècnica de Catalunya
 
PDF
Language and Vision with Deep Learning - Xavier Giró - ACM ICMR 2020 (Tutorial)
Universitat Politècnica de Catalunya
 
PDF
Image Segmentation with Deep Learning - Xavier Giro & Carles Ventura - ISSonD...
Universitat Politècnica de Catalunya
 
PDF
Curriculum Learning for Recurrent Video Object Segmentation
Universitat Politècnica de Catalunya
 
PDF
Deep Self-supervised Learning for All - Xavier Giro - X-Europe 2020
Universitat Politècnica de Catalunya
 
PDF
Transcription-Enriched Joint Embeddings for Spoken Descriptions of Images and...
Universitat Politècnica de Catalunya
 
PDF
Object Detection with Deep Learning - Xavier Giro-i-Nieto - UPC School Barcel...
Universitat Politècnica de Catalunya
 
PDF
Self-supervised Audiovisual Learning 2020 - Xavier Giro-i-Nieto - UPC Telecom...
Universitat Politècnica de Catalunya
 
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Universitat Politècnica de Catalunya
 
Deep Generative Learning for All
Universitat Politècnica de Catalunya
 
Towards Sign Language Translation & Production | Xavier Giro-i-Nieto
Universitat Politècnica de Catalunya
 
Learning Representations for Sign Language Videos - Xavier Giro - NIST TRECVI...
Universitat Politècnica de Catalunya
 
Open challenges in sign language translation and production
Universitat Politècnica de Catalunya
 
Generation of Synthetic Referring Expressions for Object Segmentation in Videos
Universitat Politècnica de Catalunya
 
Discovery and Learning of Navigation Goals from Pixels in Minecraft
Universitat Politècnica de Catalunya
 
Learn2Sign : Sign language recognition and translation using human keypoint e...
Universitat Politècnica de Catalunya
 
Intepretability / Explainable AI for Deep Neural Networks
Universitat Politècnica de Catalunya
 
Convolutional Neural Networks - Xavier Giro - UPC TelecomBCN Barcelona 2020
Universitat Politècnica de Catalunya
 
Self-Supervised Audio-Visual Learning - Xavier Giro - UPC TelecomBCN Barcelon...
Universitat Politècnica de Catalunya
 
Generative Adversarial Networks GAN - Xavier Giro - UPC TelecomBCN Barcelona ...
Universitat Politècnica de Catalunya
 
Q-Learning with a Neural Network - Xavier Giró - UPC Barcelona 2020
Universitat Politècnica de Catalunya
 
Language and Vision with Deep Learning - Xavier Giró - ACM ICMR 2020 (Tutorial)
Universitat Politècnica de Catalunya
 
Image Segmentation with Deep Learning - Xavier Giro & Carles Ventura - ISSonD...
Universitat Politècnica de Catalunya
 
Curriculum Learning for Recurrent Video Object Segmentation
Universitat Politècnica de Catalunya
 
Deep Self-supervised Learning for All - Xavier Giro - X-Europe 2020
Universitat Politècnica de Catalunya
 
Transcription-Enriched Joint Embeddings for Spoken Descriptions of Images and...
Universitat Politècnica de Catalunya
 
Object Detection with Deep Learning - Xavier Giro-i-Nieto - UPC School Barcel...
Universitat Politècnica de Catalunya
 
Self-supervised Audiovisual Learning 2020 - Xavier Giro-i-Nieto - UPC Telecom...
Universitat Politècnica de Catalunya
 

Recently uploaded (20)

PPTX
Introduction-to-Python-Programming-Language (1).pptx
dhyeysapariya
 
PDF
202501214233242351219 QASS Session 2.pdf
lauramejiamillan
 
PPTX
Power BI in Business Intelligence with AI
KPR Institute of Engineering and Technology
 
PPTX
Pipeline Automatic Leak Detection for Water Distribution Systems
Sione Palu
 
PPTX
IP_Journal_Articles_2025IP_Journal_Articles_2025
mishell212144
 
PDF
An Uncut Conversation With Grok | PDF Document
Mike Hydes
 
PDF
WISE main accomplishments for ISQOLS award July 2025.pdf
StatsCommunications
 
PPTX
Data-Driven Machine Learning for Rail Infrastructure Health Monitoring
Sione Palu
 
PDF
TIC ACTIVIDAD 1geeeeeeeeeeeeeeeeeeeeeeeeeeeeeer3.pdf
Thais Ruiz
 
PPTX
lecture 13 mind test academy it skills.pptx
ggesjmrasoolpark
 
PDF
Practical Measurement Systems Analysis (Gage R&R) for design
Rob Schubert
 
PPT
Real Life Application of Set theory, Relations and Functions
manavparmar205
 
PPTX
World-population.pptx fire bunberbpeople
umutunsalnsl4402
 
PDF
D9110.pdfdsfvsdfvsdfvsdfvfvfsvfsvffsdfvsdfvsd
minhn6673
 
PPTX
Introduction to Biostatistics Presentation.pptx
AtemJoshua
 
PDF
oop_java (1) of ice or cse or eee ic.pdf
sabiquntoufiqlabonno
 
PDF
SUMMER INTERNSHIP REPORT[1] (AutoRecovered) (6) (1).pdf
pandeydiksha814
 
PDF
Company Presentation pada Perusahaan ADB.pdf
didikfahmi
 
PPTX
INFO8116 - Week 10 - Slides.pptx big data architecture
guddipatel10
 
PPTX
INFO8116 -Big data architecture and analytics
guddipatel10
 
Introduction-to-Python-Programming-Language (1).pptx
dhyeysapariya
 
202501214233242351219 QASS Session 2.pdf
lauramejiamillan
 
Power BI in Business Intelligence with AI
KPR Institute of Engineering and Technology
 
Pipeline Automatic Leak Detection for Water Distribution Systems
Sione Palu
 
IP_Journal_Articles_2025IP_Journal_Articles_2025
mishell212144
 
An Uncut Conversation With Grok | PDF Document
Mike Hydes
 
WISE main accomplishments for ISQOLS award July 2025.pdf
StatsCommunications
 
Data-Driven Machine Learning for Rail Infrastructure Health Monitoring
Sione Palu
 
TIC ACTIVIDAD 1geeeeeeeeeeeeeeeeeeeeeeeeeeeeeer3.pdf
Thais Ruiz
 
lecture 13 mind test academy it skills.pptx
ggesjmrasoolpark
 
Practical Measurement Systems Analysis (Gage R&R) for design
Rob Schubert
 
Real Life Application of Set theory, Relations and Functions
manavparmar205
 
World-population.pptx fire bunberbpeople
umutunsalnsl4402
 
D9110.pdfdsfvsdfvsdfvsdfvfvfsvfsvffsdfvsdfvsd
minhn6673
 
Introduction to Biostatistics Presentation.pptx
AtemJoshua
 
oop_java (1) of ice or cse or eee ic.pdf
sabiquntoufiqlabonno
 
SUMMER INTERNSHIP REPORT[1] (AutoRecovered) (6) (1).pdf
pandeydiksha814
 
Company Presentation pada Perusahaan ADB.pdf
didikfahmi
 
INFO8116 - Week 10 - Slides.pptx big data architecture
guddipatel10
 
INFO8116 -Big data architecture and analytics
guddipatel10
 

The Transformer - Xavier Giró - UPC Barcelona 2021

  • 1. The Transformer Lecture 20 Xavier Giro-i-Nieto Associate Professor Universitat Politecnica de Catalunya @DocXavi [email protected]
  • 3. 3 Acknowledgments Marta R. Costa-jussà Associate Professor Universitat Politècnica de Catalunya Carlos Escolano PhD Candidate Universitat Politècnica de Catalunya Gerard I. Gállego PhD Student Universitat Politècnica de Catalunya [email protected] @geiongallego
  • 5. 5 Reminder Nikhil Sha, “Attention ? An other Perspective!”. 2020.
  • 6. 6 Reminder Attention is a mechanism to compute a context vector (c) for a query (Q) as a weighted sum of values (V). Figure: Nikhil Shah, “Attention? An Other Perspective! [Part 1]” (2020)
  • 7. 7 Reminder Nikhil Sha, “Attention ? An other Perspective!”. 2020.
  • 8. 8 Reminder: Seq2Seq with Cross-Attention Slide concept: Abigail See, Matthew Lamm (Stanford CS224N), 2020 In this case, cross-attention refers to the attention between the encoder and decoder states.
  • 9. 9 Nikhil Sha, “Attention ? An other Perspective!”. 2020. What may the term “self” refer to, as a contrast of “cross”-attention ?
  • 11. 11 Self-Attention (or intra-Attention) Lin, Z., Feng, M., Santos, C. N. D., Yu, M., Xiang, B., Zhou, B., & Bengio, Y. A structured self-attentive sentence embedding. ICLR 2017. Figure: Jay Alammar, “The Illustrated Transformer” Self-attention refers to attending to other elements from the SAME sequence.
  • 12. 12 Self-Attention (or intra-Attention) Nikhil Sha, “Attention ? An other Perspective!”. 2020. Query (Q) g(x) = WQ x Key (K) f(x) = WK x Value (V) h(x) = WV x WQ , WK and WV are projection layers shared across all words.
  • 13. 13 Self-Attention (or intra-Attention) Which steps are necessary to compute the contextual representation of a word embedding e2 in a sequences of four words embeddings (e1 , e2 , e3 , e4 ) ? A (scaled) dot-product is computed between each pair of word embeddings (eg. e1 and e2 )... #Transformer Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., ... & Polosukhin, I.. Attention is all you need. NeurIPS 2017.
  • 14. 14 Self-Attention (or intra-Attention) Which steps are necessary to compute the contextual representation of a word embedding e2 in a sequences of four words embeddings (e1 , e2 , e3 , e4 ) ? … a softmax layer normalizes the attention scores to obtain the attention distribution...
  • 15. 15 Self-Attention (or intra-Attention) Which steps are necessary to compute the contextual representation of a word embedding e2 in a sequences of four words embeddings (e1 , e2 , e3 , e4 ) ? ...the same word embeddings are combined to obtain the contextual representation e2 ’.
  • 16. 16 Self-Attention (or intra-Attention) Figure: Jay Alammar, “The illustrated Transformer” (2018)
  • 17. 17 Self-Attention (or intra-Attention) Figure: Jay Alammar, “The illustrated Transformer” (2018)
  • 18. 18 Self-Attention (or intra-Attention) Figure: Jay Alammar, “The illustrated Transformer” (2018)
  • 19. 19 Self-Attention (or intra-Attention) Figure: Jay Alammar, “The illustrated Transformer” (2018)
  • 20. 20 Self-Attention (or intra-Attention) Figure: Jay Alammar, “The illustrated Transformer” (2018)
  • 21. 21 Self-Attention (or intra-Attention) Figure: Jay Alammar, “The illustrated Transformer” (2018)
  • 22. 22 Self-Attention (or intra-Attention) Figure: Jay Alammar, “The illustrated Transformer” (2018)
  • 23. 23 Self-Attention (or intra-Attention) Figure: Jay Alammar, “The illustrated Transformer” (2018)
  • 24. 24 Self-Attention (or intra-Attention) Scaled dot-product attention Figure: Jay Alammar, “The illustrated Transformer” (2018)
  • 25. 25 Study case: Self-Attention in for image generation #SAGAN Zhang, Han, Ian Goodfellow, Dimitris Metaxas, and Augustus Odena. "Self-attention generative adversarial networks." ICML 2019. [video] Figure: Frank Xu Generator (G): Details can be generated using cues from all feature locations. Discriminator: Can check consistency betweenn features in distant portions of the image.
  • 26. 26 Study case: Self-Attention in for image generation #SAGAN Zhang, Han, Ian Goodfellow, Dimitris Metaxas, and Augustus Odena. "Self-attention generative adversarial networks." ICML 2019. [video] Query locations Attention maps for differet query locations
  • 27. Outline 1. Motivation 2. Self-attention 3. Multi-head Self-Attention (MHSA) 27
  • 28. 28 Multi-Head Self-Attention (MHSA) Nikhil Sha, “Attention ? An other Perspective!”. 2020. In vanilla self-attention, a single set of projection matrices WQ , WK , WV is used.
  • 29. 29 Nikhil Sha, “Attention ? An other Perspective!”. 2020. In multi-head self-attention, multiple sets of projection matrices are used, and can provide different contextual representations for the same input token. Multi-Head Self-Attention (MHSA)
  • 30. 30 The multi-head self-attended E’i matrixes are concatenated: Figure: Jay Alammar, “The illustrated Transformer” (2018) Multi-Head Self-Attention (MHSA)
  • 31. 31 A fully connected layer on top combines everything in a new E’. Figure: Jay Alammar, “The illustrated Transformer” (2018) Multi-Head Self-Attention (MHSA)
  • 32. Multi-head Self-Attention: Visualization 32 #BertViz Vig, Jesse. "A multiscale visualization of attention in the transformer model." ACL 2019. [code] [tweet] Each colour corresponds to a head. Blue: First head only. Multi-color: Multiple heads.
  • 33. 33 Self-Attention and Convolutional Layers Cordonnier, J. B., Loukas, A., & Jaggi, M. On the relationship between self-attention and convolutional layers. ICLR 2020. [tweet] [code]
  • 34. Outline 1. Motivation 2. Self-attention 3. Multi-head Attention 4. Positional Encoding 34
  • 35. Positional Encoding 35 Given that the attention mechanism allows accessing all input (and output) tokens, we no longer need a memory through recurrent layers.
  • 36. Positional Encoding 36 Figure: Jay Alammar, “The illustrated Transformer” (2018) Where is the relative relation in the sequence encoded ?
  • 37. Positional Encoding 37 Figure: Jay Alammar, “The illustrated Transformer” (2018) Where is the relative relation in the sequence encoded ?
  • 38. Positional Encoding 38 Maria Ribalta, Pere-Pau Vàzquez, “Visualization is all you need”. UPC GCED 2020. Sinusoidal functions are typically used to provide positional encodings.
  • 39. Positional Encoding 39 Figure: Jay Alammar, “The illustrated Transformer” (2018)
  • 40. Outline 1. Motivation 2. Self-attention 3. Multi-head Attention 4. Positional Encoding 5. The Transformer 40
  • 41. The Transformer 41 #Transformer Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., ... & Polosukhin, I.. Attention is all you need. NeurIPS 2017. The Transformer removed the recurrency mechanism thanks to self-attention.
  • 42. The Transformer 42 #Transformer Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., ... & Polosukhin, I.. Attention is all you need. NeurIPS 2017. Positional Encoding over the output sequence. Positional Encoding over the input sequence. Auto-regressive (at test).
  • 43. The Transformer 43 #Transformer Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., ... & Polosukhin, I.. Attention is all you need. NeurIPS 2017. Cross-Attention (or inter-attention) between input and output tokens Self-attention for the input tokens. Self-attention for the output tokens.
  • 44. The Transformer: Layers 44 #Transformer Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., ... & Polosukhin, I.. Attention is all you need. NeurIPS 2017. N decoder layers N encoder layers
  • 45. The Transformer: Layers 45 #BertViz Vig, Jesse. "A multiscale visualization of attention in the transformer model." ACL 2019. [code] [tweet] A birds-eye view of attention across all of the model’s layers and heads
  • 46. The Transformer: Visualization 46 Maria Ribalta, Pere-Pau Vàzquez, “Visualization is all you need”. UPC GCED 2020.
  • 47. 47 Are Transformers for Language only ? NO !! #ViT Dosovitskiy, Alexey, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn, Xiaohua Zhai, Thomas Unterthiner, Mostafa Dehghani et al. "An image is worth 16x16 words: Transformers for image recognition at scale." ICLR 2021. [blog] [code]
  • 48. Outline 1. Motivation 2. Self-attention 3. Multi-head Attention 4. Positional Encoding 5. The Transformer 48
  • 49. 49 (extra) PyTorch Lab on Google Colab DL resources from UPC Telecos: ● Lectures (with Slides & Videos) ● Labs Gerard Gallego [email protected] Student PhD Universitat Politecnica de Catalunya Technical University of Catalonia
  • 50. 50 Software ● Transformers in HuggingFace. ● GPT-Neo by EleutherAI ○ Similar results to GPT-3, but smaller and open source. ● Andrej Karpathy, minGPT (2020).
  • 51. 51 Learn more Ashish Vaswani, Stanford CS224N 2019.
  • 52. 52 Learn more ● Tutorials ○ Sebastian Ruder, Deep Learning for NLP Best Practices # Attention (2017). ○ Chris Olah, Shan Carter, “Attention and Augmented Recurrent Neural Networks”. distill.pub 2016. ○ Lilian Weg, The Transformer Family. Lil’Log 2020 ● Twitter threads ○ Christian Wolf (INSA Lyon) ● Scientific publications ○ #Perceiver Jaegle, Andrew, Felix Gimeno, Andrew Brock, Andrew Zisserman, Oriol Vinyals, and Joao Carreira. "Perceiver: General perception with iterative attention." arXiv preprint arXiv:2103.03206 (2021). ○ #Longformer Beltagy, Iz, Matthew E. Peters, and Arman Cohan. "Longformer: The long-document transformer." arXiv preprint arXiv:2004.05150 (2020). ○ Katharopoulos, A., Vyas, A., Pappas, N., & Fleuret, F. Transformers are RNS: Fast autoregressive transformers with linear attention. ICML 2020. ○ Siddhant M. Jayakumar, Wojciech M. Czarnecki, Jacob Menick, Jonathan Schwarz, Jack Rae, Simon Osindero, Yee Whye Teh, Tim Harley, Razvan Pascanu, “Multiplicative Interactions and Where to Find Them”. ICLR 2020. [tweet] ○ Self-attention in language ■ Cheng, J., Dong, L., & Lapata, M. (2016). Long short-term memory-networks for machine reading. arXiv preprint arXiv:1601.06733. ○ Self-attention in images ■ Parmar, N., Vaswani, A., Uszkoreit, J., Kaiser, Ł., Shazeer, N., Ku, A., & Tran, D. (2018). Image transformer. ICML 2018. ■ Wang, Xiaolong, Ross Girshick, Abhinav Gupta, and Kaiming He. "Non-local neural networks." In CVPR 2018.