模型:

optimum/roberta-base-squad2

英文

ONNX 转换为 QA 的 roberta-base 模型

转换 deepset/roberta-base-squad2

注意:这是模型的第2个版本。有关我们更新的说明,请参见 FARM 存储库中的 this github issue 。如果您想使用第1个版本,在 Transformers 3.5 中加载模型时,请指定 revision="v1.0" 。例如:

model_name = "deepset/roberta-base-squad2"
pipeline(model=model_name, tokenizer=model_name, revision="v1.0", task="question-answering")

概述

语言模型:roberta-base 语言:英语 下游任务:抽取式问答 训练数据:SQuAD 2.0 评估数据:SQuAD 2.0 代码:请参见 FARM 中的 example 基础设施:4x Tesla v100

超参数

batch_size = 96
n_epochs = 2
base_LM_model = "roberta-base"
max_seq_len = 386
learning_rate = 3e-5
lr_schedule = LinearWarmup
warmup_proportion = 0.2
doc_stride=128
max_query_length=64

使用蒸馏模型

请注意,我们还发布了这个模型的蒸馏版本,称为 deepset/tinyroberta-squad2 。蒸馏模型具有相当的预测质量,并且运行速度是基础模型的两倍。

性能

使用 official eval script 对 SQuAD 2.0 开发集进行评估。

"exact": 79.87029394424324,
"f1": 82.91251169582613,

"total": 11873,
"HasAns_exact": 77.93522267206478,
"HasAns_f1": 84.02838248389763,
"HasAns_total": 5928,
"NoAns_exact": 81.79983179142137,
"NoAns_f1": 81.79983179142137,
"NoAns_total": 5945

使用方法

在 Transformers 中

from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline

model_name = "deepset/roberta-base-squad2"

# a) Get predictions
nlp = pipeline('question-answering', model=model_name, tokenizer=model_name)
QA_input = {
    'question': 'Why is model conversion important?',
    'context': 'The option to convert models between FARM and transformers gives freedom to the user and let people easily switch between frameworks.'
}
res = nlp(QA_input)

# b) Load model & tokenizer
model = AutoModelForQuestionAnswering.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)

在 FARM 中

from farm.modeling.adaptive_model import AdaptiveModel
from farm.modeling.tokenization import Tokenizer
from farm.infer import Inferencer

model_name = "deepset/roberta-base-squad2"

# a) Get predictions
nlp = Inferencer.load(model_name, task_type="question_answering")
QA_input = [{"questions": ["Why is model conversion important?"],
             "text": "The option to convert models between FARM and transformers gives freedom to the user and let people easily switch between frameworks."}]
res = nlp.inference_from_dicts(dicts=QA_input, rest_api_schema=True)

# b) Load model & tokenizer
model = AdaptiveModel.convert_from_transformers(model_name, device="cpu", task_type="question_answering")
tokenizer = Tokenizer.load(model_name)

在 haystack 中

如果要对大规模的问题进行问答(而不是单个段落),您还可以在 haystack 中加载模型:

reader = FARMReader(model_name_or_path="deepset/roberta-base-squad2")
# or 
reader = TransformersReader(model_name_or_path="deepset/roberta-base-squad2",tokenizer="deepset/roberta-base-squad2")

作者

Branden Chan: branden.chan[at]deepset.ai Timo Möller: timo.moeller[at]deepset.ai Malte Pietsch: malte.pietsch[at]deepset.ai Tanay Soni: tanay.soni[at]deepset.ai

关于我们

我们通过开源将 NLP 技术带给行业!我们的重点:面向特定行业的语言模型和大规模问答系统。

我们的一些工作:

联系我们: Twitter | LinkedIn | Slack | GitHub Discussions | Website

顺便说一下: we're hiring!