这模型靠谱

#2
by ljwd - opened

from transformers import pipeline
#先下载“Files and versions”中的模型文件到本地“pretrained”文件夹
qa = pipeline(task='question-answering',model='pretrained',device=0)
res = qa(question=["你叫什么","你是谁"],context=“我是二狗,我叫渣渣灰”)

上面的代码我执行报错,应该是没有先下载模型到pretrained文件。我是用下面命令在python交互命令窗口执行的,会直接下载模型。
from transformers import pipeline
from transformers import AutoTokenizer, AutoModelForQuestionAnswering
model_name = "chinese_pretrain_mrc_roberta_wwm_ext_large"
tokenizer = AutoTokenizer.from_pretrained(f"luhua/{model_name}")
model = AutoModelForQuestionAnswering.from_pretrained(f"luhua/{model_name}")
qa = pipeline(task='question-answering',model=model,tokenizer=tokenizer)
qa(question=["你叫什么","你是谁"],context='我是二狗,我叫渣渣灰')

结果:
[{'score': 0.22574695944786072, 'start': 7, 'end': 10, 'answer': '渣渣灰'},
{'score': 0.21701981127262115, 'start': 7, 'end': 10, 'answer': '渣渣灰'}]

Sign up or log in to comment