code: def test_masked_indices_are_handled_correctly(self):
      sequence_tensor = torch.randn([2, 5, 7])
      # concatentate start and end points together to form our representation.
      extractor = EndpointSpanExtractor(7, "x,y")
  
      indices = torch.LongTensor([[[1, 3], [2, 4]], [[0, 2], [3, 4]]])
      span_representations = extractor(sequence_tensor, indices)
  
      # Make a mask with the second batch element completely masked.
      indices_mask = torch.LongTensor([[1, 1], [0, 0]])
  
      span_representations = extractor(
          sequence_tensor, indices, span_indices_mask=indices_mask
      )
      start_embeddings, end_embeddings = span_representations.split(
          7, -1
      )
      start_indices, end_indices = indices.split(1, -1)
  
      correct_start_embeddings = batched_index_select(
          sequence_tensor, start_indices.squeeze()
      ).data
      # Completely masked second batch element, so it should all be zero.
      correct_start_embeddings[1, :, :].fill_(0)
      correct_end_embeddings = batched_index_select(
          sequence_tensor, end_indices.squeeze()
      ).data
      correct_end_embeddings[1, :, :].fill_(0)
      numpy.testing.assert_array_equal(
          start_embeddings.data.numpy(),
          correct_start_embeddings.numpy(),
      )
      numpy.testing.assert_array_equal(
          end_embeddings.data.numpy(), correct_end_embeddings.numpy()
      )
  
file_path: magnitude/pymagnitude/third_party/allennlp/tests/modules/span_extractors/endpoint_span_extractor_test.py
imports: from __future__ import absolute_import
  import numpy
  import torch
  from allennlp.modules.span_extractors import SpanExtractor, EndpointSpanExtractor
  from allennlp.common.params import Params
  from allennlp.nn.util import batched_index_select
label_desc: Use image node_id 3 for calling the TestEndpointSpanExtractor obj's underlying member method code with example usage: obj.test_masked_indices_are_handled_correctly() without return types