$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Attentionさえあればいい
Search
payanotty
November 03, 2022
Technology
46
5.5k
Attentionさえあればいい
payanotty
November 03, 2022
Tweet
Share
More Decks by payanotty
See All by payanotty
トークナイザー入門
payanotty
4
2.2k
LLM_Prompt_Recovery
payanotty
3
1k
Embeddingモデルを使ったベクトル化のしくみ、fine-tuning手法を解説
payanotty
15
6.1k
Transformerによるテキストベクトル化を解説
payanotty
5
4k
Kaggle_LLMコンペの攻略法を解説.pdf
payanotty
1
1.6k
ManimMLでイケてるアニメーションを作ろう
payanotty
0
780
Lets Finetune LLM
payanotty
3
1.4k
Stable Diffusion Web UI, Let Your Fave Eat Ramen
payanotty
1
1.1k
Lets Finetune Stable Diffusion
payanotty
0
1.3k
Other Decks in Technology
See All in Technology
202512_AIoT.pdf
iotcomjpadmin
0
140
Amazon Bedrock Knowledge Bases × メタデータ活用で実現する検証可能な RAG 設計
tomoaki25
6
2.4k
AI時代のワークフロー設計〜Durable Functions / Step Functions / Strands Agents を添えて〜
yakumo
3
2.2k
Strands Agents × インタリーブ思考 で変わるAIエージェント設計 / Strands Agents x Interleaved Thinking AI Agents
takanorig
5
2.1k
Bedrock AgentCore Memoryの新機能 (Episode) を試してみた / try Bedrock AgentCore Memory Episodic functionarity
hoshi7_n
2
1.9k
投資戦略を量産せよ 2 - マケデコセミナー(2025/12/26)
gamella
0
430
Agent Skillsがハーネスの垣根を超える日
gotalab555
6
4.4k
20251222_サンフランシスコサバイバル術
ponponmikankan
2
140
Connection-based OAuthから学ぶOAuth for AI Agents
flatt_security
0
370
ハッカソンから社内プロダクトへ AIエージェント ko☆shi 開発で学んだ4つの重要要素
leveragestech
0
190
Amazon Quick Suite で始める手軽な AI エージェント
shimy
1
1.9k
20251203_AIxIoTビジネス共創ラボ_第4回勉強会_BP山崎.pdf
iotcomjpadmin
0
140
Featured
See All Featured
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
2
66
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
81
Amusing Abliteration
ianozsvald
0
69
Build The Right Thing And Hit Your Dates
maggiecrowley
38
3k
Done Done
chrislema
186
16k
Docker and Python
trallard
47
3.7k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
280
What's in a price? How to price your products and services
michaelherold
246
13k
Building the Perfect Custom Keyboard
takai
1
660
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
1
30
Designing for humans not robots
tammielis
254
26k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
286
14k
Transcript
Attentionさえあればいい。 早野康太
自己紹介 • 名前 ◦ 早野 康太 • お仕事 ◦ 自然言語モデルの改善
• 趣味 ◦ 猫、犬 ▪ YouTube ◦ ゲーム ▪ 音ゲ、ウマ娘、ギャルゲ ◦ アニメ ▪ 水星の魔女 ▪ ぼっちざろっく (てか秋アニメ豊作すぎヤバスンギ)
自然言語処理 • 深層学習で「ことば」を処理する ◦ 翻訳 ▪ Google翻訳 ▪ DeepL ◦
質問応答 ▪ Alexa ◦ 文章生成 ▪ AIのべりすと ◦ 画像生成 (最近流行ってますね) ▪ Stable Diffusion, NovelAI
最近のAIはすごい • AIのべりすと ◦ 入力した文章の続きをAIが 書いてくれる 出典: https://ai-novel.com 吾輩は猫である。名前はまだない。
最近のAIはすごい • AIのべりすと ◦ 入力した文章の続きをAIが 書いてくれる 出典: https://ai-novel.com
吾輩は猫である。名前はまだない。 そんな冗談が脳裏をよぎるほど、その日、俺の 気分は沈んでいた。 「……」 時刻は午前十一時。場所は近所の公園だ。休 日なだけあってそれなりに人通りもあるが、遊 具で遊ぶ子供の姿はない。皆一様にベンチに 腰掛けて、何やら物思いに耽っているようだ。
最近のAIはすごい • NovelAI ◦ 文章を入力すると絵を描いてくれる • a little girl,
wearing lame t-shirt , eating large cake から生成した画像 →
最近のAIはすごい AIの文章読解能力は飛躍的に向上し 文章を書く、文章をイメージに起こす といったタスクで人間を上回りつつある
最近のAIはすごい • 今日の発表 ◦ そうした進歩の発端となったTransformerについて ▪ コアとなるAttention機構の仕組みを解説 AIの文章読解能力は飛躍的に向上し
文章を書く、文章をイメージに起こす といったタスクで人間を上回りつつある
• Attention Is All You Need (Łukasz Kaiser et al.,
2017) ◦ 文章の単語同士の関連度を測る (Attention) 機構を組み込むことで 自然言語処理モデルの性能が大きく向上 Transformer チノ ちゃん かわいい 推し は 誰 ? 入 力 文 参照情報 チノ ちゃん 以外 ありえん
Transformerの構造 Attention Is All You Need (Łukasz Kaiser et al.,
2017)
• 入力文をベクトル系列に変換 Transformerの構造 Attention Is All You Need (Łukasz Kaiser
et al., 2017)
• 入力文をベクトル系列に変換 Transformerの構造 ご注文はうさぎですか? ご, 注文, は, うさぎ, ですか, ?
0, 1, 2, 3, 4, 5 形態素解析 トークンID化 E 0 , E 1 , E 2 , E 3 , E 4 , E 5 ベクトル化 Attention Is All You Need (Łukasz Kaiser et al., 2017)
• 入力文をベクトル系列に変換 Transformerの構造 Attention Is All You Need (Łukasz Kaiser
et al., 2017) Positional Encoding • Attentionだけではトークンの 位置情報を考慮できない • 位置ごとに異なる値を足して 位置関係を学習できるように ◦ 加える値は完全決め打ち
• 一連の処理をまとめた”ブロック”を 何個も積み上げている Transformerの構造 Multi-Head Attention 残差結合 正規化 Feed
Forward Attention Is All You Need (Łukasz Kaiser et al., 2017)
• 一連の処理をまとめた”ブロック”を 何個も積み上げている ◦ Multi-Head Attention ◦ 残差結合 ◦ 正規化
◦ Feed Forward Transformerの構造 Attention Is All You Need (Łukasz Kaiser et al., 2017)
• 一連の処理をまとめた”ブロック”を 何個も積み上げている ◦ Multi-Head Attention ◦ 残差結合 ◦ 正規化
◦ Feed Forward Transformerの構造 入力ベクトル 出力ベクトル Attention Is All You Need (Łukasz Kaiser et al., 2017)
入力ベクトル 出力ベクトル 残差結合 x’ = x + Attention(x) • Attention結果に処理前の値を
加えることで勾配消失を防ぐ • 残差結合はResNet(2015)で 効果が実証された Attention以外の要素 Attention Is All You Need (Łukasz Kaiser et al., 2017)
入力ベクトル 出力ベクトル ふつうのFeed Forward Attention以外の要素 Attention Is All You
Need (Łukasz Kaiser et al., 2017)
• 一連の処理をまとめた”ブロック”を 何個も積み上げている ◦ Multi-Head Attention ◦ 残差結合 ◦ 正規化
◦ Feed Forward Transformerの構造 入力ベクトル 出力ベクトル キモとなるところ Attention Is All You Need (Łukasz Kaiser et al., 2017)
• Attentionとは、入力ベクトルを別の参照情報を用いて 別のベクトルへと変換する仕組み QKV Attention 入力ベクトル q 出力ベクトル q’
• Attentionとは、入力ベクトルを別の参照情報を用いて 別のベクトルへと変換する仕組み QKV Attention 入力ベクトル q 出力ベクトル q’ 参照情報
k, v
QKV Attention q query 変換したい ベクトル key, value ベクトルを変換する際 参照する情報
keyとvalueが辞書的に 一対一に対応している (k 1 , v 1 ), (k 2 , v 2 )
QKV Attention qT k 1 q qT k 2 key,
value ベクトルを変換する際 参照する情報 keyとvalueが辞書的に 一対一に対応している (k 1 , v 1 ), (k 2 , v 2 )
QKV Attention qT k 1 q qT k 2 queryとkeyとの関連度を
内積を取ることで数値化する 1.2 3.6
QKV Attention qT k 1 q qT k 2 0-1にスケールした後
softmaxを取り 関連度の和を1に正規化 1.2 3.6 0.4 0.6 scale & softmax
QKV Attention qT k 1 q qT k 2 1.2
3.6 0.4 0.6 scale & softmax v 1 v 2 正規化した関連度で valueに重みをつける
QKV Attention qT k 1 q qT k 2 1.2
3.6 0.4 0.6 v 1 v 2 scale & softmax + q’
k 1 q k 2 QKV Attention v 1 v
2 query 変換したい ベクトル key, value ベクトルを変換する際 参照する情報 keyとvalueが辞書的に 一対一に対応している q’ output queryを元に key, valueから 情報を引き出す
Attention定式化
Attention定式化 Q K V 1行ごとに別々の q, k, vに対応
Q K V Attention定式化 関連度計算 & スケーリング
Q K V Attention定式化 queryとkeyの 関連度で valueを重み付け
TransformerのQとかKとかVってどこから来るの? Attention Is All You Need (Łukasz Kaiser et al.,
2017)
TransformerのQとかKとかVってどこから来るの? query key value • 矢印が三股になっている → 同じ情報をq, k, vに使ってる
• Self-Attention(自己注意機構) Attention Is All You Need (Łukasz Kaiser et al., 2017)
Multi-Head Attention (Self-Attention発展) • Q, K, Vをh個に分割 • h個分のAttentionを計算 •
計算したAttentionを結合 Attention Is All You Need (Łukasz Kaiser et al., 2017)
q Multi-Head Attention (Self-Attention発展) 512
q Multi-Head Attention (Self-Attention発展) 512 WQ 512
q WQ 512 512 512 / 8 = 64 Multi-Head
Attention (Self-Attention発展)
q WQ 512 512 512 / 8 = 64 q’
Multi-Head Attention (Self-Attention発展) = 64
q WQ 512 512 512 / 8 = 64 q’
Multi-Head Attention (Self-Attention発展) = 64 • 512次元空間から64次元空間への線形写像
q 512 Multi-Head Attention (Self-Attention発展) 64 WQ 1 q’ q
q’ W 3次元→2次元部分空間の 線形写像 (実際は512→64)
q 512 Multi-Head Attention (Self-Attention発展) 64 WQ 1 q’ WQ
2 q q’ W 3次元→2次元部分空間の 線形写像 (実際は512→64)
q 512 Multi-Head Attention (Self-Attention発展) 64 WQ 1 q’ WQ
2 q q’ W 3次元→2次元部分空間の 線形写像 (実際は512→64) qへの光の当て方 (どの視点から見るか) を決めるパラメータ
q 512 Multi-Head Attention (Self-Attention発展) 64 WQ 1 q’ WQ
2 q q’ W 3次元→2次元部分空間の 線形写像 (実際は512→64) qへの光の当て方 (どの視点から見るか) を決めるパラメータ WQ 8
q 512 Multi-Head Attention (Self-Attention発展) 64 q’ k’ q q’
W 3次元→2次元部分空間の 線形写像 (実際は512→64) qへの光の当て方 (どの視点から見るか) を決めるパラメータ WK 1 WK 2 WK 8
q 512 Multi-Head Attention (Self-Attention発展) 64 q’ k’ q q’
W 3次元→2次元部分空間の 線形写像 (実際は512→64) qへの光の当て方 (どの視点から見るか) を決めるパラメータ v’ WV 1 WV 2 WV 8
q 512 Multi-Head Attention (Self-Attention発展) 64 q’ k’ v’ head
1 head 2 head 8 Attention Attention Attention 64
q 512 Multi-Head Attention (Self-Attention発展) 64 q’ k’ v’ head
1 head 2 head 8 head 1 head 2 head 8 Concat Concat Attention Attention Attention 512
Multi-Head Attention (Self-Attention発展) • Self-Attention ✕ Multi-Head ◦ ただ自分に注目するだけでなく “多角的に”見た自分との
関連度を測る • Transformerではベクトルの 投影の仕方(W)を 学習パラメータにしている
• ざっくりいうと、Transformer = Attention層を複数積み上げたモデル ◦ 原点のTransformerから学習方法などを工夫することで さまざまなモデルへと派生 Transformerから他のモデルへの派生 Transformer •
BERT • RoBERTa • DeBERTa Encoderのみ • GPT Decoderのみ • BART • T5 Enc. Dec. • Vision Transformer 画像
• Bidirectional Encoder Representations from Transformers ◦ BERT: Pre-training of
Deep Bidirectional Transformers for Language Understanding ◦ Transformerによる双方向のエンコード表現 ▪ Transformerモデルの一部分を利用したモデル ◦ Googleが2018年に発表 • 当時の自然言語処理タスクの最高記録を軒並み塗り替えた • 転移学習 (finetuning) により あらゆる自然言語処理タスクに応用可能な汎用性の高さ Transformerから他のモデルへの派生
• GPT (Generative Pretrained Transformers) ◦ Improving Language Understanding by
Generative Pre-Training ◦ OpenAIが発表している、文章生成に特化したモデル ▪ 現在はGPT3まで公開されている ◦ 文章要約、翻訳、質問応答などで高い性能 ▪ 冒頭で紹介したAIのべりすとにもこのモデルが使われている ◦ TransformersのDecoder部分を使っている Transformerから他のモデルへの派生
• CLIP (Constractive Language-Image Pretraining) ◦ Learning Transferable Visual Models
From Natural Language Supervision ◦ 画像に対して正しいテキストをラベルとして割り当てる ▪ 事前学習方法を工夫することで zero-shot(初めてみるデータ)でも高い精度を出している ◦ テキストエンコーダー部分にTransformerが利用されている ◦ 冒頭で紹介したNovelAIのほか、 Stable Diffusionの派生モデルにおいて利用されている Transformerから他のモデルへの派生
• A Survey of Transformers (TIANYANG LIN et. al.,
2021) ◦ Transformer派生についてのサーベイ ◦ 膨大な数のTransformer派生について 詳細にまとめられている ◦ もっと詳しく知りたい方は こちらを読まれるのをおすすめします Transformerから他のモデルへの派生
• 近代の自然言語モデルのめざましい進歩は Transformerから始まった (Attention is All You Need) ◦ 今どきの自然言語モデルはだいたいTransformerの派生
▪ BERT, T5, GPT, … • Attentionの工夫 ◦ Self-Attention ▪ 入力された信号のうちどの部分に注目すればよいかを計算 ◦ Multi-Head化 ▪ “さまざまな視点から見た”ベクトルのSelf-Attention ▪ ベクトルをどの視点から見るかをパラメータとして学習 まとめ