Wednesday 25 November 2020

Keras multiple inputs masking

I am building a LSTM model with multiple inputs (the number is given by n_inputs). I scaled the inputs in (0, 1) and replaced all the NaN of the inputs with -1. Now I want the model to ignore such NaN values, therefore I use a mask as it follows:

model= Sequential()
model.add(Masking(mask_value=-1, input_shape=(window, n_inputs)))
model.add(LSTM(units=n_units), return_sequences=True)
model.add(Dropout(dropout_rate))
model.add(LSTM(units=n_units))
model.add(Dropout(dropout_rate))
model.add(Dense(units=1))

I am afraid that the Masking forces the model to completely ignore one timestep of data if any of the inputs has NaN value (I am not sure how to check if this is the case). What I want though is: for each timestemp, ignore only the NaN inputs, but pass the others that are valid. My question is: does the Masking exclude all the timesteps for which at least one input is NaN? If it does, how can I get the model to ignore only the NaN inputs?



from Keras multiple inputs masking

No comments:

Post a Comment