LSTM classification with different sizes
masking and padding are indeed popular preprocessing choices when working with LSTM. The easiest way is to pad all the short sequences to the same length as the longest sequence.
Here is an example of masking and padding in Keras
https://www.tensorflow.org/guide/keras/masking_and_padding
Is that what you're looking for?
raw_inputs = [
    [711, 632, 71],
    [73, 8, 3215, 55, 927],
    [83, 91, 1, 645, 1253, 927],
]

# By default, this will pad using 0s; it is configurable via the
# &quot;value&quot; parameter.
# Note that you could &quot;pre&quot; padding (at the beginning) or
# &quot;post&quot; padding (at the end).
# We recommend using &quot;post&quot; 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=&quot;post&quot;
)
print(padded_inputs)

Output:
[[ 711  632   71    0    0    0]
 [  73    8 3215   55  927    0]
 [  83   91    1  645 1253  927]]

Besides, you can also add start and end tokens to your sequences, like this example (https://www.tensorflow.org/tutorials/text/nmt_with_attention)
def preprocess_sentence(w):
  w = unicode_to_ascii(w.lower().strip())

  # creating a space between a word and the punctuation following it
  # eg: &quot;he is a boy.&quot; =&gt; &quot;he is a boy .&quot;
  # Reference:- https://stackoverflow.com/questions/3645931/python-padding-punctuation-with-white-spaces-keeping-punctuation
  w = re.sub(r&quot;([?.!,¿])&quot;, r&quot; \1 &quot;, w)
  w = re.sub(r'[&quot; &quot;]+', &quot; &quot;, w)

  # replacing everything with space except (a-z, A-Z, &quot;.&quot;, &quot;?&quot;, &quot;!&quot;, &quot;,&quot;)
  w = re.sub(r&quot;[^a-zA-Z?.!,¿]+&quot;, &quot; &quot;, w)

  w = w.strip()

  # adding a start and an end token to the sentence
  # so that the model know when to start and stop predicting.
  w = '&lt;start&gt; ' + w + ' &lt;end&gt;'
  return w

```