🚀 問答模型
本模型旨在用於問答任務,給定問題和上下文,模型會嘗試推斷答案文本、答案範圍和置信度得分。該模型僅使用編碼器(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許可證。