🚀 英文抽取式问答模型
本模型用于英文抽取式问答任务,基于预训练模型构建,能有效从文本中提取答案,为英文问答场景提供支持。
🚀 快速开始
你可以通过 🤗 Transformers 库的管道直接使用该模型:
>>> from transformers.pipelines import pipeline
>>> from transformers import AutoTokenizer, AutoModelForQuestionAnswering
>>> tokenizer = AutoTokenizer.from_pretrained("zhufy/squad-en-bert-base")
>>> model = AutoModelForQuestionAnswering.from_pretrained("zhufy/squad-en-bert-base")
>>> nlp = pipeline("question-answering", model=model, tokenizer=tokenizer)
>>> context = "A problem is regarded as inherently difficult if its \
solution requires significant resources, whatever the \
algorithm used. The theory formalizes this intuition, \
by introducing mathematical models of computation to \
study these problems and quantifying the amount of \
resources needed to solve them, such as time and storage. \
Other complexity measures are also used, such as the \
amount of communication (used in communication complexity), \
the number of gates in a circuit (used in circuit \
complexity) and the number of processors (used in parallel \
computing). One of the roles of computational complexity \
theory is to determine the practical limits on what \
computers can and cannot do."
>>> question = "What are two basic primary resources used to \
guage complexity?"
>>> inputs = {"question": question, \
"context":context }
>>> nlp(inputs)
{'score': 0.8589141368865967,
'start': 305,
'end': 321,
'answer': 'time and storage'}
✨ 主要特性
📦 安装指南
文档未提及具体安装步骤,可参考 🤗 Transformers 库的安装说明。
💻 使用示例
基础用法
>>> from transformers.pipelines import pipeline
>>> from transformers import AutoTokenizer, AutoModelForQuestionAnswering
>>> tokenizer = AutoTokenizer.from_pretrained("zhufy/squad-en-bert-base")
>>> model = AutoModelForQuestionAnswering.from_pretrained("zhufy/squad-en-bert-base")
>>> nlp = pipeline("question-answering", model=model, tokenizer=tokenizer)
>>> context = "A problem is regarded as inherently difficult if its \
solution requires significant resources, whatever the \
algorithm used. The theory formalizes this intuition, \
by introducing mathematical models of computation to \
study these problems and quantifying the amount of \
resources needed to solve them, such as time and storage. \
Other complexity measures are also used, such as the \
amount of communication (used in communication complexity), \
the number of gates in a circuit (used in circuit \
complexity) and the number of processors (used in parallel \
computing). One of the roles of computational complexity \
theory is to determine the practical limits on what \
computers can and cannot do."
>>> question = "What are two basic primary resources used to \
guage complexity?"
>>> inputs = {"question": question, \
"context":context }
>>> nlp(inputs)
{'score': 0.8589141368865967,
'start': 305,
'end': 321,
'answer': 'time and storage'}
高级用法
文档未提及高级用法相关代码示例。
📚 详细文档
模型信息