code: def setUp(self):
      super(WikiTablesDecoderStepTest, self).setUp()
  
      batch_indices = [0, 1, 0]
      action_history = [[1], [3, 4], []]
      score = [torch.FloatTensor([x]) for x in [0.1, 1.1, 2.2]]
      hidden_state = torch.FloatTensor(
          [[i, i] for i in range(len(batch_indices))]
      )
      memory_cell = torch.FloatTensor(
          [[i, i] for i in range(len(batch_indices))]
      )
      previous_action_embedding = torch.FloatTensor(
          [[i, i] for i in range(len(batch_indices))]
      )
      attended_question = torch.FloatTensor(
          [[i, i] for i in range(len(batch_indices))]
      )
      grammar_state = [
          GrammarState(["e"], {}, {}, {}, is_nonterminal)
          for _ in batch_indices
      ]
      self.encoder_outputs = torch.FloatTensor([[1, 2], [3, 4], [5, 6]])
      self.encoder_output_mask = torch.FloatTensor(
          [[1, 1], [1, 0], [1, 1]]
      )
      self.action_embeddings = torch.FloatTensor(
          [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]
      )
      self.output_action_embeddings = torch.FloatTensor(
          [[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5]]
      )
      self.action_biases = torch.FloatTensor(
          [[0], [1], [2], [3], [4], [5]]
      )
      self.action_indices = {
          (0, 0): 1,
          (0, 1): 0,
          (0, 2): 2,
          (0, 3): 3,
          (0, 4): 5,
          (1, 0): 4,
          (1, 1): 0,
          (1, 2): 2,
          (1, 3): 3,
      }
      self.possible_actions = [
          [
              ("e -> ", False, None),
              ("e -> g", True, None),
              ("e -> h", True, None),
              ("e -> i", True, None),
              ("e -> j", True, None),
          ],
          [
              ("e -> q", True, None),
              ("e -> g", True, None),
              ("e -> h", True, None),
              ("e -> i", True, None),
          ],
      ]
  
      # (batch_size, num_entities, num_question_tokens) = (2, 5, 3)
      linking_scores = torch.Tensor(
          [
              [
                  [0.1, 0.2, 0.3],
                  [0.4, 0.5, 0.6],
                  [0.7, 0.8, 0.9],
                  [1.0, 1.1, 1.2],
                  [1.3, 1.4, 1.5],
              ],
              [
                  [-0.1, -0.2, -0.3],
                  [-0.4, -0.5, -0.6],
                  [-0.7, -0.8, -0.9],
                  [-1.0, -1.1, -1.2],
                  [-1.3, -1.4, -1.5],
              ],
          ]
      )
      flattened_linking_scores = linking_scores.view(2 * 5, 3)
  
      # Maps (batch_index, action_index) to indices into the flattened linking score tensor,
      # which has shae (batch_size * num_entities, num_question_tokens).
      actions_to_entities = {
          (0, 0): 0,
          (0, 1): 1,
          (0, 2): 2,
          (0, 6): 3,
          (1, 3): 6,
          (1, 4): 7,
          (1, 5): 8,
      }
      entity_types = {
          0: 0,
          1: 2,
          2: 1,
          3: 0,
          4: 0,
          5: 1,
          6: 0,
          7: 1,
          8: 2,
      }
      rnn_state = []
      for i in range(len(batch_indices)):
          rnn_state.append(
              RnnState(
                  hidden_state[i],
                  memory_cell[i],
                  previous_action_embedding[i],
                  attended_question[i],
                  self.encoder_outputs,
                  self.encoder_output_mask,
              )
          )
      self.state = WikiTablesDecoderState(
          batch_indices=batch_indices,
          action_history=action_history,
          score=score,
          rnn_state=rnn_state,
          grammar_state=grammar_state,
          action_embeddings=self.action_embeddings,
          output_action_embeddings=self.output_action_embeddings,
          action_biases=self.action_biases,
          action_indices=self.action_indices,
          possible_actions=self.possible_actions,
          flattened_linking_scores=flattened_linking_scores,
          actions_to_entities=actions_to_entities,
          entity_types=entity_types,
      )
  
file_path: magnitude/pymagnitude/third_party/allennlp/tests/models/semantic_parsing/wikitables/wikitables_decoder_step_test.py
imports: from __future__ import absolute_import
  from numpy.testing import assert_almost_equal
  import torch
  from allennlp.common import Params
  from allennlp.common.testing import AllenNlpTestCase
  from allennlp.models.semantic_parsing.wikitables.wikitables_decoder_state import WikiTablesDecoderState
  from allennlp.models.semantic_parsing.wikitables.wikitables_decoder_step import WikiTablesDecoderStep
  from allennlp.modules import SimilarityFunction
  from allennlp.nn.decoding import GrammarState, RnnState
  from allennlp.semparse.type_declarations.type_declaration import is_nonterminal
label_desc: Use image node_id 1 for calling the WikiTablesDecoderStepTest obj's underlying member method code with example usage: obj.setUp() without return types