SlideShare a Scribd company logo
1 of 38
BERT大解明
株式会社MICIN
データサイエンスインターン 尾原
2020年1月22日 DS勉強会
All rights reserved| micin.jp
発表の目的
強力な言語モデルの1つである
BERTのイメージを掴む
All rights reserved| micin.jp 33
はじめに
BERTの数式部分について
数式をパワポに打ち込む気力がなかったので
kibe.laに記載しました。
ここでは抽象的なことしか扱わないため、
BERTを数式ベースで
眺めてみたいという方はこちらを見てね
https://micin.kibe.la/notes/2444
All rights reserved| micin.jp
目次
BERTの概要紹介1
4
2
3 BERTは何をみているのか
BERTの事前学習
All rights reserved| micin.jp 55
BERTって?
自然言語処理に使用する
事前学習済み言語モデル
(つよつよです)
All rights reserved| micin.jp 66
BERTの略称
All rights reserved| micin.jp 77
BERTの略称
Bidirectional Encoder Representations
from Transformers
これがモデルの中身の全てを示している
Transformerの2方向の
エンコーダ表現
と直訳ができます
All rights reserved| micin.jp 88
Transformer
Attentionと呼ばれる機構のみで構成され
ているEncoder-Decoderモデル。
• Attentionを使って文字列をエンコード
• Attentionを使ってデコードする
このモデルを発表した論文のタイトルは
「Attention is All You Need」
All rights reserved| micin.jp 99
Transformer
この部分を使う
(Encoder)
右半分が
Decoder
All rights reserved| micin.jp 1010
BERTのモデル構造(概略)
TransformerのEncoder部分を複数重ね
たものがBERT本体のモデル構造の全て
とてもシンプル!
だけど大きいんです
All rights reserved| micin.jp 1111
BERTのモデル構造(概略)
パラメータ数が O(108)
小さいモデルでも1枚のGPU(8GB)で訓
練しようとするとバッチサイズが2にな
るレベル
→用途に合わせてモデルの大きさを変え
たものが公開される
All rights reserved| micin.jp 1212
BERTのモデル構造(概略)
BERTbase : 1億パラメータ
BERTlarge : 3億パラメータ
All rights reserved| micin.jp 1313
BERTの出力と入力
“I have a pen.” が入力の時
𝑋 = 𝑥𝐼, 𝑥ℎ𝑎𝑣𝑒, 𝑥 𝑎, 𝑥 𝑝𝑒𝑛
𝑇
𝑥𝑖 ∈ ℝ 𝑊
出力は
𝑌 = 𝑦𝐼, 𝑦ℎ𝑎𝑣𝑒, 𝑦𝑎, 𝑦𝑝𝑒𝑛
𝑇
𝑦𝑖 ∈ ℝ 𝐹
, F ∈ {768,1024}
(厳密には文章の先頭などに特殊トークンが
設置される)
詳しい式部分の解説はkibe.laにて公開しています
All rights reserved| micin.jp 1414
BERTがやっていること
BERTが行っているのは
基本的には文章の単語(token)ごとの
エンコードのみ
特定タスク利用にはデコードする部分を
付け加えて利用する
(大抵全結合層を1つ加える)
All rights reserved| micin.jp 1515
BERTがやっていること
エンコードしかしないが、エンコード部分は
いろんなタスクに共通するのでは
↓
デコード部分だけ入れ替えれば使い回しがで
きる(はず)
↓
エンコード部分だけ事前に特定のタスクで学
習させて、色々なタスクに応用しよう
All rights reserved| micin.jp 1616
使いまわした結果
これまでの既存の10を超えるタスクに
おいて歴代最高スコア(SOTA; State of
The Art)を達成(モデル発表当時)
GLUEタスク: (General Language Understand Evaluation)
いくつかの自然言語処理タスクをまとめたもの
Jacob Devlin et al.(2018). BERT: Pre-training of Deep
Bidirectional Transformers for Language Understanding. より
All rights reserved| micin.jp 1717
使いまわした結果
SQuAD 1.1
SQuAD 2.0
SWAG
人間超えるタスクも
Jacob Devlin et al.(2018). BERT: Pre-training of Deep
Bidirectional Transformers for Language Understanding. より
All rights reserved| micin.jp 18
今、
タスクのスコアについて
出てきたので
All rights reserved| micin.jp 19
現在GLUEでの
LeaderBoardが
どうなっているかを
軽く覗いてみます
All rights reserved| micin.jp 20
2020/3/13時点
総合スコアではヒトは負けているが、
タスクごとにみるとヒトがまだ優位を
保っているものもある
上位5つは全てTransformerベースのモデル
https://gluebenchmark.com/leaderboard
All rights reserved| micin.jp
目次
BERTの概要紹介1
21
2
3 BERTは何をみているのか
BERTの事前学習
All rights reserved| micin.jp 22
事前学習
このようなタスクにするために必要不可欠なのが、
大規模コーパスを用いた事前学習
オリジナルでは主に2つのタスクを解かせている
• Masked Language Modeling (MLM)
一定確率で単語(token)を隠し、隠した部分が
どんな単語かを予測(多クラス分類)
• Next Sentence Prediction (NSP)
ランダムに接合した2つの文章が関連があるか
どうかを判定(2値分類)
All rights reserved| micin.jp 23
事前学習
MLMとNSPは同時並行で学習させていく
(MLMとNSPタスクによって算出された損失を元
に学習をしていく)
これらのタスクそのものを入れ替えることも改善
の一手
All rights reserved| micin.jp 24
事前学習
入力と出力は以下のイメージ
http://kento1109.hatenablog.com/entry/2019/04/28/142507
All rights reserved| micin.jp 25
NSPタスクはあまり意味がない?
(Yang et al., 2019; Liu et al., 2019)
↓
ランダムに入れ替えた文章を並べ直すというタス
クに変更
(ALBERT) (Lan et al., 2019)
事前学習
All rights reserved| micin.jp 26
MLMで、単語(token)を複数マスクするとマス
クされたもの同士の依存関係はモデリングでき
ない
↓
単語をランダムに並べ替えたものを予測するタ
スクに変更
(XLNet)(Yang et al.,2019)
事前学習
All rights reserved| micin.jp 27
MLMで、単語(token)を複数マスクするとマスク
されたもの同士の依存関係はモデリングできない
↓
似たような単語で入れ替えたものに
対して、入れ替えを検知する
(ELECTRA) (Kevin et al., 2020)
事前学習
All rights reserved| micin.jp 28
事前学習
膨大な計算量
BERTbase : TPU 4枚(16チップ)で丸4日間
BERTlarge : TPU16枚(64チップ)で丸4日間
対象コーパス :
BookCorpus 1億 words
English Wikipedia : 25億 words
All rights reserved| micin.jp 2929
ここまでのまとめ
• BERTは事前学習済みの学習モデル
• AttentionベースのTransformerが構成単位と
なる
• 文章をエンコードするのが役割
• 様々なタスクに使い回しできる
• スコアめっちゃすごい
All rights reserved| micin.jp
目次
BERTの概要紹介1
30
2
3 BERTは何を見ているのか
BERTの事前学習
All rights reserved| micin.jp 31
Do Attention Heads in BERT Track Syntactic
Dependencies?
• BERTのAttention Headsが係り受け解析を内
在的にモデル化しているかどうかを検証した論
文
• 答えは一部的にyes。
• (nsubj, obj, conjなどは良好に取得できた)
• 一方で、係り受け木を完全に生成できるような
Attention Headは存在しなかった
Attentionは何をモデル化しているのか
All rights reserved| micin.jp 32
Attentionは何をモデル化しているのか
2つのやり方で係受け木を作成した時のそれぞれ
のスコア
(右から二番目がbaseline)
All rights reserved| micin.jp 33
Attentionから解釈をすることは難しい
Attention is not Explainable
BERTで学習されているAttentionの重みは説
明可能性を持っていないとする研究結果を発
表。
• Attentionの重みと、タスクを解く上で重要
視される単語とに関連がない
• Attentionの重みを入れ替えても精度に差が
生じない
All rights reserved| micin.jp 34
ここまでのまとめ
• Attentionの中身が何を見ているのかと
いう解釈は難しい
• Attentionの中身の一部を使うと係り受
け解析の情報を抽出することも可能
All rights reserved| micin.jp 35
参考になるスライド
BERT系列のモデルについて
非常によくまとめられたスライドが存在するので
ぜひこちらもご覧ください。
西田京介さんによって作成されたスライド
「事前学習済言語モデルの動向」
https://speakerdeck.com/kyoun/survey-of-
pretrained-language-models-f6319c84-a3bc-
42ed-b7b9-05e2588b12c7
All rights reserved| micin.jp 36
まとめ
All rights reserved| micin.jp 37
まとめ
• BERTの概要についてざっくりと解説した
個人の感想として、BERTはまだまだ大規模コー
パスのパターンを全部覚え込んだモデルに過ぎな
く、言語の理解をしているとは考えにくい。
我々の持っている知識までもモデルとして考慮で
きるようになれば更に強いモデルが出てくるかも
しれない。
All rights reserved| micin.jp 38
終わり

More Related Content

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 

200122 bert slideshare

  • 2. All rights reserved| micin.jp 発表の目的 強力な言語モデルの1つである BERTのイメージを掴む
  • 3. All rights reserved| micin.jp 33 はじめに BERTの数式部分について 数式をパワポに打ち込む気力がなかったので kibe.laに記載しました。 ここでは抽象的なことしか扱わないため、 BERTを数式ベースで 眺めてみたいという方はこちらを見てね https://micin.kibe.la/notes/2444
  • 4. All rights reserved| micin.jp 目次 BERTの概要紹介1 4 2 3 BERTは何をみているのか BERTの事前学習
  • 5. All rights reserved| micin.jp 55 BERTって? 自然言語処理に使用する 事前学習済み言語モデル (つよつよです)
  • 6. All rights reserved| micin.jp 66 BERTの略称
  • 7. All rights reserved| micin.jp 77 BERTの略称 Bidirectional Encoder Representations from Transformers これがモデルの中身の全てを示している Transformerの2方向の エンコーダ表現 と直訳ができます
  • 8. All rights reserved| micin.jp 88 Transformer Attentionと呼ばれる機構のみで構成され ているEncoder-Decoderモデル。 • Attentionを使って文字列をエンコード • Attentionを使ってデコードする このモデルを発表した論文のタイトルは 「Attention is All You Need」
  • 9. All rights reserved| micin.jp 99 Transformer この部分を使う (Encoder) 右半分が Decoder
  • 10. All rights reserved| micin.jp 1010 BERTのモデル構造(概略) TransformerのEncoder部分を複数重ね たものがBERT本体のモデル構造の全て とてもシンプル! だけど大きいんです
  • 11. All rights reserved| micin.jp 1111 BERTのモデル構造(概略) パラメータ数が O(108) 小さいモデルでも1枚のGPU(8GB)で訓 練しようとするとバッチサイズが2にな るレベル →用途に合わせてモデルの大きさを変え たものが公開される
  • 12. All rights reserved| micin.jp 1212 BERTのモデル構造(概略) BERTbase : 1億パラメータ BERTlarge : 3億パラメータ
  • 13. All rights reserved| micin.jp 1313 BERTの出力と入力 “I have a pen.” が入力の時 𝑋 = 𝑥𝐼, 𝑥ℎ𝑎𝑣𝑒, 𝑥 𝑎, 𝑥 𝑝𝑒𝑛 𝑇 𝑥𝑖 ∈ ℝ 𝑊 出力は 𝑌 = 𝑦𝐼, 𝑦ℎ𝑎𝑣𝑒, 𝑦𝑎, 𝑦𝑝𝑒𝑛 𝑇 𝑦𝑖 ∈ ℝ 𝐹 , F ∈ {768,1024} (厳密には文章の先頭などに特殊トークンが 設置される) 詳しい式部分の解説はkibe.laにて公開しています
  • 14. All rights reserved| micin.jp 1414 BERTがやっていること BERTが行っているのは 基本的には文章の単語(token)ごとの エンコードのみ 特定タスク利用にはデコードする部分を 付け加えて利用する (大抵全結合層を1つ加える)
  • 15. All rights reserved| micin.jp 1515 BERTがやっていること エンコードしかしないが、エンコード部分は いろんなタスクに共通するのでは ↓ デコード部分だけ入れ替えれば使い回しがで きる(はず) ↓ エンコード部分だけ事前に特定のタスクで学 習させて、色々なタスクに応用しよう
  • 16. All rights reserved| micin.jp 1616 使いまわした結果 これまでの既存の10を超えるタスクに おいて歴代最高スコア(SOTA; State of The Art)を達成(モデル発表当時) GLUEタスク: (General Language Understand Evaluation) いくつかの自然言語処理タスクをまとめたもの Jacob Devlin et al.(2018). BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding. より
  • 17. All rights reserved| micin.jp 1717 使いまわした結果 SQuAD 1.1 SQuAD 2.0 SWAG 人間超えるタスクも Jacob Devlin et al.(2018). BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding. より
  • 18. All rights reserved| micin.jp 18 今、 タスクのスコアについて 出てきたので
  • 19. All rights reserved| micin.jp 19 現在GLUEでの LeaderBoardが どうなっているかを 軽く覗いてみます
  • 20. All rights reserved| micin.jp 20 2020/3/13時点 総合スコアではヒトは負けているが、 タスクごとにみるとヒトがまだ優位を 保っているものもある 上位5つは全てTransformerベースのモデル https://gluebenchmark.com/leaderboard
  • 21. All rights reserved| micin.jp 目次 BERTの概要紹介1 21 2 3 BERTは何をみているのか BERTの事前学習
  • 22. All rights reserved| micin.jp 22 事前学習 このようなタスクにするために必要不可欠なのが、 大規模コーパスを用いた事前学習 オリジナルでは主に2つのタスクを解かせている • Masked Language Modeling (MLM) 一定確率で単語(token)を隠し、隠した部分が どんな単語かを予測(多クラス分類) • Next Sentence Prediction (NSP) ランダムに接合した2つの文章が関連があるか どうかを判定(2値分類)
  • 23. All rights reserved| micin.jp 23 事前学習 MLMとNSPは同時並行で学習させていく (MLMとNSPタスクによって算出された損失を元 に学習をしていく) これらのタスクそのものを入れ替えることも改善 の一手
  • 24. All rights reserved| micin.jp 24 事前学習 入力と出力は以下のイメージ http://kento1109.hatenablog.com/entry/2019/04/28/142507
  • 25. All rights reserved| micin.jp 25 NSPタスクはあまり意味がない? (Yang et al., 2019; Liu et al., 2019) ↓ ランダムに入れ替えた文章を並べ直すというタス クに変更 (ALBERT) (Lan et al., 2019) 事前学習
  • 26. All rights reserved| micin.jp 26 MLMで、単語(token)を複数マスクするとマス クされたもの同士の依存関係はモデリングでき ない ↓ 単語をランダムに並べ替えたものを予測するタ スクに変更 (XLNet)(Yang et al.,2019) 事前学習
  • 27. All rights reserved| micin.jp 27 MLMで、単語(token)を複数マスクするとマスク されたもの同士の依存関係はモデリングできない ↓ 似たような単語で入れ替えたものに 対して、入れ替えを検知する (ELECTRA) (Kevin et al., 2020) 事前学習
  • 28. All rights reserved| micin.jp 28 事前学習 膨大な計算量 BERTbase : TPU 4枚(16チップ)で丸4日間 BERTlarge : TPU16枚(64チップ)で丸4日間 対象コーパス : BookCorpus 1億 words English Wikipedia : 25億 words
  • 29. All rights reserved| micin.jp 2929 ここまでのまとめ • BERTは事前学習済みの学習モデル • AttentionベースのTransformerが構成単位と なる • 文章をエンコードするのが役割 • 様々なタスクに使い回しできる • スコアめっちゃすごい
  • 30. All rights reserved| micin.jp 目次 BERTの概要紹介1 30 2 3 BERTは何を見ているのか BERTの事前学習
  • 31. All rights reserved| micin.jp 31 Do Attention Heads in BERT Track Syntactic Dependencies? • BERTのAttention Headsが係り受け解析を内 在的にモデル化しているかどうかを検証した論 文 • 答えは一部的にyes。 • (nsubj, obj, conjなどは良好に取得できた) • 一方で、係り受け木を完全に生成できるような Attention Headは存在しなかった Attentionは何をモデル化しているのか
  • 32. All rights reserved| micin.jp 32 Attentionは何をモデル化しているのか 2つのやり方で係受け木を作成した時のそれぞれ のスコア (右から二番目がbaseline)
  • 33. All rights reserved| micin.jp 33 Attentionから解釈をすることは難しい Attention is not Explainable BERTで学習されているAttentionの重みは説 明可能性を持っていないとする研究結果を発 表。 • Attentionの重みと、タスクを解く上で重要 視される単語とに関連がない • Attentionの重みを入れ替えても精度に差が 生じない
  • 34. All rights reserved| micin.jp 34 ここまでのまとめ • Attentionの中身が何を見ているのかと いう解釈は難しい • Attentionの中身の一部を使うと係り受 け解析の情報を抽出することも可能
  • 35. All rights reserved| micin.jp 35 参考になるスライド BERT系列のモデルについて 非常によくまとめられたスライドが存在するので ぜひこちらもご覧ください。 西田京介さんによって作成されたスライド 「事前学習済言語モデルの動向」 https://speakerdeck.com/kyoun/survey-of- pretrained-language-models-f6319c84-a3bc- 42ed-b7b9-05e2588b12c7
  • 36. All rights reserved| micin.jp 36 まとめ
  • 37. All rights reserved| micin.jp 37 まとめ • BERTの概要についてざっくりと解説した 個人の感想として、BERTはまだまだ大規模コー パスのパターンを全部覚え込んだモデルに過ぎな く、言語の理解をしているとは考えにくい。 我々の持っている知識までもモデルとして考慮で きるようになれば更に強いモデルが出てくるかも しれない。
  • 38. All rights reserved| micin.jp 38 終わり

Editor's Notes

  1. CoLA : 文章の自然さを評価する SST-2 : MNLI:含意関係の分類タスク ・QQP:質問内容が同じであるかを分類するタスク ・QNLI:質問と文が与えられ、文が質問の答えになるかを当てる分類タスク ・SST-2:映画のレビューに対する感情分析タスク ・CoLA:文の文法性判断を行う分類タスク ・STS-B:2文の類似度を5段階で評価する分類タスク ・MRPC:ニュースに含まれる2文の意味が等しいかを当てる分類タスク ・RTE:小規模な含意関係の分類タスク