🚀 roberta_qa_japanese
このモデルは、抽出型の質問応答タスク向けに微調整された、[rinna/japanese - roberta - base](https://huggingface.co/rinna/japanese - roberta - base)(rinna株式会社によって提供される事前学習済みRoBERTaモデル)のバージョンです。このモデルは、Skelter Labsによって提供されるJaQuADデータセットで微調整されており、このデータセットのデータは日本語のウィキペディア記事から収集され、人手によってアノテーション付けされています。
🚀 クイックスタート
このモデルを使用するには、以下の2つの方法があります。
専用パイプラインを使用する場合
from transformers import pipeline
model_name = "tsmatz/roberta_qa_japanese"
qa_pipeline = pipeline(
"question-answering",
model=model_name,
tokenizer=model_name)
result = qa_pipeline(
question = "決勝トーナメントで日本に勝ったのはどこでしたか。",
context = "日本は予選リーグで強豪のドイツとスペインに勝って決勝トーナメントに進んだが、クロアチアと対戦して敗れた。",
align_to_words = False,
)
print(result)
手動で順伝播を行う場合
import torch
import numpy as np
from transformers import AutoModelForQuestionAnswering, AutoTokenizer
model_name = "tsmatz/roberta_qa_japanese"
model = (AutoModelForQuestionAnswering
.from_pretrained(model_name))
tokenizer = AutoTokenizer.from_pretrained(model_name)
def inference_answer(question, context):
question = question
context = context
test_feature = tokenizer(
question,
context,
max_length=318,
)
with torch.no_grad():
outputs = model(torch.tensor([test_feature["input_ids"]]))
start_logits = outputs.start_logits.cpu().numpy()
end_logits = outputs.end_logits.cpu().numpy()
answer_ids = test_feature["input_ids"][np.argmax(start_logits):np.argmax(end_logits)+1]
return "".join(tokenizer.batch_decode(answer_ids))
question = "決勝トーナメントで日本に勝ったのはどこでしたか。"
context = "日本は予選リーグで強豪のドイツとスペインに勝って決勝トーナメントに進んだが、クロアチアと対戦して敗れた。"
answer_pred = inference_answer(question, context)
print(answer_pred)
✨ 主な機能
このモデルは、日本語の抽出型質問応答タスクに特化しており、日本語のウィキペディア記事をベースにしたデータセットで訓練されています。
🔧 技術詳細
訓練手順
微調整のソースコードは、[こちら](https://github.com/tsmatz/huggingface - finetune - japanese/blob/master/03 - question - answering.ipynb)からダウンロードできます。
訓練ハイパーパラメータ
訓練時に使用されたハイパーパラメータは以下の通りです。
ハイパーパラメータ |
値 |
learning_rate |
7e - 05 |
train_batch_size |
2 |
eval_batch_size |
1 |
seed |
42 |
gradient_accumulation_steps |
16 |
total_train_batch_size |
32 |
optimizer |
Adam(betas=(0.9, 0.999)、epsilon = 1e - 08) |
lr_scheduler_type |
linear |
lr_scheduler_warmup_steps |
100 |
num_epochs |
3 |
訓練結果
訓練損失 |
エポック |
ステップ |
検証損失 |
2.1293 |
0.13 |
150 |
1.0311 |
1.1965 |
0.26 |
300 |
0.6723 |
1.022 |
0.39 |
450 |
0.4838 |
0.9594 |
0.53 |
600 |
0.5174 |
0.9187 |
0.66 |
750 |
0.4671 |
0.8229 |
0.79 |
900 |
0.4650 |
0.71 |
0.92 |
1050 |
0.2648 |
0.5436 |
1.05 |
1200 |
0.2665 |
0.5045 |
1.19 |
1350 |
0.2686 |
0.5025 |
1.32 |
1500 |
0.2082 |
0.5213 |
1.45 |
1650 |
0.1715 |
0.4648 |
1.58 |
1800 |
0.1563 |
0.4698 |
1.71 |
1950 |
0.1488 |
0.4823 |
1.84 |
2100 |
0.1050 |
0.4482 |
1.97 |
2250 |
0.0821 |
0.2755 |
2.11 |
2400 |
0.0898 |
0.2834 |
2.24 |
2550 |
0.0964 |
0.2525 |
2.37 |
2700 |
0.0533 |
0.2606 |
2.5 |
2850 |
0.0561 |
0.2467 |
2.63 |
3000 |
0.0601 |
0.2799 |
2.77 |
3150 |
0.0562 |
0.2497 |
2.9 |
3300 |
0.0516 |
フレームワークバージョン
- Transformers 4.23.1
- Pytorch 1.12.1+cu102
- Datasets 2.6.1
- Tokenizers 0.13.1
📄 ライセンス
このモデルはMITライセンスの下で提供されています。