code: def test_widths_are_embedded_correctly(self):
      input_dim = 7
      max_span_width = 5
      span_width_embedding_dim = 3
      output_dim = input_dim + span_width_embedding_dim
      extractor = SelfAttentiveSpanExtractor(
          input_dim=input_dim,
          num_width_embeddings=max_span_width,
          span_width_embedding_dim=span_width_embedding_dim,
      )
      assert extractor.get_output_dim() == output_dim
      assert extractor.get_input_dim() == input_dim
  
      sequence_tensor = torch.randn([2, max_span_width, input_dim])
      indices = torch.LongTensor(
          [[[1, 3], [0, 4], [0, 0]], [[0, 2], [1, 4], [2, 2]]]
      )  # smaller span tests masking.
      span_representations = extractor(sequence_tensor, indices)
      assert list(span_representations.size()) == [2, 3, output_dim]
  
      width_embeddings = (
          extractor._span_width_embedding.weight.data.numpy()
      )
      widths_minus_one = indices[..., 1] - indices[..., 0]
      for element in range(indices.size(0)):
          for span in range(indices.size(1)):
              width = widths_minus_one[element, span].item()
              width_embedding = span_representations[
                  element, span, input_dim:
              ]
              numpy.testing.assert_array_almost_equal(
                  width_embedding.data.numpy(), width_embeddings[width]
              )
  
file_path: allennlp/tests/modules/span_extractors/self_attentive_span_extractor_test.py
imports: import numpy
  import torch
  from allennlp.modules.span_extractors import SpanExtractor, SelfAttentiveSpanExtractor
  from allennlp.common.params import Params
label_desc: Use image node_id 3 for calling the TestSelfAttentiveSpanExtractor obj's underlying member method code with example usage: obj.test_widths_are_embedded_correctly() without return types