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
4
3.3k
Transformerによるテキストベクトル化を解説
payanotty
January 18, 2024
Tweet
Share
More Decks by payanotty
See All by payanotty
トークナイザー入門
payanotty
2
1.6k
LLM_Prompt_Recovery
payanotty
3
930
Embeddingモデルを使ったベクトル化のしくみ、fine-tuning手法を解説
payanotty
15
5.4k
Kaggle_LLMコンペの攻略法を解説.pdf
payanotty
1
1.4k
ManimMLでイケてるアニメーションを作ろう
payanotty
0
730
Lets Finetune LLM
payanotty
3
1.3k
Stable Diffusion Web UI, Let Your Fave Eat Ramen
payanotty
1
1.1k
Lets Finetune Stable Diffusion
payanotty
0
1.3k
Deffusion解説
payanotty
3
840
Other Decks in Technology
See All in Technology
Prox Industries株式会社 会社紹介資料
proxindustries
0
260
Абьюзим random_bytes(). Фёдор Кулаков, разработчик Lamoda Tech
lamodatech
0
330
AWS CDK 実践的アプローチ N選 / aws-cdk-practical-approaches
gotok365
6
680
Кто отправит outbox? Валентин Удальцов, автор канала Пых
lamodatech
0
330
PHPでWebブラウザのレンダリングエンジンを実装する
dip_tech
PRO
0
200
Clineを含めたAIエージェントを 大規模組織に導入し、投資対効果を考える / Introducing AI agents into your organization
i35_267
4
1.5k
20250625 Snowflake Summit 2025活用事例 レポート / Nowcast Snowflake Summit 2025 Case Study Report
kkuv
1
290
生成AIで小説を書くためにプロンプトの制約や原則について学ぶ / prompt-engineering-for-ai-fiction
nwiizo
3
730
20250623 Findy Lunch LT Brown
3150
0
840
強化されたAmazon Location Serviceによる新機能と開発者体験
dayjournal
2
200
MySQL5.6から8.4へ 戦いの記録
kyoshidaxx
1
170
Snowflake Summit 2025全体振り返り / Snowflake Summit 2025 Overall Review
mtpooh
2
390
Featured
See All Featured
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
31
1.2k
Documentation Writing (for coders)
carmenintech
71
4.9k
Building a Modern Day E-commerce SEO Strategy
aleyda
41
7.3k
Making Projects Easy
brettharned
116
6.3k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
35
2.3k
Docker and Python
trallard
44
3.4k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
657
60k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
357
30k
Stop Working from a Prison Cell
hatefulcrawdad
270
20k
[RailsConf 2023] Rails as a piece of cake
palkan
55
5.6k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
53
2.8k
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によって 高品質なテキストベクトル化が実現可能になった • ベクトル化のクオリティが向上することで 検索だけでなく文章→画像や文章→音楽などマルチモーダルなモデルの クオリティも格段に向上している