提问人:Pramit 提问时间:11/16/2023 最后编辑:KinjalPramit 更新时间:11/23/2023 访问量:31
使用变压器管道的正确命令是什么?
What is the correct command to use pipelines from transformers?
问:
我安装了变压器,也安装了 huggingface,并且我成功地运行了这段代码,但我不知道现在发生了什么。之后我有pip安装管道,但它干扰了代码(所以我删除了它)
from pipelines import pipeline
nlp = pipeline("e2e-qg")
nlp("42 is the answer to life, the universe and everything.")
它现在给了我一个错误
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
from pipelines import pipeline
ModuleNotFoundError: No module named 'pipelines'
答:
0赞
Kinjal
11/23/2023
#1
尝试使用最新的库。以下是其他尝试方法transformers
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text2text-generation", model="valhalla/t5-base-e2e-qg")
另一种方式
# Load model directly
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained("valhalla/t5-base-e2e-qg")
model = AutoModelForSeq2SeqLM.from_pretrained("valhalla/t5-base-e2e-qg")
您可以在此处找到此文档
评论
from transformers import pipeline