英文

多语言XLM-RoBERTa基于各种语言的问答

概览

语言模型:xlm-roberta-base 语言:多语言 下游任务:提取性问答 训练数据:SQuAD 2.0 评估数据:SQuAD 2.0开发集 - 德文MLQA - 德文XQuAD 代码:请见 example 中的 FARM 基础设施:4x Tesla v100

超参数

batch_size = 22*4
n_epochs = 2
max_seq_len=256,
doc_stride=128,
learning_rate=2e-5,

相应的实验日志在mlflow中: link

性能

official eval script 评估SQuAD 2.0开发集。

"exact": 73.91560683904657
"f1": 77.14103746689592

在德文MLQA上评估:test-context-de-question-de.json"exact": 33.67279167589108 "f1": 44.34437105434842 "total": 4517

在德文XQuAD上评估:xquad.de.json"exact": 48.739495798319325 "f1": 62.552615701071495 "total": 1190

用法

在Transformers中

from transformers.pipelines import pipeline
from transformers.modeling_auto import AutoModelForQuestionAnswering
from transformers.tokenization_auto import AutoTokenizer

model_name = "deepset/xlm-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/xlm-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/xlm-roberta-base-squad2")
# or 
reader = TransformersReader(model="deepset/roberta-base-squad2",tokenizer="deepset/xlm-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 | Discord | GitHub Discussions | Website

顺便说一句: we're hiring!