code: def test_map_entity_productions(self):
      # (batch_size, num_entities, num_question_tokens) = (3, 4, 5)
      linking_scores = torch.rand(3, 4, 5)
      # Because we only need a small piece of the WikiTablesWorld and TableKnowledgeGraph, we'll
      # just use some namedtuples to fake the part of the API that we need, instead of going to
      # the trouble of constructing the full objects.
      FakeTable = namedtuple("FakeTable", ["entities"])
      FakeWorld = namedtuple("FakeWorld", ["table_graph"])
      entities = [
          [
              "fb:cell.2010",
              "fb:cell.2011",
              "fb:row.row.year",
              "fb:row.row.year2",
          ],
          ["fb:cell.2012", "fb:cell.2013", "fb:row.row.year"],
          ["fb:cell.2010", "fb:row.row.year"],
      ]
      worlds = [
          FakeWorld(FakeTable(entity_list)) for entity_list in entities
      ]
      # The tensors here for the global actions won't actually be read, so we're not constructing
      # them.
      # it.  Same with the RHS tensors.  NT* here is just saying "some non-terminal".
      actions = [
          [
              ("@START@ -> r", True, None),
              ("@START@ -> c", True, None),
              ("@START@ -> <c,r>", True, None),
              ("c -> fb:cell.2010", False, None),
              ("c -> fb:cell.2011", False, None),
              ("<c,r> -> fb:row.row.year", False, None),
              ("<c,r> -> fb:row.row.year2", False, None),
          ],
          [
              ("@START@ -> c", True, None),
              ("c -> fb:cell.2012", False, None),
              ("c -> fb:cell.2013", False, None),
              ("<c,r> -> fb:row.row.year", False, None),
          ],
          [
              ("@START@ -> c", True, None),
              ("c -> fb:cell.2010", False, None),
              ("<c,r> -> fb:row.row.year", False, None),
          ],
      ]
      (
          flattened_linking_scores,
          actions_to_entities,
      ) = WikiTablesMmlSemanticParser._map_entity_productions(
          linking_scores, worlds, actions
      )
      assert_almost_equal(
          flattened_linking_scores.detach().cpu().numpy(),
          linking_scores.view(3 * 4, 5).detach().cpu().numpy(),
      )
      assert actions_to_entities == {
          (0, 3): 0,
          (0, 4): 1,
          (0, 5): 2,
          (0, 6): 3,
          (1, 1): 4,
          (1, 2): 5,
          (1, 3): 6,
          (2, 1): 8,
          (2, 2): 9,
      }
  
imports: from __future__ import division
  from __future__ import absolute_import
  from collections import namedtuple
  import os
  import pytest
  from flaky import flaky
  from numpy.testing import assert_almost_equal
  import torch
  from allennlp.common import Params
  from allennlp.common.testing import ModelTestCase
  from allennlp.models import Model, WikiTablesMmlSemanticParser
  from allennlp.training.metrics.wikitables_accuracy import SEMPRE_ABBREVIATIONS_PATH, SEMPRE_GRAMMAR_PATH
label_desc: Use image node_id 11 for calling the WikiTablesMmlSemanticParserTest obj's underlying member method code with example usage: obj.test_map_entity_productions() without return types