属性错误:模块“keras.preprocessing.sequence”没有属性“pad_sequences”

nqwrtyyt  于 2023-05-07  发布在  其他
关注(0)|答案(1)|浏览(494)

我得到这个错误:属性错误:模块“keras.preprocessing.sequence”没有属性“pad_sequences”

import keras
from keras import preprocessing
from keras.utils import pad_sequences

tokenizer = text.Tokenizer(num_words=max_features)
tokenizer.fit_on_texts(x_train)
tokenized_train = tokenizer.texts_to_sequences(x_train)
x_train = sequence.pad_sequences(tokenized_train, maxlen=maxlen)

tokenized_test = tokenizer.texts_to_sequences(x_test)
X_test = sequence.pad_sequences(tokenized_test, maxlen=maxlen)
Error:

AttributeError                            Traceback (most recent call last)
Cell In[41], line 4
2 tokenizer.fit_on_texts(x_train)
3 tokenized_train = tokenizer.texts_to_sequences(x_train)
4 x_train = sequence.pad_sequences(tokenized_train, maxlen=maxlen)

AttributeError: module 'keras.preprocessing.sequence' has no attribute 'pad_sequences'
nszi6y05

nszi6y051#

尝试将pad_sequences导入为from tensorflow.keras.utils import pad_sequences

相关问题