Very long sequence in neural networks

Beginner's question regarding sequences in neural networks: suppose I have classification problem that looks like:
X = very long sequence of varying length. Y = class (assume for simplicity y=0/1).
The class depends on the whole sequence - it is impossible to determine the class without seeing all of it.
How NN handle this? I have read various methods, such as truncating the sequence (which is a problem - there is no class for truncated part of the sequence, so I cannot label it), using encoder/decoder lstm (again, couldn't completely understand how it solves the problem), etc.

You can indeed use the ability of recurrent network like LSTM to handle the varying length problem. But unfortunately if you use keras or Tensorflow, all the Tensor must have the same length in a batch. What you can do :

• Pad all the sequences with an unused value (typically 0) so that all the sequences have the same length. Use a mask layer just after the Input layer : the 0s will not be taken into account for training the model. Bellow an example using the Keras framework (not complete, not tested) :

from keras.models import Model
from keras.layers import Input, LSTM, Dense
input = Input(shape=[None, nb_of_features_per_timestep])