code: def test_masking(self):
      sequence = np.arange(24).reshape((2, 4, 3)).astype("float32")
      mask = np.array(
          [[True, True, False, True], [True, False, False, True]]
      )
      layer = layers.LSTM(
          2,
          kernel_initializer=initializers.Constant(0.01),
          recurrent_initializer=initializers.Constant(0.02),
          bias_initializer=initializers.Constant(0.03),
          unroll=True,
      )
      output = layer(sequence, mask=mask)
      self.assertAllClose(
          np.array([[0.1524914, 0.1524914], [0.35969394, 0.35969394]]),
          output,
      )
  
      layer = layers.LSTM(
          2,
          kernel_initializer=initializers.Constant(0.01),
          recurrent_initializer=initializers.Constant(0.02),
          bias_initializer=initializers.Constant(0.03),
          return_sequences=True,
      )
      output = layer(sequence, mask=mask)
      self.assertAllClose(
          np.array(
              [
                  [0.0158891, 0.0158891],
                  [0.05552047, 0.05552047],
                  [0.05552047, 0.05552047],
                  [0.1524914, 0.1524914],
              ],
          ),
          output[0],
      )
      self.assertAllClose(
          np.array(
              [
                  [0.14185596, 0.14185596],
                  [0.14185596, 0.14185596],
                  [0.14185596, 0.14185596],
                  [0.35969394, 0.35969394],
              ],
          ),
          output[1],
      )
  
      layer = layers.LSTM(
          2,
          kernel_initializer=initializers.Constant(0.01),
          recurrent_initializer=initializers.Constant(0.02),
          bias_initializer=initializers.Constant(0.03),
          return_sequences=True,
          zero_output_for_mask=True,
      )
      output = layer(sequence, mask=mask)
      self.assertAllClose(
          np.array(
              [
                  [0.0158891, 0.0158891],
                  [0.05552047, 0.05552047],
                  [0.0, 0.0],
                  [0.1524914, 0.1524914],
              ],
          ),
          output[0],
      )
      self.assertAllClose(
          np.array(
              [
                  [0.14185596, 0.14185596],
                  [0.0, 0.0],
                  [0.0, 0.0],
                  [0.35969394, 0.35969394],
              ],
          ),
          output[1],
      )
  
      layer = layers.LSTM(
          2,
          kernel_initializer=initializers.Constant(0.01),
          recurrent_initializer=initializers.Constant(0.02),
          bias_initializer=initializers.Constant(0.03),
          go_backwards=True,
      )
      output = layer(sequence, mask=mask)
      self.assertAllClose(
          np.array(
              [[0.10056866, 0.10056866], [0.31006062, 0.31006062]]
          ),
          output,
      )
  
file_path: keras/keras/layers/rnn/lstm_test.py
imports: import numpy
  import pytest
  from absl.testing import parameterized
  from keras import initializers
  from keras import layers
  from keras import testing
label_desc: Use image node_id 5 for calling the LSTMTest obj's underlying member method code with example usage: obj.test_masking() without return types