Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Transformerによるテキストベクトル化を解説
Search
payanotty
January 18, 2024
Technology
6
4.1k
Transformerによるテキストベクトル化を解説
payanotty
January 18, 2024
Tweet
Share
More Decks by payanotty
See All by payanotty
トークナイザー入門
payanotty
4
2.4k
LLM_Prompt_Recovery
payanotty
3
1k
Embeddingモデルを使ったベクトル化のしくみ、fine-tuning手法を解説
payanotty
15
6.3k
Kaggle_LLMコンペの攻略法を解説.pdf
payanotty
1
1.6k
ManimMLでイケてるアニメーションを作ろう
payanotty
0
800
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
Deffusion解説
payanotty
3
960
Other Decks in Technology
See All in Technology
Claude Codeが爆速進化してプラグイン追従がつらいので半自動化した話 ver.2
rfdnxbro
0
510
AWS DevOps Agent vs SRE俺 / AWS DevOps Agent vs me, the SRE
sms_tech
3
540
JAWS DAYS 2026 ExaWizards_20260307
exawizards
0
410
[JAWSDAYS2026]Who is responsible for IAM
mizukibbb
0
440
8万デプロイ
iwamot
PRO
2
230
AI は "道具" から "同僚" へ 自律型 AI エージェントの最前線と、AI 時代の人材の在り方 / Colleague in the AI Era - Autonomous AI Seminar 2026 at Niigata
gawa
0
110
新職業『オーケストレーター』誕生 — エージェント10体を同時に回すAgentOps
gunta
4
1.8k
アーキテクチャモダナイゼーションを実現する組織
satohjohn
0
190
kintone開発のプラットフォームエンジニアの紹介
cybozuinsideout
PRO
0
860
OCI Security サービス 概要
oracle4engineer
PRO
2
13k
vLLM Community Meetup Tokyo #3 オープニングトーク
jpishikawa
0
320
Datadog の RBAC のすべて
nulabinc
PRO
3
450
Featured
See All Featured
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
250
Documentation Writing (for coders)
carmenintech
77
5.3k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
390
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
83
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
68
Measuring & Analyzing Core Web Vitals
bluesmoon
9
780
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Claude Code のすすめ
schroneko
67
220k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
110k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Typedesign – Prime Four
hannesfritz
42
3k
Design in an AI World
tapps
0
170
Transcript
Transformerを使った テキストベクトル化の基本 早野康太
自己紹介 • 名前 ◦ 早野 康太 • お仕事 ◦ 自然言語モデルの改善
• 今期アニメ ◦ ダンジョン飯 ◦ 姫様“拷問”の時間です ◦ 魔法少女にあこがれて
• Attention Is All You Need (Łukasz Kaiser et al.,
2017) ◦ 文章の単語同士の関連度を測る (Attention) 機構を組み込むことで 自然言語処理モデルの性能が大きく向上 ◦ GPTなどの文章生成モデル ▪ → TransformerモデルのDecoder部分を利用 ◦ テキストベクトル化用のモデル ▪ → TransformerモデルのEncoder部分を利用 Transformerモデル
• A Survey of Transformers (TIANYANG LIN et. al.,
2021) ◦ Transformer派生についてのサーベイ ◦ 膨大な数のTransformer派生について 詳細にまとめられている ◦ もっと詳しく知りたい方は こちらを読まれるのをおすすめします Transformerから他のモデルへの派生
Transformerモデルを使ったテキストベクトル化 • Transformerモデルは文章をベクトル(数値)に落とし込むことが得意 ◦ ベクトル同士の類似度 (近さ) を測って検索に応用できる ◦ いったんベクトルに落とし込んでしまえば 画像処理や音声処理などと文章処理を組み合わせることもできる
吾輩は猫である Transformer 0.1, 0.3, 0.04, … 文章(文字列) ベクトル 画像生成 モデル 類似度 検索
Attentionによる単語のベクトル化 吾輩 は 猫 である 。 吾輩 は 猫 である
。 文章を単語単位に分かち書き(トークナイズ) 各単語に対応するベクトル
Attentionによる単語のベクトル化 吾輩 は 猫 である 。 吾輩 は 猫 である
。 0.1 0.3 -0.5 0.8 長方形はベクトルだと思ってください 文章を単語単位に分かち書き(トークナイズ)
Attentionによる単語のベクトル化 吾輩 は 猫 である 。 吾輩 は 猫 である
。 文章を単語単位に分かち書き(トークナイズ) 各単語に対応するベクトル 単語に対応する新しいベクトル ベクトル同士の内積の値(類似度) ×
余談: ベクトル同士の”類似度”の測り方 近い 遠い • 内積 ◦ 近い(同じ方向を向いている)ほど大きくなる • コサイン類似度
◦ 内積を-1 ~ 1に正規化 (要はcosθ ) 内積 = |a||b|cosθ
AttentionからTransformerへ 吾輩 は 猫 である 。 Attention Attention Transformer 吾輩
は 猫 である 。 BERTやGPTをはじめとしたTransformer系列のモデルは Attentionを繰り返して文章をベクトルの連なりに変換している
AttentionからTransformerへ 吾輩 は 猫 である 。 Attention Attention Transformer 吾輩
は 猫 である 。 BERTやGPTをはじめとしたTransformer系列のモデルは Attentionを繰り返して文章をベクトルの連なりに変換している 一番はじめのベクトルは ランダム初期化 (学習の中で最適化されていく)
文章のベクトル化 吾輩 は 猫 である 。 Attention Attention Transformer 吾輩
は 猫 である 。 [CLS] [CLS] 文頭に特別な トークンを追加 • CLS Pooling ◦ 文頭の特別なトークンのベクトルを文章ベクトルとして使う • Average Pooling ◦ 全トークンの値を平均して文章ベクトルとして使う
ベクトル化に特化させるためのfine-tuning Query: 吾輩は猫であるの作者は? Negative Passage: 『人間失格』(にんげんしっかく)は、太宰 治による中編小説。 ベクトル化&類似度計算 ポジティブ類似度
ネガティブ類似度 Positive Passage: 『吾輩は猫である』(わがはいはねこであ る)は、夏目漱石の長編小説であり、処女 小説である。 • ポジティブ類似度が高く、ネガティブ類似度が低くなるように ロス関数を設定して学習する ◦ ロス = - ポジティブ / (ポジティブ + ネガティブ)
ベクトル化のベンチマーク • MTEB: Massive Text Embedding Benchmark ◦ テキスト埋め込みモデルのための大規模ベンチマーク ◦
8つのタスクにわたり56のデータセットが含まれる
ベンチマーク上位のモデルたち • MTEB Leaderboard - a Hugging Face Space by
mteb ◦ AnglE-optimized Text Embeddings ◦ Cohere/Cohere-embed-english-v3.0 · Hugging Face ◦ BAAI/bge-large-en-v1.5 · Hugging Face ◦ intfloat/e5-large-v2 · Hugging Face
RAG (Retrieval Augmented Generation) 質問 + 選択肢 Wikipedia passages dump
Wikipedia embeddings あらかじめベクトル化 ベクトル化 embedding ベクトル類似度検索 関連する文章 (Context) LLMへのインプット Wikipedia記事から 検索してContextを取得 ベクトル検索用に調整された言語モデルを使う (質問に回答するモデルとは別物)
Stable Diffusion (画像生成モデルへの応用) raw pixel value VAE latent
noisy latent + noise input text Text Encoder embedding UNET prediction loss velocity 生成したい画像についての文章を ベクトル化して生成モデルに与える
音楽生成モデル • Suno AI ◦ 自然言語で歌詞や曲調を指定すると その通りに音楽を生成してくれる ◦
具体的なモデルは公開されていないが 内部では文章→ベクトルの変換を通して 文章情報を生成モデルに与えている......はず!
まとめ • Attention機構を利用したTransformerによって 高品質なテキストベクトル化が実現可能になった • ベクトル化のクオリティが向上することで 検索だけでなく文章→画像や文章→音楽などマルチモーダルなモデルの クオリティも格段に向上している