Search code examples
python-3.xtensorflowmachine-learningkerasdeep-learning

why getting only zeros while padding this values?


I'm trying to do post pad But I'm getting zeros for all values. How to get values from available ones.

raw_inputs = [
    [-6.7329314e-04, -3.2805078e-04,  9.8458688e-05],
    [-6.7329314e-04, -3.2805078e-04,  9.8458688e-05,-6.7329314e-04, -3.2805078e-04,  9.8458688e-05],
    [-6.7329314e-04, -3.2805078e-04,  9.8458688e-05,-6.7329314e-04, -3.2805078e-04,  9.8458688e-05,-6.7329314e-04, -3.2805078e-04,  9.8458688e-05],
]

# By default, this will pad using 0s; it is configurable via the
# "value" parameter.
# Note that you could "pre" padding (at the beginning) or
# "post" padding (at the end).
# We recommend using "post" padding when working with RNN layers
# (in order to be able to use the
# CuDNN implementation of the layers).
padded_inputs = tf.keras.preprocessing.sequence.pad_sequences(
    raw_inputs, padding="post"
)
print(padded_inputs)

Please help me this. Thanks in advance


Solution

  • by default pad_sequences return data in dtype='int32' and this is the reason because your data are cast to zeros... specifying dtype='float64' solves the problem

    padded_inputs = tf.keras.preprocessing.sequence.pad_sequences(
        raw_inputs, padding="post", dtype='float64')