1

I'm getting this error : 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'

1 Answers1

0

Try to import pad_sequences as from tensorflow.keras.utils import pad_sequences

ptushev
  • 177
  • 3
  • 16