Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
知らないとやばい!最新トレンドの根幹技術 Attention
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Shotaro
December 14, 2022
73
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
知らないとやばい!最新トレンドの根幹技術 Attention
LabTech Talkの講演資料です。
https://labtechtalk-event221209.peatix.com/view
Shotaro
December 14, 2022
Featured
See All Featured
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.6k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
630
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Done Done
chrislema
187
17k
The Curious Case for Waylosing
cassininazir
1
570
It's Worth the Effort
3n
188
29k
Leo the Paperboy
mayatellez
10
2.4k
Skip the Path - Find Your Career Trail
mkilby
1
260
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
The Pragmatic Product Professional
lauravandoore
37
7.5k
Transcript
Attentionの徹底理解 2022 / 12 / 9 徳永 匡⾂ (とくなが まさおみ)
1
⾃⼰紹介 2 徳永 匡⾂ Tokunaga Masaomi 宮城県 育った 場所 野村総合研究所
AIソリューション推進部 AI tech lab. 所属 扱う分野 コンピュータビジョン / ⾃然⾔語処理 • 論⽂調査 / 実験 • AIを⽤いた事業テーマ探索 ChatGPT マイブーム Vision Transformer⼊⾨ (技術評論社、2022年9⽉) 拙著 (共著) ブログ投稿 / 勉強会開催 世界に衝撃を与えた画像⽣成AI「Stable Diffusion」を徹底解説︕ その他 活動 Twitter : @omiita_atiimo Qiita: @omiita
本⽇の流れ § AttentionなしでいまのAIは語れない § Self-Attentionの仕組み § 4コマ漫画で理解しよう § 図解で理解しよう §
数式で理解しよう § Self-Attentionの実装(PyTorch) 3
本⽇の流れ § AttentionなしでいまのAIは語れない § Self-Attentionの仕組み § 4コマ漫画で理解しよう § 図解で理解しよう §
数式で理解しよう § Self-Attentionの実装(PyTorch) 4
AttentionなしでいまのAIは語れない 5 Transformer GPT-3 DALL-E 2 Vision Transformer BERT Stable
Diffusion
AttentionなしでいまのAIは語れない 6 Transformer GPT-3 DALL-E 2 Vision Transformer BERT Stable
Diffusion これらのモデルで使われている QKVのSelf-Attentionを取り扱います
本⽇の流れ § AttentionなしでいまのAIは語れない § Self-Attentionの仕組み § 4コマ漫画で理解しよう § 図解で理解しよう §
数式で理解しよう § Self-Attentionの実装(PyTorch) 7
本⽇の流れ § AttentionなしでいまのAIは語れない § Self-Attentionの仕組み § 4コマ漫画で理解しよう § 図解で理解しよう §
数式で理解しよう § Self-Attentionの実装(PyTorch) 8
Self-Attentionの仕組み 4コマ漫画で理解しよう 9 より良い⾃分になりたいAさんの物語
Self-Attentionの仕組み 4コマ漫画で理解しよう 10 「より良い」とは「⾃分似ていること」 Aさんは、Bさん、Cさん、Dさんを連れてきました
Self-Attentionの仕組み 4コマ漫画で理解しよう 11 Aさんはみんなの情報を聞きます AさんはBさんとは似ているが、Cさん・Dさんとは似ていません
Self-Attentionの仕組み 4コマ漫画で理解しよう 12 類似度にそってみんなをガッチャンコします このときAさん⾃⾝も含みます
Self-Attentionの仕組み 4コマ漫画で理解しよう 13 Aさんはより良い⾃分になりました。 Bさん、Cさん、Dさんも同じ⽅法でより良い⾃分になりました
Self-Attentionの仕組み 4コマ漫画で理解しよう 14 Self-Attentionとは、 ⾃分に似た⼈たちを集約して、 より良い⾃分になる ① 情報抽出 ② 類似度
③ ガッチャンコ
本⽇の流れ § AttentionなしでいまのAIは語れない § Self-Attentionの仕組み § 4コマ漫画で理解しよう § 図解で理解しよう §
数式で理解しよう § Self-Attentionの実装(PyTorch) 15
Self-Attentionの仕組み 「図解で理解しよう」の前に・・・。 § 個⼈的に、画像の例がわかりやすいのでここからは パッチ(Patch)に対してSelf-Attention。 § パッチとは、画像を分割したやつ。 16 パッチ 分割
Self-Attentionの仕組み 「図解で理解しよう」の前に・・・。 § 個⼈的に、画像の例がわかりやすいのでここからは パッチ(Patch)に対してSelf-Attention。 § パッチとは、画像を分割したやつ。 § パッチは、4コマでいうAさんやBさんなどに対応 17
分割
Self-Attentionの仕組み 「図解で理解しよう」の前に・・・。 § パッチをぺしゃんこにして( flattenして)ベクトルに。 18
Self-Attentionの仕組み 「図解で理解しよう」の前に・・・。 § これらを合わせて、⼊⼒画像は右のように表せる § パッチごとにflattenしただけ。 19 パッチごとに flatten この表現に対して
Self-Attentionをおこなう
Self-Attentionの仕組み 図解で理解しよう 20 0.8 0.2 0.2 0.6 0.2 0.5 0.5
0.2 0.8 X X ! " # ① 情報抽出 ② 類似度 ③ ガッチャンコ
Self-Attentionの仕組み 図解で理解しよう 21 0.8 0.2 0.2 0.6 0.2 0.5 0.5
0.2 0.8 X X ! " # ① 情報抽出 =埋め込み ② 類似度 =内積 ③ ガッチャンコ =加重和
Self-Attentionの仕組み ①埋め込み 22 ! " # それぞれ異なる 線形層で埋め込む 4 ×
&' 形状 4 × &' &' × &' ⼊⼒ 線形層 !, ", #
Self-Attentionの仕組み ②内積 23 0.8 0.2 0.2 0.6 0.2 0.5 0.5
0.2 0.8 X ! "# ⾏列積で まとめて内積 (キー "は転置) 4 × &' &' × 4 4 × 4 形状 ⾏⽅向でSoftmax → 合計が1になっている Softmax クエリ キー Attention Weight
Self-Attentionの仕組み ③加重和 24 0.8 0.2 0.2 0.6 0.2 0.5 0.5
0.2 0.8 4 × 4 # 4 × $% 形状 X ⾏列積で まとめて加重和 4 × $% Attention Weight バリュー 出⼒
Self-Attentionの仕組み (再掲)図解で理解しよう 25 0.8 0.2 0.2 0.6 0.2 0.5 0.5
0.2 0.8 X X ! " # ① 情報抽出 =埋め込み ② 類似度 =内積 ③ ガッチャンコ =加重和
Self-Attentionの仕組み テキストの場合も完全に同じ︕ 26 0.8 0.2 0.2 0.6 0.2 0.5 0.5
0.2 0.8 X X ! " # ① 情報抽出 =埋め込み ② 類似度 =内積 ③ ガッチャンコ =加重和 This is a dog This is a dog This is a dog This is a dog This is a dog This is a dog This is a dog
本⽇の流れ § AttentionなしでいまのAIは語れない § Self-Attentionの仕組み § 4コマ漫画で理解しよう § 図解で理解しよう §
数式で理解しよう § Self-Attentionの実装(PyTorch) 27
Self-Attentionの仕組み 数式で理解しよう 1. 埋め込み 2. 内積 3. 加重和 28 スケール化
ドット積Self-Attention
本⽇の流れ § AttentionなしでいまのAIは語れない § Self-Attentionの仕組み § 4コマ漫画で理解しよう § 図解で理解しよう §
数式で理解しよう § Self-Attentionの実装(PyTorch) 29
Self-Attentionの実装(PyTorch) 30 コードへ移ります
Self-Attention まとめ 31 0.8 0.2 0.2 0.6 0.2 0.5 0.5
0.2 0.8 X X ! " # ① 情報抽出 ② 類似度 ③ ガッチャンコ
補⾜︓いろいろなAttention Soft-Attention vs Hard-Attention § Soft-Attentionは、ガッチャンコ § Hard-Attentionは、1つだけをえらぶ。 32 0.8
0.2 0.2 0.6 0.2 0.5 0.5 0.2 0.8 1.0 1.0 1.0 1.0 Soft-Attention Hard-Attention
補⾜︓いろいろなAttention Cross-Attention § Stable Diffusionに使われている 33 0.8 0.2 0.2 0.6
0.2 0.5 0.5 0.2 0.8 X X ! " # ② 類似度 ③ ガッチャンコ This is a library This is a library This is a library This is a library キー / バリューが クエリと異なる ① 情報抽出