Why can't I use preprocessing module in Keras?
Question:
I’m trying to use the function pad_sequences() but the same error keeps rising: ‘AttributeError: ‘module’ object has no attribute ‘sequence”
I have followed Keras documentation and I can’t figure out why It does not work. Here is the line of code:
from keras import preprocessing
import keras
X_test = sequence.pad_sequences(X_test, maxlen=500)
X_test = preprocessing.sequence.pad_sequences(X_test, maxlen=500)
X_test = keras.preprocessing.sequence.pad_sequences(X_test, maxlen=500)
None of the above lines seem to work.
Answers:
In the first line please use
X_test = preprocessing.sequence.pad_sequences(X_test, maxlen=500)
You can simply import pad_sequences like so instead
from keras.preprocessing.sequence import pad_sequences
and replace preprocessing.sequence.pad_sequences
with just pad_sequences
in tf version 2.9 it is under keras.utils
from keras.utils import pad_sequences
always search the function in TF git repo and locate the right path.
Try replacing X_test = preprocessing.sequence.pad_sequences(X_test, maxlen=500)
with
X_test = keras.utils.pad_sequences(X_test, maxlen=500)
and using
(from keras.utils import pad_sequences)
keras–v=2.10.2
I’m trying to use the function pad_sequences() but the same error keeps rising: ‘AttributeError: ‘module’ object has no attribute ‘sequence”
I have followed Keras documentation and I can’t figure out why It does not work. Here is the line of code:
from keras import preprocessing
import keras
X_test = sequence.pad_sequences(X_test, maxlen=500)
X_test = preprocessing.sequence.pad_sequences(X_test, maxlen=500)
X_test = keras.preprocessing.sequence.pad_sequences(X_test, maxlen=500)
None of the above lines seem to work.
In the first line please use
X_test = preprocessing.sequence.pad_sequences(X_test, maxlen=500)
You can simply import pad_sequences like so instead
from keras.preprocessing.sequence import pad_sequences
and replace preprocessing.sequence.pad_sequences
with just pad_sequences
in tf version 2.9 it is under keras.utils
from keras.utils import pad_sequences
always search the function in TF git repo and locate the right path.
Try replacing X_test = preprocessing.sequence.pad_sequences(X_test, maxlen=500)
with
X_test = keras.utils.pad_sequences(X_test, maxlen=500)
and using
(from keras.utils import pad_sequences)
keras–v=2.10.2