ichou1のブログ

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

BERT

Kerasメモ(XLNet)その3

前回の続き。AttentionレイヤがBERTとどう変わるのか見てみる。 work-in-progress.hatenablog.com前々回のmodel.summaryの抜粋 model.summary Layer (type) Output Shape Param # Connected to ======================= ===================== ======== ====…

BERTメモ(structural probes)その2

前回の続き。probe parametersを生成する「run_experiment.py」の動きを追ってみる。 今回、パラメータは「Depth」を指定する。 python structural-probes/run_experiment.py example/config/pad_en_ewt-ud-sample.yaml pad_en_ewt-ud-sample.yaml(Depth) pr…

BERTメモ(structural probes)その1

『A Structural Probe for Finding Syntax in Word Representations』を試してみる。ソースコード。 https://github.com/john-hewitt/structural-probesまずは、pre-trained structural probesを使ったデモを動かしてみる。 printf "The chef that went to t…

BERTメモ(torchsummary)

PyTorch版BERTを使ってみる。 pytorch-pretrained-bert · PyPI モデルの要約を表示する方法を探したところ、「torchsummary」パッケージが公開されている模様。 torchsummary · PyPIinputのサイズを指定する必要があり、今回はtokenの長さが「13」であるもの…

BERTメモ(BertViz)その2

前回の続き。sentence-pair (sentence A / B)での出力を見てみる。2つ目の文に、接続詞と指示代名詞が含まれている文を指定。 sentence_a = '栄養バランスの良い食事は健康づくりの基本です。' sentence_b = 'しかしながら、それを実践することはなかなか困…

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…

BERTメモ(BertSum)その2

前回の続き。起点となるスクリプトはtrain.pyで、modeオプションは3つ。 train validate test モデルによる予測の動きを確認するため、トレーニングデータを減らした上で、「train」モードで数stepほど学習させてみる。その後、「validate」モードを実行。オ…

BERTメモ(BertSum)その1

「Document Summarization on CNN / Daily Mail」でSOTAを達成した「BertSum」を試してみる。 github GitHub - nlpyang/BertSum: Code for paper Fine-tune BERT for Extractive Summarization 実装は「PyTorch」を使用している。 論文 https://arxiv.org/pd…

BERTメモ(日本語pretrainedモデル)

BERTのPre-trainedモデルに関するメモ。本家。日本語だけでなく、104言語に対応。 GitHub - google-research/bert: TensorFlow code and pre-trained models for BERT multi_cased_L-12_H-768_A-12.zip BERT-Base, Multilingual Cased (New, recommended): 1…

Kerasメモ(BERTその4)

前回の続き。Transformerを構成するFeedForwardレイヤを見てみる。論文「Attention Is All You Need」からの抜粋。 In addition to attention sub-layers, each of the layers in our encoder and decoder contains a fully connected feed-forward network,…

Kerasメモ(BERTその3)

前々回の続き。Transformerを構成するMultiHeadAttentionレイヤを見てみる。MultiHeadAttentionレイヤのインプットの形状が(bathc_size, 512, 768)、「head_num」が「12」である場合、並列化は下図のとおりとなる。 図中の「Wq」、「Wk」、「Wv」、「Wo」はM…

Kerasメモ(BERTその2)

前回の続き。Position Embeddingレイヤを見てみる。 model.summary Layer (type) Output Shape Param # ========================================================================== Embedding-Position (PositionEmbedding) (None, 512, 768) 393216 ====…

Kerasメモ(BERTその1)

BERT(Bidirectional Encoder Representations from Transformers)を試してみる。論文には2種類のモデルが掲載されている。 the number of layers (i.e., Transformer blocks) as L the hidden size as H the number of self-attention heads as ABERT(BASE)…