Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

OpenJNY
August 01, 2020
2.7k

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

Google が 2018 年に発表した深層モデル BERT は、自然言語処理 (NLP) の多くのタスクでブレイクスルーを起こしました。性能面で進歩がある一方で、公平性に関するガイドラインが総務省から発表される等、産業界では解釈可能な AI を求める声が大きくなってきています。そこで本セッションでは、このギャップを埋めるために Microsoft Research が開発している、interpret-text と呼ばれる機械学習ライブラリをご紹介します。BERT を含む、様々な自然言語処理モデルを解釈するための 2 つの方法について解説し、簡単なデモをお見せします。

Deep Learning Digital Conference - connpass
https://dllab.connpass.com/event/178714/

OpenJNY

August 01, 2020
Tweet

Transcript

  1. BERT の解剖学
    interpret-text による自然言語処理 (NLP) モデル解釈
    2020/08/01, Deep Learning Digital Conference
    日本マイクロソフト株式会社
    山口 順也

    View Slide

  2. $ ./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)

    View Slide

  3. 本セッションで話すこと
    • 機械学習モデルの解釈性
    • 自然言語処理のための深層モデルを解釈するライブラリ interpret-text
    • Interpret-text で実装されている 2 つの手法
    • Unified Information Explainer
    • Introspective Rationale Explainer

    View Slide

  4. 国内の 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

    View Slide

  5. 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 システムを設計しましたか ?

    View Slide

  6. https://www.microsoft.com/en-us/ai/responsible-ai

    View Slide

  7. https://interpret.ml/

    View Slide

  8. Interpretability for
    Text Data
    https://github.com/interpretml/interpret-text

    View Slide

  9. Interpret-text: NLP モデルの解釈
    • 文章データのテキスト分類予測について、”局所的な説明” のアルゴリズムを提供
    するオープンソースライブラリ
    • 分類タスク等の予測に寄与した単語をピックアップできる
    • 主な特徴
    • 最先端のテキスト解釈・説明アルゴリズム
    • 複数の解釈手法に対する統合された API
    • 対話型のダッシュボードによる高いユーザビリティ
    • 実装済みの説明手法
    • Classical Text Explainer
    • Unified Information Explainer (post-hoc, model agnostic)
    • Introspective Rationale Explainer (plug-in during training, model agnostic)

    View Slide

  10. Unified
    Information
    Explainer
    Introspective
    Rationale
    Explainer
    interpret-text

    View Slide

  11. 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]

    View Slide

  12. High-Level Overview


    好き
    positive
    negative

    View Slide

  13. High-Level Overview


    好き
    positive
    negative
    僕、拙者
    似てる単語
    似てない単語

    View Slide

  14. High-Level Overview


    好き
    positive
    negative
    僕、拙者
    車、カラス
    似てる単語
    似てない単語

    View Slide

  15. High-Level Overview


    好き
    positive
    negative
    僕、拙者
    愛する、想う
    車、カラス
    似てる単語
    似てない単語

    View Slide

  16. High-Level Overview


    好き
    positive
    negative
    僕、拙者
    愛する、想う
    帰る、見る
    車、カラス
    似てる単語
    似てない単語

    View Slide

  17. High-Level Overview
    は positive
    negative
    僕、拙者
    愛する、想う
    帰る、見る
    車、カラス
    似てる単語
    似てない単語
    意味的に近い単語でしか置換できない!
    = 重要な単語
    意味的に遠い単語に置換しても予測結果が変わらない
    = 重要でない単語

    好き

    View Slide

  18. 最大エントロピーの原理に則り
    余計な情報をなるべく仮定しない

    ≅ ( ෨

    |) の近似が出来るくらい、
    ノイズを加えた入力による計算結果を変化させない
    条件付きエントロピーの計算
    近似トリック 近似のための最適化


    ≅ 1
    + 2
    log
    近似式
    正規分布するノイズを
    各単語に加える
    ノイズを加えて単語の
    意味を遠ざける
    結果をなるべく変えない

    View Slide

  19. 特徴: Coherency
    解釈手法が一貫性 (coherency) をもつ = 異なるレイヤー/モデル間でも比較可能な統一的な重要度が獲得できる
    「勾配 (gradient) の絶対値 = 重要度」という強い仮定の為、
    勾配の値が大きいレイヤー (i.e. L3) の重要度が強く映し出されている。
    その結果、勾配のスケールが一致しないレイヤー間比較が意味をなさない。
    従来手法 (gradient-based) による解釈 Unified Information Explainer による解釈
    相互情報量をベースに重要度を算出している為、上表のいかなるセル同士でも
    重要度のスケールが揃っており、比較が可能。
    レイヤー方向で比較できない レイヤー方向で比較できる
    レイヤー

    View Slide

  20. 特徴: Generality
    解釈手法が一般性 (generality) をもつ = どのようなアーキテクチャの NN であっても解釈が可能である
    従来手法による解釈 Unified Information Explainer による解釈
    活性化関数が
    微分できない
    Reconstructed
    層が存在しない
    解釈手法に
    チューニングした
    モデル
    活性化関数が
    微分できない
    Reconstructed
    層が存在しない
    解釈手法に
    チューニングした
    モデル

    View Slide

  21. #BERT分析してみた
    BERT は Stop words を重視しない
    BERT はレイヤーの浅い段階ですでに
    無意味な単語 (e.g. to, it) を判別出来ている。
    感情分析を目的とした多値分類タスク 言語的に許容できるか判定する分類タスク
    タスクに使えるか微妙なラインの単語 (e.g. enough)
    については、割と後半まで利用している。
    最後のレイヤーでは、感情分析に有益な単語
    (e.g. charm) のみを利用して分類を実行。
    BERT がこのような性質を持っている点が大事
    ではなく、Unified Information Explainer を
    使えば任意のモデルを解釈できることが大切

    View Slide

  22. Unified
    Information
    Explainer
    Introspective
    Rationale
    Explainer
    interpret-text

    View Slide

  23. Introspective Rationale Explainer
    • モデル学習時に説明性を提供するモジュールも学
    習するフレームワーク (Three Player Framework)
    を提供
    • 学習済みモデルへの解釈手法ではない
    • 予測に不可欠な単語集合 (根拠) を選択できるモ
    ジュールを、モデル学習時に一緒に獲得する
    • 任意の NLP モデルに対して使える
    • 別のモジュールで説明性を得るので、NLP モデル自体に
    特に配慮が要らない
    Rethinking Cooperative Rationalization: Introspective Extraction and Complement Control, Yu et al. [EMNLP 2019]
    解釈用
    モジュール
    任意の
    NLP モデル
    解釈モジュールの
    検証用モデル

    View Slide

  24. 根拠 (rationale) とは ?
    通話の品質が極めてクリアで、
    相手も聞き取りやすいそうです。
    車の運転中も片耳インカムとして使えるので、
    (左右どちらでも)これ以上ないくらい便利です。
    positive
    negative
    内包性 (comprehensiveness)
    根拠以外の単語はラベルを予
    測するのに十分な情報を持って
    いないこと
    コンパクト性 (compactness)
    根拠はスパースであり、かつ連続
    している (まばらでない) こと
    根拠 (rationale) は、入力センテンスに含まれる「ラベル予測に寄与する単語」の集合
    十分性 (sufficiency)
    根拠だけで十分予測が出来ること

    View Slide

  25. Three Player Framework
    NLP
    モデル
    私,は,好き
    Positive
    Positive
    label
    data

    View Slide

  26. Three Player Framework
    NLP
    モデル
    私,は,好き
    Positive
    NLP
    モデル
    *,*,好き
    Positive
    根拠
    精度変化なし
    Positive
    label
    data

    View Slide

  27. Three Player Framework
    NLP
    モデル
    私,は,好き
    Positive
    NLP
    モデル
    *,*,好き
    Positive
    Generator
    私,は,好き
    根拠
    精度変化なし
    「好き」って単語使って
    予測したいんでしょ?
    Positive
    label
    data

    View Slide

  28. Three Player Framework
    NLP
    モデル
    私,は,好き
    Positive
    NLP
    モデル
    *,*,好き
    Positive
    Generator
    NLP
    モデル
    私,は,*
    Negative
    私,は,好き
    根拠
    根拠
    以外
    精度変化なし
    精度が悪化
    「好き」って単語使って
    予測したいんでしょ?
    Positive
    label
    data

    View Slide

  29. 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 内包性 スパース性 連続性

    View Slide

  30. Introspective Generator
    学習済みの分類器
    予測ラベル = 新たな特徴として入力

    View Slide

  31. 各手法の比較 ※ 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.

    View Slide

  32. Demo

    View Slide

  33. まとめ
    • Interpret-text は NLP 向け DNN モデルを解釈するための Python パッケージ
    • 単語ごとの予測への寄与を獲得することでモデルを説明する
    • 最先端の解釈手法が実装されている
    • Unified Information Explainer
    • 訓練済みの任意の NLP モデルを解釈する
    • 情報理論に基づき、比較可能な一貫性のある重要度を算出する
    • Introspective Rationale Explainer
    • NLP モデルを学習する際、 Three Player Framework と呼ばれるフレームワークで、重要な
    単語集合 (根拠) を抽出するジェネレーターも同時に学習する
    • 任意のモデルに適用できる

    View Slide

  34. 参考文献

    View Slide

  35. 参考文献
    責任ある 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

    View Slide