code: def test_as_tensor_produces_correct_output(self):
      self.field.index(self.vocab)
      padding_lengths = self.field.get_padding_lengths()
      padding_lengths["num_utterance_tokens"] += 1
      padding_lengths["num_entities"] += 1
      tensor_dict = self.field.as_tensor(padding_lengths)
      assert list(tensor_dict.keys()) == set(["text", "linking"])
      expected_text_tensor = [
          [self.negative_one_index, 0, 0],
          [self.zero_index, 0, 0],
          [self.one_index, 0, 0],
          [self.edirne_index, 0, 0],
          [self.lake_index, self.gala_index, 0],
          [self.mersin_index, 0, 0],
          [self.paradeniz_index, 0, 0],
          [self.location_index, self.in_index, self.english_index],
          [self.name_index, self.in_index, self.english_index],
          [0, 0, 0],
      ]
      assert_almost_equal(
          tensor_dict["text"]["tokens"].detach().cpu().numpy(),
          expected_text_tensor,
      )
  
      linking_tensor = tensor_dict["linking"].detach().cpu().numpy()
      expected_linking_tensor = [
          [
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],  # -1, "where"
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],  # -1, "is"
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],  # -1, "mersin"
              [0, 0, 0, 0, 0, -1, 0, 0, 0, 0],
          ],  # -1, "?"
          [
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],  # 0, "where"
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],  # 0, "is"
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],  # 0, "mersin"
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
          ],  # 0, "?"
          [
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],  # 1, "where"
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],  # 1, "is"
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],  # 1, "mersin"
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
          ],  # 1, "?"
          [
              [
                  0,
                  0,
                  0,
                  0,
                  0,
                  0.2,
                  0,
                  0,
                  0,
                  0,
              ],  # fb:cell.edirne, "where"
              [0, 0, 0, 0, 0, -1.5, 0, 0, 0, 0],  # fb:cell.edirne, "is"
              [
                  0,
                  0,
                  0,
                  0,
                  0,
                  0.1666,
                  0,
                  0,
                  0,
                  0,
              ],  # fb:cell.edirne, "mersin"
              [0, 0, 0, 0, 0, -5, 0, 0, 0, 0],  # fb:cell.edirne, "?"
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
          ],  # fb:cell.edirne, padding
          [
              [
                  0,
                  0,
                  0,
                  0,
                  0,
                  -0.6,
                  0,
                  0,
                  0,
                  0,
              ],  # fb:cell.lake_gala, "where"
              [
                  0,
                  0,
                  0,
                  0,
                  0,
                  -3.5,
                  0,
                  0,
                  0,
                  0,
              ],  # fb:cell.lake_gala, "is"
              [
                  0,
                  0,
                  0,
                  0,
                  0,
                  -0.3333,
                  0,
                  0,
                  0,
                  0,
              ],  # fb:cell.lake_gala, "mersin"
              [0, 0, 0, 0, 0, -8, 0, 0, 0, 0],  # fb:cell.lake_gala, "?"
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
          ],  # fb:cell.lake_gala, padding
          [
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],  # fb:cell.mersin, "where"
              [0, 0, 0, 0, 0, -1.5, 0, 0, 0, 0],  # fb:cell.mersin, "is"
              [
                  0,
                  1,
                  1,
                  1,
                  1,
                  1,
                  0,
                  0,
                  1,
                  1,
              ],  # fb:cell.mersin, "mersin"
              [0, 0, 0, 0, 0, -5, 0, 0, 0, 0],  # fb:cell.mersin, "?"
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
          ],  # fb:cell.mersin, padding
          [
              [
                  0,
                  0,
                  0,
                  0,
                  0,
                  -0.6,
                  0,
                  0,
                  0,
                  0,
              ],  # fb:cell.paradeniz, "where"
              [
                  0,
                  0,
                  0,
                  0,
                  0,
                  -3,
                  0,
                  0,
                  0,
                  0,
              ],  # fb:cell.paradeniz, "is"
              [
                  0,
                  0,
                  0,
                  0,
                  0,
                  -0.1666,
                  0,
                  0,
                  0,
                  0,
              ],  # fb:cell.paradeniz, "mersin"
              [0, 0, 0, 0, 0, -8, 0, 0, 0, 0],  # fb:cell.paradeniz, "?"
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
          ],  # fb:cell.paradeniz, padding
          [
              [
                  0,
                  0,
                  0,
                  0,
                  0,
                  -2.6,
                  0,
                  0,
                  0,
                  0,
              ],  # fb:row.row.name_in_english, "where"
              [
                  0,
                  0,
                  0,
                  0,
                  0,
                  -7.5,
                  0,
                  0,
                  0,
                  0,
              ],  # fb:row.row.name_in_english, "is"
              [
                  0,
                  0,
                  0,
                  0,
                  0,
                  -1.8333,
                  1,
                  1,
                  0,
                  0,
              ],  # fb:row.row.name_in_english, "mersin"
              [
                  0,
                  0,
                  0,
                  0,
                  0,
                  -18,
                  0,
                  0,
                  0,
                  0,
              ],  # fb:row.row.name_in_english, "?"
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
          ],  # fb:row.row.name_in_english, padding
          [
              [
                  0,
                  0,
                  0,
                  0,
                  0,
                  -1.6,
                  0,
                  0,
                  0,
                  0,
              ],  # fb:row.row.location_in_english, "where"
              [
                  0,
                  0,
                  0,
                  0,
                  0,
                  -5.5,
                  0,
                  0,
                  0,
                  0,
              ],  # fb:row.row.location_in_english, "is"
              [
                  0,
                  0,
                  0,
                  0,
                  0,
                  -1,
                  0,
                  0,
                  0,
                  0,
              ],  # fb:row.row.location_in_english, "mersin"
              [
                  0,
                  0,
                  0,
                  0,
                  0,
                  -14,
                  0,
                  0,
                  0,
                  0,
              ],  # fb:row.row.location_in_english, "?"
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
          ],  # fb:row.row.location_in_english, padding
          [
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],  # padding, "where"
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],  # padding, "is"
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],  # padding, "mersin"
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],  # padding, "?"
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
          ],
      ]  # padding, padding
      for entity_index, entity_features in enumerate(
          expected_linking_tensor
      ):
          for question_index, feature_vector in enumerate(
              entity_features
          ):
              assert_almost_equal(
                  linking_tensor[entity_index, question_index],
                  feature_vector,
                  decimal=4,
                  err_msg="{entity_index} {question_index}",
              )
  
imports: from __future__ import division
  from __future__ import with_statement
  from __future__ import absolute_import
  from collections import defaultdict
  import pytest
  from numpy.testing import assert_almost_equal
  import torch
  from allennlp.common.testing import AllenNlpTestCase
  from allennlp.data import Vocabulary
  from allennlp.data.fields import KnowledgeGraphField
  from allennlp.data.token_indexers import SingleIdTokenIndexer, TokenCharactersIndexer
  from allennlp.data.tokenizers import WordTokenizer
  from allennlp.data.tokenizers.word_splitter import SpacyWordSplitter
  from allennlp.semparse.contexts import TableQuestionKnowledgeGraph
label_desc: Use image node_id 6 for calling the KnowledgeGraphFieldTest obj's underlying member method code with example usage: obj.test_as_tensor_produces_correct_output() without return types