code: def test_get_linking_probabilities(self):
      worlds, num_entities = self.get_fake_worlds()
      # (batch_size, num_question_tokens, num_entities)
      linking_scores = [
          [[-2, 1, 0, -3, 2], [4, -1, 5, -3, 4]],
          [[0, 1, 8, 10, 10], [3, 2, -1, -2, 1]],
      ]
      linking_scores = torch.FloatTensor(linking_scores)
      question_mask = torch.LongTensor([[1, 1], [1, 0]])
      _, entity_type_dict = self.model._get_type_vector(
          worlds, num_entities, linking_scores
      )
  
      # (batch_size, num_question_tokens, num_entities)
      entity_probability = self.model._get_linking_probabilities(
          worlds, linking_scores, question_mask, entity_type_dict
      )
  
      # The following properties in entity_probability are tested for by true_probability:
      # (1) It has all 0.0 probabilities when there is no question token, as seen for the
      #     second word in the second batch.
      # (2) It has 0.0 probabilities when an entity is masked, as seen in the last two entities
      #     for the second batch instance.
      # (3) The probabilities for entities of the same type with the same question token should
      #     sum to at most 1, but not necessarily 1, because some probability mass goes to the
      #     null entity.  We have three entity types here, so each row should sum to at most 3,
      #     and that number will approach 3 as the unnormalized linking scores for each entity
      #     get higher.
      true_probability = [
          [
              [0.1192029, 0.5761169, 0.2119416, 0.0058998, 0.8756006],
              [0.9820138, 0.0024561, 0.9908675, 0.0008947, 0.9811352],
          ],
          [
              [0.5, 0.7310586, 0.9996647, 0.0, 0.0],
              [0.0, 0.0, 0.0, 0.0, 0.0],
          ],
      ]
      assert_almost_equal(
          entity_probability.detach().cpu().numpy(), true_probability
      )
  
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 8 for calling the WikiTablesMmlSemanticParserTest obj's underlying member method code with example usage: obj.test_get_linking_probabilities() without return types