我得到这个错误:属性错误:模块“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'
1条答案
按热度按时间nszi6y051#
尝试将
pad_sequences
导入为from tensorflow.keras.utils import pad_sequences