首页 > 解决方案 > texts_to_sequences() 缺少 1 个必需的位置参数:“文本”

问题描述

我有一系列形状为 ((8084,)) (UTF-8) 的注释,当我运行此 cod 时出现错误

from keras.preprocessing.text import Tokenizer
X = Tokenizer.texts_to_sequences(data['comment_text'].values)

错误是 TypeError: texts_to_sequences() missing 1 required positional argument: 'texts'

标签: pythontensorflowkerasdeep-learninggoogle-colaboratory

解决方案


texts_to_sequence不是类方法,这不是调用它的方式。查看文档以获取示例。

您应该首先创建一个 Tokenizer 对象并对其进行拟合,然后您可以调用texts_to_sequence.

from keras.preprocessing.text import Tokenizer
texts = data['comment_text'].values
tokenizer = Tokenizer()
tokenizer.fit_on_texts(texts)
X = tokenizer.texts_to_sequences(texts)

推荐阅读