AttributeError:模块'keras.preprocessing.sequence'没有属性'pad_sequences'

问题描述 投票:0回答:0

我收到这个错误:AttributeError: module 'keras.preprocessing.sequence' has no attribute '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'
keras nlp data-science tokenize data-preprocessing
© www.soinside.com 2019 - 2024. All rights reserved.