🚀 DistilBERT base uncased distilled SQuAD
DistilBERT base uncased distilled SQuADは、質問応答タスクに特化した軽量で高速なTransformerベースの言語モデルです。BERTを蒸留したDistilBERTをベースに、SQuAD v1.1データセットでファインチューニングされています。
🚀 クイックスタート
以下のコードを使用して、このモデルを始めることができます。
基本的な使用法
>>> from transformers import pipeline
>>> question_answerer = pipeline("question-answering", model='distilbert-base-uncased-distilled-squad')
>>> context = r"""
... Extractive Question Answering is the task of extracting an answer from a text given a question. An example of a
... question answering dataset is the SQuAD dataset, which is entirely based on that task. If you would like to fine-tune
... a model on a SQuAD task, you may leverage the examples/pytorch/question-answering/run_squad.py script.
... """
>>> result = question_answerer(question="What is a good example of a question answering dataset?", context=context)
>>> print(
... f"Answer: '{result['answer']}', score: {round(result['score'], 4)}, start: {result['start']}, end: {result['end']}"
...)
Answer: 'SQuAD dataset', score: 0.4704, start: 147, end: 160
高度な使用法
PyTorchでの使用例
from transformers import DistilBertTokenizer, DistilBertForQuestionAnswering
import torch
tokenizer = DistilBertTokenizer.from_pretrained('distilbert-base-uncased-distilled-squad')
model = DistilBertForQuestionAnswering.from_pretrained('distilbert-base-uncased-distilled-squad')
question, text = "Who was Jim Henson?", "Jim Henson was a nice puppet"
inputs = tokenizer(question, text, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
answer_start_index = torch.argmax(outputs.start_logits)
answer_end_index = torch.argmax(outputs.end_logits)
predict_answer_tokens = inputs.input_ids[0, answer_start_index : answer_end_index + 1]
tokenizer.decode(predict_answer_tokens)
TensorFlowでの使用例
from transformers import DistilBertTokenizer, TFDistilBertForQuestionAnswering
import tensorflow as tf
tokenizer = DistilBertTokenizer.from_pretrained("distilbert-base-uncased-distilled-squad")
model = TFDistilBertForQuestionAnswering.from_pretrained("distilbert-base-uncased-distilled-squad")
question, text = "Who was Jim Henson?", "Jim Henson was a nice puppet"
inputs = tokenizer(question, text, return_tensors="tf")
outputs = model(**inputs)
answer_start_index = int(tf.math.argmax(outputs.start_logits, axis=-1)[0])
answer_end_index = int(tf.math.argmax(outputs.end_logits, axis=-1)[0])
predict_answer_tokens = inputs.input_ids[0, answer_start_index : answer_end_index + 1]
tokenizer.decode(predict_answer_tokens)
✨ 主な機能
このモデルは質問応答タスクに使用できます。
誤用と範囲外の使用
このモデルは、人に対して敵意的または疎外感を与える環境を意図的に作り出すために使用してはいけません。また、このモデルは人や出来事の事実的または真実の表現を学習するように訓練されていないため、そのような内容を生成するために使用することは、このモデルの能力範囲外です。
🔧 技術詳細
モデル詳細
DistilBERTモデルは、ブログ記事 Smaller, faster, cheaper, lighter: Introducing DistilBERT, adistilled version of BERT と論文 DistilBERT, adistilled version of BERT: smaller, faster, cheaper and lighter で提案されました。DistilBERTは、BERT baseを蒸留して訓練された小さく、速く、安く、軽量なTransformerモデルです。bert-base-uncased よりもパラメータが40%少なく、60%高速に動作し、GLUE言語理解ベンチマークで測定したBERTの性能の95%以上を維持しています。
このモデルは、DistilBERT-base-uncased のファインチューニングチェックポイントであり、SQuAD v1.1 で知識蒸留(2段階目)を使用してファインチューニングされています。
訓練
訓練データ
distilbert-base-uncasedモデル は、以下のように訓練データを説明しています。
DistilBERTは、BERTと同じデータ、つまり11,038冊の未公開の本からなるデータセット BookCorpus と 英語版ウィキペディア(リスト、表、ヘッダーを除く)で事前学習されています。
SQuAD v1.1データセットについて詳しく知るには、SQuAD v1.1データカード を参照してください。
訓練手順
前処理
詳細については、distilbert-base-uncasedモデルカード を参照してください。
事前学習
詳細については、distilbert-base-uncasedモデルカード を参照してください。
評価
モデルリポジトリ で議論されているように、
このモデルは、[SQuAD v1.1] 開発セットでF1スコア86.9に達します(比較のため、Bert bert-base-uncasedバージョンはF1スコア88.5に達します)。
環境への影響
炭素排出量は、Lacoste et al. (2019) で提示された Machine Learning Impact calculator を使用して推定できます。以下は、関連論文 に基づいたハードウェアタイプと使用時間です。これらの詳細は、DistilBERTの訓練のみに関するもので、SQuADでのファインチューニングは含まれていません。
- ハードウェアタイプ:8台の16GB V100 GPU
- 使用時間:90時間
- クラウドプロバイダー:不明
- コンピュートリージョン:不明
- 排出された炭素量:不明
技術仕様
モデリングアーキテクチャ、目的、コンピュートインフラストラクチャ、および訓練の詳細については、関連論文 を参照してください。
📄 ライセンス
このモデルはApache 2.0ライセンスの下で提供されています。
📚 引用情報
@inproceedings{sanh2019distilbert,
title={DistilBERT, a distilled version of BERT: smaller, faster, cheaper and lighter},
author={Sanh, Victor and Debut, Lysandre and Chaumond, Julien and Wolf, Thomas},
booktitle={NeurIPS EMC^2 Workshop},
year={2019}
}
APA形式:
- Sanh, V., Debut, L., Chaumond, J., & Wolf, T. (2019). DistilBERT, a distilled version of BERT: smaller, faster, cheaper and lighter. arXiv preprint arXiv:1910.01108.
モデルカード作成者
このモデルカードはHugging Faceチームによって作成されました。