模型:
nguyenvulebinh/vi-mrc-large
任务:
许可:
该模型旨在用于越南语的问答,因此验证集仅使用越南语(但英语也可以)。下面的评估结果使用了VLSP MRC 2021测试集。该实验在排行榜上取得了第一名。
| Model | EM | F1 | 
|---|---|---|
| 1238321 public_test_set | 85.847 | 83.826 | 
| 1238321 private_test_set | 82.072 | 78.071 | 
| Public leaderboard | Private leaderboard | 
|---|
MRCQuestionAnswering 使用 XLM-RoBERTa 作为预训练语言模型。默认情况下,XLM-RoBERTa会将单词分割为子词。但在我的实现中,我使用求和策略将子词表示(在BERT层编码后)重新组合成单词表示。
from transformers import pipeline
# model_checkpoint = "nguyenvulebinh/vi-mrc-large"
model_checkpoint = "nguyenvulebinh/vi-mrc-base"
nlp = pipeline('question-answering', model=model_checkpoint,
                   tokenizer=model_checkpoint)
QA_input = {
  'question': "Bình là chuyên gia về gì ?",
  'context': "Bình Nguyễn là một người đam mê với lĩnh vực xử lý ngôn ngữ tự nhiên . Anh nhận chứng chỉ Google Developer Expert năm 2020"
}
res = nlp(QA_input)
print('pipeline: {}'.format(res))
#{'score': 0.5782045125961304, 'start': 45, 'end': 68, 'answer': 'xử lý ngôn ngữ tự nhiên'}
 from infer import tokenize_function, data_collator, extract_answer
from model.mrc_model import MRCQuestionAnswering
from transformers import AutoTokenizer
model_checkpoint = "nguyenvulebinh/vi-mrc-large"
#model_checkpoint = "nguyenvulebinh/vi-mrc-base"
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
model = MRCQuestionAnswering.from_pretrained(model_checkpoint)
QA_input = {
  'question': "Bình được công nhận với danh hiệu gì ?",
  'context': "Bình Nguyễn là một người đam mê với lĩnh vực xử lý ngôn ngữ tự nhiên . Anh nhận chứng chỉ Google Developer Expert năm 2020"
}
inputs = [tokenize_function(*QA_input)]
inputs_ids = data_collator(inputs)
outputs = model(**inputs_ids)
answer = extract_answer(inputs, outputs, tokenizer)
print(answer)
# answer: Google Developer Expert. Score start: 0.9926977753639221, Score end: 0.9909810423851013