code: def test_embed_actions_works_with_batched_and_padded_input(self):
      params = Params.from_file(self.param_file)
      model = Model.from_params(
          vocab=self.vocab, params=params["model"]
      )
      action_embedding_weights = model._action_embedder.weight
      rule1 = model.vocab.get_token_from_index(1, "rule_labels")
      rule1_tensor = torch.LongTensor([1])
      rule2 = model.vocab.get_token_from_index(2, "rule_labels")
      rule2_tensor = torch.LongTensor([2])
      rule3 = model.vocab.get_token_from_index(3, "rule_labels")
      rule3_tensor = torch.LongTensor([3])
      actions = [
          [
              (rule1, True, rule1_tensor),
              (rule2, True, rule2_tensor),
              # This one is padding; the tensors shouldn't matter here.
              ("", False, None),
          ],
          [
              (rule3, True, rule3_tensor),
              ("instance_action", False, None),
              (rule1, True, rule1_tensor),
          ],
      ]
  
      embedded_actions, _, _, action_indices = model._embed_actions(
          actions
      )
      assert action_indices[(0, 0)] == action_indices[(1, 2)]
      assert action_indices[(1, 1)] == -1
      assert len(set(action_indices.values())) == 4
  
      # Now we'll go through all three unique actions and make sure the embedding is as we expect.
      action_embedding = embedded_actions[action_indices[(0, 0)]]
      expected_action_embedding = action_embedding_weights[
          action_indices[(0, 0)]
      ]
      assert_almost_equal(
          action_embedding.cpu().data.numpy(),
          expected_action_embedding.cpu().data.numpy(),
      )
  
      action_embedding = embedded_actions[action_indices[(0, 1)]]
      expected_action_embedding = action_embedding_weights[
          action_indices[(0, 1)]
      ]
      assert_almost_equal(
          action_embedding.cpu().data.numpy(),
          expected_action_embedding.cpu().data.numpy(),
      )
  
      action_embedding = embedded_actions[action_indices[(1, 0)]]
      expected_action_embedding = action_embedding_weights[
          action_indices[(1, 0)]
      ]
      assert_almost_equal(
          action_embedding.cpu().data.numpy(),
          expected_action_embedding.cpu().data.numpy(),
      )
  
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 10 for calling the WikiTablesMmlSemanticParserTest obj's underlying member method code with example usage: obj.test_embed_actions_works_with_batched_and_padded_input() without return types