python - 我正在使用 Huggingface 的预训练 Pegasus 模型获取 Inshorts 数据集的抽象摘要
问题描述
我正在使用 Huggingface 的预训练 Pegasus 模型获取 Inshorts 数据集的抽象摘要。
我正在尝试在“inshorts”数据集(https://www.kaggle.com/shashichander009/inshorts-news-data/metadata)上使用此模型,其中我基本上需要由预训练模型为每个 Inshorts 样本生成的摘要使用输入作为数据集中的“短裤”列来预测摘要。因此,我尝试遍历“短裤”列但抛出错误:
TypeError: 'NoneType' object is not callable
下面是后台代码:
from transformers import PegasusForConditionalGeneration, PegasusTokenizer
tokenizer = PegasusTokenizer.from_pretrained("google/pegasus-xsum")
model = PegasusForConditionalGeneration.from_pretrained("google/pegasus-xsum")
以下是与数据集相关的代码:
import io
df = pd.read_excel(io.BytesIO(uploaded['inshorts.xlsx']))
这是它引发错误的代码:
for a in range(0,3):
text = df.iloc[a,1]
updated_text= ' """ ' + text + ' """ '
print(updated_text)
错误在这一行:
tokens = tokenizer(updated_text , truncation=True, padding="longest", return_tensors="pt")
summary = model.generate(**tokens)
tokenizer.decode(summary[0])
解决方案
问题是因为运行后tokenizer
仍然存在。有一个名为running的必备软件包,可能您已经安装了,但请记住,安装后您必须使用 session/kernel 才能使更改生效。完成上述步骤后,tokenizer 变量将保存对象并解决了问题。None
tokenizer = PegasusTokenizer.from_pretrained("google/pegasus-xsum")
SentencePiece
pegasus
restart
transformers.models.pegasus.tokenization_pegasus.PegasusTokenizer
推荐阅读
- flutter - FlutterError:“在 DrawerMenu 上查找已停用小部件的祖先是不安全的”?
- gremlin - Tinkerpop Gremlin - 如何将变量聚合到遍历独立集合中
- java - gcr.io/distroless/java:11 使用从 11:.0.6 到 11.0.8 的基本版本
- sql - 在子查询中使用 distinct on
- c++ - 创建容量溢出异常
- ios - 如何与测试用户一起测试“使用 Apple 登录”?
- java - 如何将数据从一个表复制到另一个表,然后使用 Java 删除第一个表中的数据?
- xslt - 我们可以在调用 number() 函数是 xslt 时使用加号参数吗
- python - 电报editMessageMedia替代telepot
- html - 随机生成“id”属性值的缺点是什么?