语言: 英语
许可证: Apache-2.0
数据集:
- squad
评估指标:
- squad
模型索引:
- 名称: distilbert-base-cased-distilled-squad
结果:
- 任务:
类型: 问答
名称: 问答
数据集:
名称: squad
类型: squad
配置: 纯文本
拆分: 验证
评估指标:
- 类型: 精确匹配
值: 79.5998
名称: 精确匹配
已验证: 是
验证令牌: eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJoYXNoIjoiZTViZDA2Y2E2NjUyMjNjYjkzNTUzODc5OTk2OTNkYjQxMDRmMDhlYjdmYWJjYWQ2N2RlNzY1YmI3OWY1NmRhOSIsInZlcnNpb24iOjF9.ZJHhboAMwsi3pqU-B-XKRCYP_tzpCRb8pEjGr2Oc-TteZeoWHI8CXcpDxugfC3f7d_oBcKWLzh3CClQxBW1iAQ
- 类型: F1分数
值: 86.9965
名称: F1
已验证: 是
验证令牌: eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJoYXNoIjoiZWZlMzY2MmE1NDNhOGNjNWRmODg0YjQ2Zjk5MjUzZDQ2MDYxOTBlMTNhNzQ4NTA2NjRmNDU3MGIzMTYwMmUyOSIsInZlcnNpb24iOjF9.z0ZDir87aT7UEmUeDm8Uw0oUdAqzlBz343gwnsQP3YLfGsaHe-jGlhco0Z7ISUd9NokyCiJCRc4NNxJQ83IuCw
DistilBERT基础版(区分大小写)蒸馏SQuAD模型
目录
模型详情
模型描述: DistilBERT模型在博客文章更小、更快、更便宜、更轻量:介绍DistilBERT,BERT的蒸馏版本和论文DistilBERT,BERT的蒸馏版本:更小、更快、更便宜、更轻量中提出。DistilBERT是一个通过蒸馏BERT基础版训练得到的小型、快速、经济且轻量的Transformer模型。其参数量比bert-base-uncased少40%,运行速度快60%,同时在GLUE语言理解基准测试中保留了BERT 95%以上的性能表现。
该模型是基于DistilBERT-base-cased的微调检查点,通过(第二步)知识蒸馏在SQuAD v1.1数据集上微调而成。
如何开始使用该模型
使用以下代码快速上手该模型:
>>> from transformers import pipeline
>>> question_answerer = pipeline("question-answering", model='distilbert-base-cased-distilled-squad')
>>> context = r"""
... 抽取式问答是从给定问题的文本中提取答案的任务。例如
... SQuAD数据集就是完全基于该任务的问答数据集。如果想在SQuAD任务上微调
... 模型,可以利用examples/pytorch/question-answering/run_squad.py脚本。
... """
>>> result = question_answerer(question="什么是问答数据集的好例子?", context=context)
>>> print(
... f"答案: '{result['answer']}', 得分: {round(result['score'], 4)}, 起始位置: {result['start']}, 结束位置: {result['end']}"
... )
答案: 'SQuAD数据集', 得分: 0.5152, 起始位置: 147, 结束位置: 160
PyTorch使用示例:
from transformers import DistilBertTokenizer, DistilBertModel
import torch
tokenizer = DistilBertTokenizer.from_pretrained('distilbert-base-cased-distilled-squad')
model = DistilBertModel.from_pretrained('distilbert-base-cased-distilled-squad')
question, text = "吉姆·汉森是谁?", "吉姆·汉森是个好木偶"
inputs = tokenizer(question, text, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
print(outputs)
TensorFlow使用示例:
from transformers import DistilBertTokenizer, TFDistilBertForQuestionAnswering
import tensorflow as tf
tokenizer = DistilBertTokenizer.from_pretrained("distilbert-base-cased-distilled-squad")
model = TFDistilBertForQuestionAnswering.from_pretrained("distilbert-base-cased-distilled-squad")
question, text = "吉姆·汉森是谁?", "吉姆·汉森是个好木偶"
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)
用途
该模型适用于问答任务。
滥用与超范围使用
不得使用该模型蓄意制造针对人群的敌对或疏离环境。此外,该模型未训练用于生成关于人物或事件的真实表述,因此用于此类内容超出模型能力范围。
风险、局限性与偏见
内容警告:读者须知,该模型生成的语言可能对部分人群造成不适或冒犯,并可能传播历史及现有偏见。
大量研究探讨了语言模型的偏见与公平性问题(参见Sheng等人(2021)和Bender等人(2021))。模型预测可能包含涉及受保护群体、身份特征及敏感社会职业群体的有害刻板印象,例如:
>>> from transformers import pipeline
>>> question_answerer = pipeline("question-answering", model='distilbert-base-cased-distilled-squad')
>>> context = r"""
... 爱丽丝坐在长椅上。鲍勃坐在她旁边。
... """
>>> result = question_answerer(question="谁是CEO?", context=context)
>>> print(
... f"答案: '{result['answer']}', 得分: {round(result['score'], 4)}, 起始位置: {result['start']}, 结束位置: {result['end']}"
... )
答案: '鲍勃', 得分: 0.7527, 起始位置: 32, 结束位置: 35
用户(包括直接使用者和下游使用者)应充分了解该模型的风险、偏见和局限性。
训练
训练数据
distilbert-base-cased模型使用与distilbert-base-uncased模型相同的数据训练。distilbert-base-uncased模型描述其训练数据为:
DistilBERT预训练数据与BERT相同,包括BookCorpus(11,038本未出版书籍)和英文维基百科(排除列表、表格和标题)。
关于SQuAD v1.1数据集的更多信息,请参阅SQuAD v1.1数据卡。
训练流程
预处理
详见distilbert-base-cased模型卡。
预训练
详见distilbert-base-cased模型卡。
评估
如模型仓库所述:
该模型在[SQuAD v1.1]开发集上达到87.1的F1分数(对比BERT bert-base-cased版本为88.7)。
环境影响
碳排放量可通过Lacoste等人(2019)提出的机器学习影响计算器估算。训练DistilBERT(不含SQuAD微调)的硬件类型和使用时长基于相关论文:
- 硬件类型: 8块16GB V100 GPU
- 使用时长: 90小时
- 云服务商: 未知
- 计算区域: 未知
- 碳排放量: 未知
技术规格
详见相关论文获取建模架构、目标函数、计算基础设施及训练细节。
引用信息
@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团队撰写。