How to train real-time LSTM with input and output of varying length?
I have the data of banner clicks by minute.
I have the following data: hour, minute, and was the banner clicked by someone in that minute. There are some other features (I omitted them in the example dataframe). I need to predict will be any clicks on banner for all following minutes of this hour.
For example I have data for the first 11 minutes of an hour.




hour
minute
is_click




1
1
0


1
2
0


1
3
1


1
4
0


1
5
1


1
6
0


1
7
0


1
8
0


1
9
1


1
10
1


1
11
0




My goal is to make prediction for 12, 13  ... 59, 60 minute.
It will be real-time model that makes predictions every minute using the latest data.
For example, I made the prediction at 18:00 for the next 59 minutes (until 18:59). Now it is 18:01 and I get the real data about  clicks at 18:00, so I want to make more precise prediction for following 58 minutes (from 18:02 to 18:59). And so on.
My idea was to mask-out the passed minutes with -1
I created the example of 11 minutes.There are targets:




minute
target vector




1
-1  0  1  0  1  0  0  0  1  1  0


2
-1 -1 1 0 1 0 0 0 1 1 0


3
-1 -1 -1 0 1 0 0 0 1 1 0


4
-1 -1 -1 -1 1 0 0 0 1 1 0


5
-1 -1 -1 -1 -1 0 0 0 1 1 0


6
-1 -1 -1 -1 -1 -1 0 0 1 1 0


7
-1 -1 -1 -1 -1 -1 -1 0 1 1 0


8
-1 -1 -1 -1 -1 -1 -1 -1 1 1 0


9
-1 -1 -1 -1 -1 -1 -1 -1 -1 1 0


10
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0


11
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1




However it seems strange to me to train a model to predict this mask values of -1. I think for neural network it will be not obvious that these -1 are just a padding.
The another idea was to use a current minute as a feature and ,therefore, to predict always the sequence of 60 - minute length and then cut the extra prediction. However, the input will have  different lengths anyway, so it does not solve the problem.
So how I should preprocess the data to use LSTM? Should I use described above padding so all vectors will be have the same length of 60? Is there any better solution?

An RNN (or LSTM) will return an output for every input, as well as the final hidden state (and cell state for LSTM). So one possible solution: Pad your input of future minutes with with a different token and use an embedding layer with 3 embeddings (0, 1, 2 where 2 represents unseen value). For example, at timestep 3 the input = [0, 0, 1, 2, 2, 2,...2].
After this goes through an embedding layer each token will mapped to some embedding dimension (e.g. 16) and this would be pass to the LSTM. So the input size for your LSTM would be 16 and the hidden size would be one (so that you get a scalar output for every timestep of the input). Then you pass this output through a sigmoid so each prediction is between 0 and 1 and use binary cross entropy between the predictions and targets as your loss function. Additionally, since you probably don't care how accurate the predictions are for the minutes you've already seen, you could ignore their contribution to the loss.
