BERT の解剖学
interpret-text による自然言語処理 (NLP) モデル解釈
2020/08/01, Deep Learning Digital Conference
日本マイクロソフト株式会社
山口 順也
$ ./about-me
├── 山口順也 (Junya Yamaguchi)
│ ├── 日本マイクロソフト
│ ├── カスタマーサービス&サポート Support Engineer
│ └── Azure Networking (Load Balancer, ExpressRoute, etc)
└── 東京工業大学・大学院で人工知能基礎/機械学習の勉強をしてました
https://www.slideshare.net/DeepLearningLab/glm-gam https://www.slideshare.net/ssuser0c8361/20200212-227754437
グラフ分析ナイト (2020/02/12)機械学習モデル解釈ナイト (2020/11/27)
本セッションで話すこと
• 機械学習モデルの解釈性
• 自然言語処理のための深層モデルを解釈するライブラリ interpret-text
• Interpret-text で実装されている 2 つの手法
• Unified Information Explainer
• Introspective Rationale Explainer
国内の AI 倫理原則/ガイドライン
2017.02 人工知能学会倫理指針
人工知能学会
国際的な議論のためのAI開発ガイドライン案
総務省 – AIネットワーク社会推進会議
2017.07
2019.03 人間中心のAI社会原則
内閣府 – 統合イノベーション戦略推進会議
2019.08 AI利活用に関する原則
総務省 ─ AIネットワーク社会推進会議
適正利用 適正学習
連携 安全
セキュリティ プライバシー
尊厳・自律 公平性
透明性 アカウンタビリティ
AI 利活用原則
https://www.soumu.go.jp/menu_news/s-news/01iicp01_02000081.html
Ethics Guidelines for Trustworthy AI
• AI HLEG (欧州委員会, 2018) による AI システムのガイドライン
• 信頼できる AI システムを作るするための評価リスト
https://ec.europa.eu/futurium/en/ai-alliance-consultation
Explainability:
- Did you ensure an explanation as to why the system took a certain choice
resulting in a certain outcome that all users can understand?
すべてのユーザーが理解できる形で、AI システムが結果を選択した理由が説明できるようにしましたか ?
- Did you design the AI system with interpretability in mind from the start?
はじめから解釈性を念頭に AI システムを設計しましたか ?
https://www.microsoft.com/en-us/ai/responsible-ai
https://interpret.ml/
Interpretability for
Text Data
https://github.com/interpretml/interpret-text
Interpret-text: NLP モデルの解釈
• 文章データのテキスト分類予測について、”局所的な説明” のアルゴリズムを提供
するオープンソースライブラリ
• 分類タスク等の予測に寄与した単語をピックアップできる
• 主な特徴
• 最先端のテキスト解釈・説明アルゴリズム
• 複数の解釈手法に対する統合された API
• 対話型のダッシュボードによる高いユーザビリティ
• 実装済みの説明手法
• Classical Text Explainer
• Unified Information Explainer (post-hoc, model agnostic)
• Introspective Rationale Explainer (plug-in during training, model agnostic)
Unified
Information
Explainer
Introspective
Rationale
Explainer
interpret-text
Unified Information Explainer
• Microsoft Research が ICML 2019 で
提案した state-of-the-art な解釈手法
• 情報理論の考え方がベース
• 学習済みモデルを解釈
• 特徴
• レイヤー間やモデル間で一貫性のある解釈を獲得出来る
• 活性化関数やアーキテクチャに制約がなく、任意の DNN モデルに対して適用できる
• 現在 interpret-text としては BERT のみを実装済み
• 将来的に LSTM, RNN に対応予定
Towards A Deep and Unified Understanding of Deep Neural Models in NLP, Guan et al. [ICML 2019]
High-Level Overview
私
は
好き
positive
negative
High-Level Overview
私
は
好き
positive
negative
僕、拙者
似てる単語似てない単語
High-Level Overview
私
は
好き
positive
negative
僕、拙者車、カラス
似てる単語似てない単語
High-Level Overview
私
は
好き
positive
negative
僕、拙者
愛する、想う
車、カラス
似てる単語似てない単語
High-Level Overview
私
は
好き
positive
negative
僕、拙者
愛する、想う帰る、見る
車、カラス
似てる単語似てない単語
High-Level Overview
は
positive
negative
僕、拙者
愛する、想う帰る、見る
車、カラス
似てる単語似てない単語
意味的に近い単語でしか置換できない!
= 重要な単語
意味的に遠い単語に置換しても予測結果が変わらない
= 重要でない単語
私
好き
最大エントロピーの原理に則り
余計な情報をなるべく仮定しない
𝐻 𝑋𝑖 𝑠 ≅ 𝐻( ෨𝑋𝑖|𝑠) の近似が出来るくらい、
ノイズを加えた入力による計算結果を変化させない
条件付きエントロピーの計算
近似トリック 近似のための最適化
𝐻 𝑋𝑖 𝑠
≅ 𝐾1 + 𝐾2 log 𝜎𝑖
近似式
正規分布するノイズを
各単語に加える
ノイズを加えて単語の
意味を遠ざける
結果をなるべく変えない
特徴: Coherency
解釈手法が一貫性 (coherency) をもつ = 異なるレイヤー/モデル間でも比較可能な統一的な重要度が獲得できる
「勾配 (gradient) の絶対値 = 重要度」という強い仮定の為、
勾配の値が大きいレイヤー (i.e. L3) の重要度が強く映し出されている。
その結果、勾配のスケールが一致しないレイヤー間比較が意味をなさない。
従来手法 (gradient-based) による解釈 Unified Information Explainer による解釈
相互情報量をベースに重要度を算出している為、上表のいかなるセル同士でも
重要度のスケールが揃っており、比較が可能。
レイヤー方向で比較できない レイヤー方向で比較できる
レイヤー
特徴: Generality
解釈手法が一般性 (generality) をもつ = どのようなアーキテクチャの NN であっても解釈が可能である
従来手法による解釈 Unified Information Explainer による解釈
活性化関数が
微分できない
Reconstructed
層が存在しない
解釈手法に
チューニングした
モデル
活性化関数が
微分できない
Reconstructed
層が存在しない
解釈手法に
チューニングした
モデル
#BERT分析してみた
BERT は Stop words を重視しないBERT はレイヤーの浅い段階ですでに
無意味な単語 (e.g. to, it) を判別出来ている。
感情分析を目的とした多値分類タスク 言語的に許容できるか判定する分類タスク
タスクに使えるか微妙なラインの単語 (e.g. enough)
については、割と後半まで利用している。
最後のレイヤーでは、感情分析に有益な単語
(e.g. charm) のみを利用して分類を実行。
BERT がこのような性質を持っている点が大事
ではなく、Unified Information Explainer を
使えば任意のモデルを解釈できることが大切
Unified
Information
Explainer
Introspective
Rationale
Explainer
interpret-text
Introspective Rationale Explainer
• モデル学習時に説明性を提供するモジュールも学
習するフレームワーク (Three Player Framework)
を提供
• 学習済みモデルへの解釈手法ではない
• 予測に不可欠な単語集合 (根拠) を選択できるモ
ジュールを、モデル学習時に一緒に獲得する
• 任意の NLP モデルに対して使える
• 別のモジュールで説明性を得るので、NLP モデル自体に
特に配慮が要らない
Rethinking Cooperative Rationalization: Introspective Extraction and Complement Control, Yu et al. [EMNLP 2019]
解釈用
モジュール
任意の
NLP モデル
解釈モジュールの
検証用モデル
根拠 (rationale) とは ?
通話の品質が極めてクリアで、
相手も聞き取りやすいそうです。
車の運転中も片耳インカムとして使えるので、
(左右どちらでも)これ以上ないくらい便利です。
positive
negative
内包性 (comprehensiveness)
根拠以外の単語はラベルを予
測するのに十分な情報を持って
いないこと
コンパクト性 (compactness)
根拠はスパースであり、かつ連続
している (まばらでない) こと
根拠 (rationale) は、入力センテンスに含まれる「ラベル予測に寄与する単語」の集合
十分性 (sufficiency)
根拠だけで十分予測が出来ること
Three Player Framework
NLP
モデル
私,は,好き
PositivePositive
label
data
Three Player Framework
NLP
モデル
私,は,好き
Positive
NLP
モデル
*,*,好き
Positive
根拠
精度変化なし
Positive
label
data
Three Player Framework
NLP
モデル
私,は,好き
Positive
NLP
モデル
*,*,好き
Positive
Generator
私,は,好き
根拠
精度変化なし
「好き」って単語使って
予測したいんでしょ?
Positive
label
data
Three Player Framework
NLP
モデル
私,は,好き
Positive
NLP
モデル
*,*,好き
Positive
Generator
NLP
モデル
私,は,*
Negative
私,は,好き
根拠
根拠
以外
精度変化なし
精度が悪化
「好き」って単語使って
予測したいんでしょ?
Positive
label
data
Three Player Framework
プレイヤー
• Generator: 根拠/根拠以外の単語を抽出するモデル
• Predictor: 任意の NLP モデル
• Complement Predictor: 任意の NLP モデル
根拠
(e.g 好き)
根拠以外の単語
(e.g. 私,は)
センテンス
(e.g. 私は好き)
根拠による予測
(e.g. Positive)
根拠以外の単語による予測
(e.g. Negative)
Generator の最適化
𝐿 𝑝: Predictor の目的関数
𝐿 𝑐: Complement Predictor の目的関数
Cooperative 内包性 スパース性 連続性
Introspective Generator
学習済みの分類器
予測ラベル = 新たな特徴として入力
各手法の比較 ※ Interpret-text への実装ベースでの比較
Classical Text Explainer Unified Information
Explainer
Introspective Rationale
Explainer
Input model support Scikit-learn linear models
and tree-based models
PyTorch PyTorch
Explain BERT No Yes Yes
Explain RNN No No Yes
NLP Pipeline Support Handles text pre-
processing, encoding,
training, hyperparameter
tuning
Uses BERT tokenizer
however user needs to
supply trained/fine-
tuned BERT model, and
samples of trained data
Generator and predictor
modules handle the required
text pre-processing.
Demo
まとめ
• Interpret-text は NLP 向け DNN モデルを解釈するための Python パッケージ
• 単語ごとの予測への寄与を獲得することでモデルを説明する
• 最先端の解釈手法が実装されている
• Unified Information Explainer
• 訓練済みの任意の NLP モデルを解釈する
• 情報理論に基づき、比較可能な一貫性のある重要度を算出する
• Introspective Rationale Explainer
• NLP モデルを学習する際、 Three Player Framework と呼ばれるフレームワークで、重要な
単語集合 (根拠) を抽出するジェネレーターも同時に学習する
• 任意のモデルに適用できる
参考文献
参考文献
責任ある AI の基本原則を特定する - Learn | Microsoft Docs
https://docs.microsoft.com/ja-jp/learn/modules/responsible-ai-principles/
【記事更新】私のブックマーク「説明可能AI」(Explainable AI) – 人工知能学会 (The Japanese Society for Artificial Intelligence)
https://www.ai-gakkai.or.jp/my-bookmark_vol34-no4/
BlackBox モデルの説明性・解釈性技術の実装
https://www.slideshare.net/DeepLearningLab/blackbox-198324328
interpretml/interpret-text: A library that incorporates state-of-the-art explainers for text-based machine learning models and visualizes the result with a
built-in dashboard.
https://github.com/interpretml/interpret-text
Responsible AI: Interpret-Text with the Introspective Rationale Explainer | by Eve Pardi | Medium
https://medium.com/@evepardi/responsible-ai-interpret-text-introspective-rationale-explainer-9a3b1d7a5e4a
How to Explain Text Models with IntepretML Deep Dive | AI Show | Channel 9
https://channel9.msdn.com/Shows/AI-Show/How-to-Explain-Text-Models-with-IntepretML-Deep-Dive

BERT の解剖学: interpret-text による自然言語処理 (NLP) モデル解釈