🚀 英文抽取式問答模型
本模型用於英文抽取式問答任務,基於預訓練模型構建,能有效從文本中提取答案,為英文問答場景提供支持。
🚀 快速開始
你可以通過 🤗 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'}
高級用法
文檔未提及高級用法相關代碼示例。
📚 詳細文檔
模型信息