🚀 问答模型
本模型旨在用于问答任务,给定问题和上下文,模型会尝试推断答案文本、答案范围和置信度得分。该模型仅使用编码器(deepset/roberta-base-squad2),带有问答语言模型头,并在SQUADx数据集上进行了微调,精确匹配得分达到84.83,F1得分达到91.80。
实时演示:问答编码器与生成式模型对比
点击此链接查看基于编码器的问答模型V1
点击此链接查看生成式问答模型
🚀 快速开始
示例代码
from transformers import pipeline
model_checkpoint = "consciousAI/question-answering-roberta-base-s-v2"
context = """
🤗 Transformers is backed by the three most popular deep learning libraries — Jax, PyTorch and TensorFlow — with a seamless integration
between them. It's straightforward to train your models with one before loading them for inference with the other.
"""
question = "Which deep learning libraries back 🤗 Transformers?"
question_answerer = pipeline("question-answering", model=model_checkpoint)
question_answerer(question=question, context=context)
✨ 主要特性
- 专为问答任务设计,能根据问题和上下文推断答案。
- 仅使用编码器架构,带有问答语言模型头。
- 在SQUADx数据集上微调,有较好的精确匹配和F1得分。
📦 安装指南
文档未提供安装步骤,可参考transformers
库的官方安装文档进行安装。
💻 使用示例
基础用法
from transformers import pipeline
model_checkpoint = "consciousAI/question-answering-roberta-base-s-v2"
context = """
🤗 Transformers is backed by the three most popular deep learning libraries — Jax, PyTorch and TensorFlow — with a seamless integration
between them. It's straightforward to train your models with one before loading them for inference with the other.
"""
question = "Which deep learning libraries back 🤗 Transformers?"
question_answerer = pipeline("question-answering", model=model_checkpoint)
question_answerer(question=question, context=context)
📚 详细文档
训练和评估数据
SQUAD拆分
训练过程
预处理
- SQUAD数据的长块被分割成子块,输入上下文最大长度为384个标记,步长为128个标记。
- 针对子块重新调整目标答案,没有答案或部分答案的子块的目标答案范围设置为(0,0)。
指标
- 相应调整以处理子块划分。
- n最佳答案数为20。
- 跳过长度为零或高于最大答案长度(30)的答案。
训练超参数
自定义训练循环:
以下超参数在训练期间使用:
- 学习率:2e-5
- 训练批次大小:32
- 评估批次大小:32
- 优化器:Adam,β值为(0.9, 0.999),ε值为1e-08
- 学习率调度器类型:线性
- 训练轮数:2
训练结果
{'exact_match': 84.83443708609272, 'f1': 91.79987545811638}
框架版本
- Transformers 4.23.0.dev0
- Pytorch 1.12.1+cu113
- Datasets 2.5.2
- Tokenizers 0.13.0
📄 许可证
本项目采用Apache-2.0许可证。