Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
AllenNLPを使った開発
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Yasufumi Taniguchi
July 29, 2019
Programming
2.3k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
AllenNLPを使った開発
Yasufumi Taniguchi
July 29, 2019
More Decks by Yasufumi Taniguchi
See All by Yasufumi Taniguchi
Pathologies of Neural Models Make Interpretations Difficult
yasufumy
1
1.8k
Making Neural QA as Simple as Possible but not Simpler
yasufumy
0
100
Other Decks in Programming
See All in Programming
わからない話を追いかけたら、プログラミング言語を作る側にいた
ydah
3
430
メールのエイリアス機能を履き違えない
isshinfunada
0
210
AI時代に設計が 最大の生産性レバーになる 意図駆動開発とデータを消さない設計|Don't Delete Your Data or Your Intent — Design as the Deepest Lever in the AI Era
tomohisa
1
530
今さら聞けない .NET CLI
htkym
0
170
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
510
Claude Team Plan導入・ガイド
tk3fftk
0
250
2年かけて Deno に DOMMatrix を実装した話 / How I implemented DOMMatrix in Deno over two years
petamoriken
0
190
React本体のコードリーディング
high_g_engineer
1
130
PHP初心者セッション2026 〜生成AIでは見えない裏側を知る:今だからLAMPを通して仕組みを学ぶ〜
kashioka
0
800
20260722_microCMSで考える、AI時代のコンテンツ運用設計
yosh1
0
270
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
440
Terraform標準の組織で AWS CDKをどう使うか
mu7889yoon
1
460
Featured
See All Featured
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
660
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.5k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.5k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.8k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
240
The Pragmatic Product Professional
lauravandoore
37
7.4k
Information Architects: The Missing Link in Design Systems
soysaucechin
0
1k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
160
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Chasing Engaging Ingredients in Design
codingconduct
0
260
Transcript
AllenNLPを使った開発 ⾕⼝泰史
⽬次 1. AllenNLPとは︖ 2. AllenNLPの概要 3. AllenNLPによる実装例 4. まとめ
1. AllenNLPとは • NLP研究に特化したPyTorchベースのライブラリ • プロトタイプ作成が簡単 • ハイパーパラメータ管理が簡単
1. AllenNLPとは • NLP研究に特化したPyTorchベースのライブラリ • プロトタイプ作成が簡単 • ハイパーパラメータ管理が簡単
1. プロトタイプ作成
1. プロトタイプ作成 論⽂で提案された様々な⼿法が実装済み
1. AllenNLPとは • NLP研究に特化したPyTorchベースのライブラリ • プロトタイプ作成が簡単 • ハイパーパラメータ管理が簡単
1. パラメータ管理 python -m torch.distributed.launch --nproc_per_node=8 ./examples/run_squad.py ¥ --model_type bert
¥ --model_name_or_path bert-large-uncased-whole-word-masking ¥ --do_train ¥ --do_eval ¥ --do_lower_case ¥ --train_file $SQUAD_DIR/train-v1.1.json ¥ --predict_file $SQUAD_DIR/dev-v1.1.json ¥ --learning_rate 3e-5 ¥ --num_train_epochs 2 ¥ --max_seq_length 384 ¥ --doc_stride 128 ¥ --output_dir ../models/wwm_uncased_finetuned_squad/ ¥ --per_gpu_eval_batch_size=3 ¥ --per_gpu_train_batch_size=3 ¥
1. パラメータ管理 allennlp train ¥ --include-package pretrained_bert ¥ model_config/pretrained_bert_large_squad1.1.jsonnet
1. パラメータ管理 allennlp train ¥ --include-package pretrained_bert ¥ model_config/pretrained_bert_large_squad1.1.jsonnet ファイルで指定するのでGit管理可能
2. AllenNLPの概要
Trainer データセットの準備 実験 モデル構築 DatasetReader Model torch.optim, etc Config files
$ allennlp train 2. AllenNLPの概要
2. AllenNLPの概要 DatasetReader Model
2. AllenNLPの概要 DatasetReader Model
2. DatasetReaderの役割 誰が⼀番に着くか私には分かりません。 DatasetReader tensor([88, 19, 226, 3, 151, 25,
18, 14, 3, 1, 273, 34, 17, 37, 26, 0])
2. AllenNLPの概要 DatasetReader Model
2. Modelの役割 tensor([88, 19, 226, 3, 151, 25, 18, 14,
3, 1, 273, 34, 17, 37, 26, 0]) Model {“loss”: tensor([0.1234])}
3. AllenNLPによる実装例
3. AllenNLPによる実装例 • 感情分析タスク (IMDB Dataset) に取り組む • 与えられた⽂書が肯定的か・否定的かを予測する •
DatasetReaderとModelの実装を紹介
3. DatasetReaderの実装 @overrides def text_to_instance(self, string, label): fields = {}
tokens = self._tokenizer.tokenize(string) fields['tokens'] = TextField(tokens, self._token_indexers) fields['label'] = LabelField(label, skip_indexing=True) return Instance(fields) • トークナイゼーション • インデックス化
3. DatasetReaderの実装 • ⽂書のトークナイズを⾏う • トークナイザは設定ファイルで指定する @overrides def text_to_instance(self, string,
label): fields = {} tokens = self._tokenizer.tokenize(string) fields['tokens'] = TextField(tokens, self._token_indexers) fields['label'] = LabelField(label, skip_indexing=True) return Instance(fields)
3. DatasetReaderの実装 • トークナイズした⽂書からTextFieldを⽣成 • インデックス化はTextFieldが実⾏ @overrides def text_to_instance(self, string,
label): fields = {} tokens = self._tokenizer.tokenize(string) fields['tokens'] = TextField(tokens, self._token_indexers) fields['label'] = LabelField(label, skip_indexing=True) return Instance(fields)
3. Modelの実装 def forward(self, tokens, label): embedded_text = self._text_field_embbeder(tokens) mask
= get_text_field_mask(tokens).float() encoded_text = self._dropout( self._seq2vec_encoder(embedded_text, mask=mask) ) logits = self._classification_layer(encoded_text) probs = F.softmax(logits, dim=1) loss = self._loss(logits, label.long().view(-1)) return {“loss”: loss} • ⼊⼒からロスを計算 • dict形式で値を返却
3. 設定ファイル作成 allennlp configure --include-package allennlp_imdb
3. 設定ファイル作成
3. 学習 allennlp train –include-package allennlp_imdb ¥ -s /path/to/serialization ¥
training_config/base_cpu.jsonnet • 設定ファイルを指定して実験を⾏う
3. 学習 allennlp train –include-package allennlp_imdb ¥ -s /path/to/serialization ¥
-o ‘{“trainer”: {“cuda_device”: 0}}’ training_config/base_cpu.jsonnet • 設定ファイルを指定して実験を⾏う • 設定の上書きも可能
4. まとめ • AllenNLPを使えば、必要最低限の実装で実験を⾏える • プロトタイプ作成、ハイパーパラメータの管理も簡単 • コードは下記リンク https://github.com/yasufumy/allennlp_imdb