ichou1のブログ

主に音声認識、時々、データ分析のことを書く

BERTメモ(BertViz)その1

BERTのattentionを可視化する「BertViz」を試してみる。

GitHub - jessevig/bertviz: Tool for visualizing attention in the Transformer model (BERT, GPT-2, XLNet, and RoBERTa)

論文「A Multiscale Visualization of Attention in the Transformer Model」
https://arxiv.org/pdf/1906.05714.pdf

ICLR 2019 workshop
https://debug-ml-iclr2019.github.io/cameraready/DebugML-19_paper_2.pdf

BERTの日本語Pre-trainedモデルは、以下を使用させていただいた。
GitHub - yoheikikuta/bert-japanese: BERT with SentencePiece for Japanese text.

今回、試した文は

木でできた美しい大きな円いテーブル


BERT-baseの場合、Layerが「12」、attention-headが「12」なので、出力パターンは144通りあり、その一部は以下のとおり。

Layer 0, attention-head 0 to 3

f:id:ichou1:20190924221718p:plainf:id:ichou1:20190924221558p:plainf:id:ichou1:20190924221626p:plainf:id:ichou1:20190924221638p:plain

Layer 1, attention-head 0 to 3

f:id:ichou1:20190924221743p:plainf:id:ichou1:20190924221648p:plainf:id:ichou1:20190924221657p:plainf:id:ichou1:20190924221706p:plain