code: def test_get_final_encoder_states(self):
      encoder_outputs = torch.Tensor(
          [
              [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]],
              [[13, 14, 15, 16], [17, 18, 19, 20], [21, 22, 23, 24]],
          ]
      )
      mask = torch.Tensor([[1, 1, 1], [1, 1, 0]])
      final_states = util.get_final_encoder_states(
          encoder_outputs, mask, bidirectional=False
      )
      assert_almost_equal(
          final_states.data.numpy(), [[9, 10, 11, 12], [17, 18, 19, 20]]
      )
      final_states = util.get_final_encoder_states(
          encoder_outputs, mask, bidirectional=True
      )
      assert_almost_equal(
          final_states.data.numpy(), [[9, 10, 3, 4], [17, 18, 15, 16]]
      )
  
imports: from __future__ import with_statement
  from __future__ import division
  from __future__ import absolute_import
  import numpy
  from numpy.testing import assert_array_almost_equal, assert_almost_equal
  import torch
  import pytest
  from allennlp.common.checks import ConfigurationError
  from allennlp.common.testing import AllenNlpTestCase
  from allennlp.nn import util
label_desc: Use image node_id 5 for calling the TestNnUtil obj's underlying member method code with example usage: obj.test_get_final_encoder_states() without return types