自然言語処理の最新技術動向紹介

1.1K Views

December 24, 20

スライド概要

2020年12月16日(水)に行われた対話システム勉強会(第2回)での発表資料です。
https://cotobaagent-developers-community.connpass.com/event/196095/

profile-image

2023年10月からSpeaker Deckに移行しました。最新情報はこちらをご覧ください。 https://speakerdeck.com/lycorptech_jp

シェア

埋め込む »CMSなどでJSが使えない場合

関連スライド

各ページのテキスト
1.

⾃然⾔語処理の 最新技術動向紹介 ヤフー株式会社 柴⽥ 知秀 tomshiba@yahoo-corp.jp 対話システム勉強会(第2回) 20/12/16

2.

⾃⼰紹介 • 柴⽥ 知秀 (しばた ともひで) • 2007年〜 京都⼤学⿊橋研究室 助教・特定講師 • 2019年〜 Yahoo! JAPAN研究所 上席研究員 • 研究分野: 深層学習 (特に転移学習)を⽤いた⽇本語基礎解析 2

3.

⾃然⾔語処理の急激な進展 • BERT(2018年)の登場以降、⽇々新しいモデルが提案されている • 国際会議: ⼀昔前の数倍の投稿 • arXiv (cs.CL): 1⽇10本以上 • よくあること • • • • • 進歩についていけない どのモデルがよいのかわからない WebやSNSには多くの情報があふれている (誤りが多いので注意) ライブラリを動かしたけどうまくいかない .. • ポイントをしぼって最新技術動向を紹介 3

4.

よくある説明 • この説明ではわかる⼈にはわかるが、わからない⼈にはわからない (もしくはわかった気になるだけ) • なぜこれで劇的に精度がよくなったかわからない Figure 1: Overall pre-training and fine-tuning procedures for BERT. Apart from output layers, the same architectures are used in both pre-training and fine-tuning. The same pre-trained model parameters are used to initialize Figure 1: The Transformer - model architecture. [Devlin+ 18] [Vaswani+ 17] models for different down-stream tasks. During fine-tuning, all parameters are fine-tuned. [CLS] is a special symbol added in front of every input example, and [SEP] is a special separator token (e.g. separating ques(https://arxiv.org/abs/1810.04805) (https://arxiv.org/abs/1706.03762) 4 ch of the sub-layers, followed by layer normalization. We also modify the self-attention tions/answers). in the decoder stack to prevent positions from attending to subsequent positions. This Transformer BERT

5.

テキスト変換: encoder-decoderモデル[Sutskever+ 14] encoder decoder ⼀単語ずつ⽣成 (先を⾒ることができない) ⼊⼒⽂をすべて⾒ることができる 私 は 学⽣ です I am a student EOS EOS I am a 5 student

6.

テキスト変換: encoder-decoderモデル[Sutskever+ 14] encoder decoder ⼀単語ずつ⽣成 (先を⾒ることができない) ⼊⼒⽂をすべて⾒ることができる I am a student EOS am a 6 student 15年: アテンション機構 16年: Google翻訳 17年: Transformer [Vaswani+ 17] 学習データ: 数百万⽂〜 私 は 学⽣ です EOS I

7.

単⾔語解析 (2017-18年) Pre-training 各タスク 単語ベクトルの学習 (word2vec [Mikolov+ 13]) ネガティブ Bi-LSTMで ⽂脈を考慮 電池 初期値 が … すぐ 切れる 7

8.

単⾔語解析 (2017-18年) Pre-training ⽂脈レベルの情報の学習は 単語ベクトルの学習 タスクの訓練データのみ (word2vec [Mikolov+ = 13]通常数万⽂ ) • 京⼤コーパス: 4万⽂ • ⽂書分類: 数千⽂書 電池 初期値 各タスク ネガティブ Bi-LSTMで ⽂脈を考慮 が … すぐ 切れる 8

9.

テキスト変換: encoder-decoderモデル[Sutskever+ 14] encoder decoder ⼀単語ずつ⽣成 (先を⾒ることができない) ⼊⼒⽂をすべて⾒ることができる 私 は 学⽣ です I am a student EOS EOS I am a 9 student

10.

BERT [Devlin+ 2018] ポイント1 (Bidirectional Encoder Representations from Transformers) ポイント4 1. Pre-training (学習データ: 数千万⽂〜) “2⽂が隣接して いるかどうか” 2. Fine-tuning ポイント3: ⾃⼰教師あり学習 “⽳うめ問題” 放電 正例 ポイント2 を (学習データ: 数万⽂) タスク: 評判分析 negative BERT BERT [CLS] 電池 が [MASK] ⽂A で … [SEP] 機能 [MASK] 損なう ⽂B [CLS] この 電池 は すぐ 10 切れる

11.

1. Pre-training GPT-1 の 消耗 が 2. Fine-tuning negative 激しい … … タスク: ⾔語モデル (decoderと同じ) タスク例: 評判分析 GPT-1 GPT-1 … … 電池 の 消耗 が この … 電池 は すぐ … 前しか参照できない negative 消耗 BERT … タスク: ⽳埋め問題 … BERT BERT … [CLS] 電池 の [MASK] 前も後ろも参照できる! が … … [CLS] この 電池 は すぐ … 11

12.

BERT [Devlin+ 2018] ポイント1 (Bidirectional Encoder Representations from Transformers) ポイント4 1. Pre-training (学習データ: 数千万⽂〜) “2⽂が隣接して いるかどうか” 2. Fine-tuning ポイント3: ⾃⼰教師あり学習 “⽳うめ問題” 放電 正例 ポイント2 (学習データ: 数万⽂) タスク: 評判分析 negative を BERT BERT [CLS] 電池 が [MASK] ⽂A で … [SEP] 機能 [MASK] 損なう ⽂B [CLS] この 電池 は すぐ 切れる ポイント5: 12 Pre-trainingとFine-tuningで同じモデルを使い回す

13.

ポイント6: タスク固有のネットワークを⽤いない Fine-tuning: 同じ枠組みを利⽤ ⽂ペア分類問題 (例: 含意関係認識) ⼊⼒⽂/⽂章のベクトル表現 positive 含意 ⽂・⽂章 レベル 1⽂分類問題 (例: 評判分析) … … … … … … … … … … … … … … … … … … [CLS] 彼 … ⾷べた [SEP] 彼 … ⾷べた [SEP] [CLS] この PC は 丈夫 ##で 軽い 。 [SEP] スパン抽出 (例: 機械読解) 系列ラベリング (例: 固有表現解析) Start/End Span 単語 レベル B-ORG I-ORG O B-LOC O O O … … … … … … … … … … … … … … … … … … [CLS] … どこ ? [SEP] … 京⼤ … [SEP] [CLS] 京都 ⼤学 は 京都 に ある 13 。 [SEP]

14.

テキスト変換にPre-trainingを導⼊ Text-to-Text Transfer Transformer (T5) [Raffel+ 19] 1. Pre-training encoder 電池 が [X] した 放電 で 消耗 … こちらで⽣成 機能 [Y] が … decoder 放電 で 消耗 [Y] が [X] 放電 で 消耗 [Y] 14

15.

テキスト変換にPre-trainingを導⼊ Text-to-Text Transfer Transformer (T5) [Raffel+ 19] 1. Pre-training Fine-tuningで分類タスクも テキスト変換の枠組みで扱う (詳細は省略) encoder decoder こちらで⽣成 電池 が [X] した 放電 で 消耗 … 機能 [Y] が … 放電 で 消耗 [Y] が [X] 放電 で 消耗 [Y] 15

16.

テキスト変換: encoder-decoderモデル[Sutskever+ 14] encoder decoder ⼀単語ずつ⽣成 (先を⾒ることができない) ⼊⼒⽂をすべて⾒ることができる 私 は 学⽣ です I am a student EOS EOS I am a 16 student

17.

GPT-2 [Radford+ 19], GPT-3 [Brown+ 20] ⾔語モデルを適⽤するのみ 1. Pre-training (Fine-tuningがないのに“Pre-”は少しおかしいが) の 電池 消耗 の が 消耗 This battery 激しい が … … … … … この パラメータを更新しない 電池 … 英語 で This GPT-2: ⼿がかりとなる語を与える GPT-3: 例を数⼗個与える ⽇本語を英語に翻訳してください: 机 → desk りんご → apple 電池 → [タスク説明] [例] … [プロンプト] 17

18.

GPT-2, 3がなぜ可能なのか? 以下のようなテキストがWebには → ここから Language Models are Unsupervised Multitask Learners たくさんある ⾔語モデルを学習 例: 英語 ⇒ フランス語 many different tasks on examples with ”I’m not the cleverest man in the world, but like they say in French: Je ne suis pas un imbecile [I’m not a fool]. In a now-deleted post from Aug. 16, Soheil Eid, Tory candidate is also able to, in principle, learn the in the riding of Joliette, wrote in French: ”Mentez mentez, l. (2018) without the need for explicit il en restera toujours quelque chose,” which translates as, h symbols are the outputs to be pre”Lie lie and something will always remain.” rvised objective is the the same as the “I hate the word ‘perfume,”’ Burr says. ‘It’s somewhat better e but only evaluated on a subset of the in French: ‘parfum.’ minimum of the unsupervised objective If listened carefully at 29:55, a conversation can be heard imum of the supervised objective. In between two guys in French: “-Comment on fait pour aller g, the concerns with density estimation de l’autre coté? -Quel autre coté?”, which means “- How ng objective discussed in (Sutskever do you get to the other side? - What side?”. tepped. The problem instead becomes If this sounds like a bit of a stretch, consider this questo, in practice, optimize the unsuper※ GPT-2の論⽂から引⽤ tion in French: As-tu aller au cinéma?, or Did you go to nvergence. Preliminary experiments https://cdn.openai.com/better-language-models/language_models_are_unsupervised_multitask_learners.pdf the movies?, which literally translates as Have-you to go to ently large language models are able to 18 movies/theater?

19.

GPT-3の精度 (例: 質問応答) モデルパラメータ数の増⼤によって ようやくFine-tuningの⼿法を超える ※ GPT-3の論⽂から引⽤ https://arxiv.org/abs/2005.14165 Figure 3.3: On TriviaQA GPT3’s performance grows smoothly with model size, suggesting that language models 19

20.

タスクとモデルのまとめ encoder-decoder タスク テキスト変換 (翻訳, 要約, 対話, ..) ⽣成と呼ぶことも多い encoder こっちと区別する decoder こちらも扱える 分類タスク - ⽂・⽂章レベル (⽂書分類, 評判分析) - トークンレベル (固有表現解析, 機械読解) テキスト⽣成 モデル (従来の)encoderdecoder T5, BART, .. GPT-1, BERT ⽅式が違う GPT-2, GPT-3 ?BERTのおかげでGoogle翻訳がよくなった ?GPT-Nはパラメータ数が異なるだけ 20

21.

⽇本語処理における状況 • ⽇本語BERTモデルが公開されている (京⼤, 東北⼤, NICT, ..) • mT5 (多⾔語T5)も先⽇公開された • LINEが⽇本語GPT-3を学習することを発表 • ⽇本語の特殊性 • ニューラルネットワークの利⽤により薄まりつつある • 形態素解析を⾏い、形態素をサブワードに分割し、英語と同様に扱う (BERT) • ⽣⽂に対してSentencepieceでトークナイズ (mT5) • 英語に⽐べて評価セットが圧倒的に少ない → いろいろ⼤変なことが多いが、評価セットの構築・共有が重要 21

22.

ライブラリ・ソフトウェア • transformers (pytorch / tensorflow) • 最新のモデルが⼿軽に試すことができる • ⽂書分類・固有表現解析・機械読解など、サンプルプログラムを動か すだけならまずはこれを試す • AllenNLP (pytorch) • 詳細は前回の勉強会を参照のこと • サンプルプログラム以上のことを⾏うにはこれが⼀番 • モジュール化されていて、LSTMとの⽐較などが簡単 • BERT関係はtransformersで提供されているモジュールを利⽤ 22

23.

動かし⽅: 固有表現解析 注意: ネット上の記事ではコードが⻑々と書かれていることが多い → たいていのことはデータを⽤意し、コマンドを実⾏するだけでよい 東北⼤学提供の BERTモデル transformers $ python run_ner_old.py --model_name_or_path cl-tohoku/bert-base-japanese-whole-wordmasking --data_dir /somewhere .. Allennlp ただし O 、O 50 B-DATE 周年 I-DATE ソング O にO … $ allennlp train bert.jsonnet ‒s /output_dir .. 23

24.
[beta]
動かし⽅: 固有表現解析
{

"dataset_reader": {
"type": "conll2003",
"tag_label": "ner",
"lazy": false,
"token_indexers": {
"transformer": {
"type": "pretrained_transformer_mismatched",
"model_name": std.extVar("BERT_MODEL_NAME”)
}
}
},
"train_data_path": std.extVar("NER_TRAIN_DATA_PATH"),
"validation_data_path": std.extVar("NER_VALID_DATA_PATH"),
"model": {
"type": "crf_tagger",
"label_encoding": "BIO",
"calculate_span_f1": true,
"text_field_embedder": {
"token_embedders": {
"transformer": {
"type": "pretrained_transformer_mismatched",
"model_name": std.extVar("BERT_MODEL_NAME")
}
}
},
"encoder": {
"type": "pass_through",
"input_dim": 768,
},
},
"data_loader": {
"batch_size": 32
},
"trainer": {
"optimizer": {
"type": "huggingface_adamw",
"lr": 5e-5
},
"num_epochs": 4,
"cuda_device": 0
}

注意: ネット上の記事ではコードが⻑々と書かれていることが多い
→ たいていのことはデータを⽤意し、コマンドを実⾏するだけでよい
東北⼤学提供の
BERTモデル
BERTの利⽤

transformers

$ python run_ner_old.py --model_name_or_path cl-tohoku/bert-base-japanese-whole-wordmasking --data_dir /somewhere ..

Allennlp

ただし O
、O
50 B-DATE
周年 I-DATE
ソング O
にO
…

$ allennlp train bert.jsonnet ‒s /output_dir ..
}

24

25.

精度 (評価尺度: スパン単位のF値) Universal Dependency NE (Megagon Labs) NLU スロット認識 (コトバデザイン) (train: 約7,000⽂, dev: 約500⽂, test: 約540⽂) 1 0.9 0.932 0.909 0.849 0.827 0.775 0.8 0.925 0.779 0.974 1 0.883 0.734 0.9 0.8 0.905 0.579 0.5 0.952 0.923 0.884 0.723 0.762 0.742 0.729 0.685 0.6 0.508 0.5 0.929 0.853 0.7 0.7 0.6 (train: 約500⽂, dev: 約250⽂) 0.5 0.4 0.4 0.3 0.3 0.2 0.2 0.1 0.1 0 0 overall DATE ORG QUANTITY PERSON GPE overall 場所 ⽇にち 駅(終点) 値段 駅(始点) (1249) (206) (179) (172) (127) (102) (753) (134) (128) (97) (85) (84) Bi-LSTM BERT Bi-LSTM ※ ラベル数トップ5のみ表⽰ BERT 25

26.

解析例: NLU スロット認識 乗⾞時間 駅 (始点) 駅 (終点) 午前8時25分頃に清⾳を出て、⼤泉へ⾏く⽅法を教えて ○ ○ Bi-LSTM BERT × ○ × ○ 駅 (始点) 駅 (終点) 乗⾞時間 厚⽊から庭瀬で9:25頃乗る場合の乗り換えはどれがいい Bi-LSTM ○ × × • BERTでかなりできるようになっている BERT ○ ○ ×(到着時間) • 不思議な誤りがまだたまにある • アノテーション誤り/微妙な例がよく⾒つかる 場所 レストランジャンル ⾼⽥町エリアで焼⾁がある飲み屋を探して Bi-LSTM ○ × BERT ×(料理名) ○ 26

27.

まとめ • ⾃然⾔語処理の最新技術動向のポイントを紹介 • ⽇本語処理におけるライブラリを紹介 • ⾃分で試してみることが重要 • ⾃分の解きたいタスク・データでモデルを動かし、結果を分析 • SNSにあがっている論⽂のまとめを読んで終わりではなく、⾃分で確認 • 対話についてはよくわからない (⾃分で試していないという意味で) • ⼤規模データで⼤規模モデルを学習した論⽂はある • [Adiwardana+ 20, Roller+ 20] • さしあたりモジュール(スロット認識など)の⾼度化 • いろんなことが可能となってきていて、これからが楽しい時代27

29.

様々な観点での進展 • BERTの改良 • 中⾝の分析 • 軽量化 • ドメイン特化型モデル: バイオ, 医療, .. • 多⾔語・英語以外の⾔語のモデル • マルチモーダル • .. https://github.com/tomohideshibata/BERT-related-papers 29