code: def test_stacked_bidirectional_lstm_dropout_version_is_different(
      self, dropout_name: str
  ):
      stacked_lstm = StackedBidirectionalLstm(
          input_size=10, hidden_size=11, num_layers=3
      )
      if dropout_name == "layer_dropout_probability":
          dropped_stacked_lstm = StackedBidirectionalLstm(
              input_size=10,
              hidden_size=11,
              num_layers=3,
              layer_dropout_probability=0.9,
          )
      elif dropout_name == "recurrent_dropout_probability":
          dropped_stacked_lstm = StackedBidirectionalLstm(
              input_size=10,
              hidden_size=11,
              num_layers=3,
              recurrent_dropout_probability=0.9,
          )
      else:
          raise ValueError(
              "Do not recognise the following dropout name "
              f"{dropout_name}"
          )
      # Initialize all weights to be == 1.
      constant_init = Initializer.from_params(
          Params({"type": "constant", "val": 0.5})
      )
      initializer = InitializerApplicator([(".*", constant_init)])
      initializer(stacked_lstm)
      initializer(dropped_stacked_lstm)
  
      initial_state = torch.randn([3, 5, 11])
      initial_memory = torch.randn([3, 5, 11])
  
      tensor = torch.rand([5, 7, 10])
      sequence_lengths = torch.LongTensor([7, 7, 7, 7, 7])
  
      sorted_tensor, sorted_sequence, _, _ = sort_batch_by_length(
          tensor, sequence_lengths
      )
      lstm_input = pack_padded_sequence(
          sorted_tensor, sorted_sequence.data.tolist(), batch_first=True
      )
  
      stacked_output, stacked_state = stacked_lstm(
          lstm_input, (initial_state, initial_memory)
      )
      dropped_output, dropped_state = dropped_stacked_lstm(
          lstm_input, (initial_state, initial_memory)
      )
      dropped_output_sequence, _ = pad_packed_sequence(
          dropped_output, batch_first=True
      )
      stacked_output_sequence, _ = pad_packed_sequence(
          stacked_output, batch_first=True
      )
      if dropout_name == "layer_dropout_probability":
          with pytest.raises(AssertionError):
              numpy.testing.assert_array_almost_equal(
                  dropped_output_sequence.data.numpy(),
                  stacked_output_sequence.data.numpy(),
                  decimal=4,
              )
      if dropout_name == "recurrent_dropout_probability":
          with pytest.raises(AssertionError):
              numpy.testing.assert_array_almost_equal(
                  dropped_state[0].data.numpy(),
                  stacked_state[0].data.numpy(),
                  decimal=4,
              )
          with pytest.raises(AssertionError):
              numpy.testing.assert_array_almost_equal(
                  dropped_state[1].data.numpy(),
                  stacked_state[1].data.numpy(),
                  decimal=4,
              )
  
file_path: allennlp/tests/modules/stacked_bidirectional_lstm_test.py
imports: import numpy
  import pytest
  import torch
  from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence
  from allennlp.modules.stacked_bidirectional_lstm import StackedBidirectionalLstm
  from allennlp.modules.seq2seq_encoders import Seq2SeqEncoder
  from allennlp.modules.seq2vec_encoders import Seq2VecEncoder
  from allennlp.common.params import Params
  from allennlp.nn import InitializerApplicator, Initializer
  from allennlp.nn.util import sort_batch_by_length
label_desc: Use image node_id 5 for calling the TestStackedBidirectionalLstm obj's underlying member method code with example usage: obj.test_stacked_bidirectional_lstm_dropout_version_is_different(dropout_name) without return types