class_docstr: A ``WikiTablesSemanticParser`` is a :class:`Model` which takes as input a table and a question,
  and produces a logical form that answers the question when executed over the table.  The
  logical form is generated by a `type-constrained`, `transition-based` parser. This is an
  abstract class that defines most of the functionality related to the transition-based parser. It
  does not contain the implementation for actually training the parser. You may want to train it
  using a learning-to-search algorithm, in which case you will want to use
  ``WikiTablesErmSemanticParser``, or if you have a set of approximate logical forms that give the
  correct denotation, you will want to use ``WikiTablesMmlSemanticParser``.
  
  Parameters
  ----------
  vocab : ``Vocabulary``
  question_embedder : ``TextFieldEmbedder``
      Embedder for questions.
  action_embedding_dim : ``int``
      Dimension to use for action embeddings.
  encoder : ``Seq2SeqEncoder``
      The encoder to use for the input question.
  entity_encoder : ``Seq2VecEncoder``
      The encoder to used for averaging the words of an entity.
  max_decoding_steps : ``int``
      When we're decoding with a beam search, what's the maximum number of steps we should take?
      This only applies at evaluation time, not during training.
  use_neighbor_similarity_for_linking : ``bool``, optional (default=False)
      If ``True``, we will compute a max similarity between a question token and the `neighbors`
      of an entity as a component of the linking scores.  This is meant to capture the same kind
      of information as the ``related_column`` feature.
  dropout : ``float``, optional (default=0)
      If greater than 0, we will apply dropout with this probability after all encoders (pytorch
      LSTMs do not apply dropout to their last layer).
  num_linking_features : ``int``, optional (default=10)
      We need to construct a parameter vector for the linking features, so we need to know how
      many there are.  The default of 8 here matches the default in the ``KnowledgeGraphField``,
      which is to use all eight defined features. If this is 0, another term will be added to the
      linking score. This term contains the maximum similarity value from the entity's neighbors
      and the question.
  rule_namespace : ``str``, optional (default=rule_labels)
      The vocabulary namespace to use for production rules.  The default corresponds to the
      default used in the dataset reader, so you likely don't need to modify this.
  tables_directory : ``str``, optional (default=/wikitables/)
      The directory to find tables when evaluating logical forms.  We rely on a call to SEMPRE to
      evaluate logical forms, and SEMPRE needs to read the table from disk itself.  This tells
      SEMPRE where to find the tables.
docstr: Given all of the possible actions for all batch instances, produce an embedding for them.
  There will be significant overlap in this list, as the production rules from the grammar
  are shared across all batch instances.  Our returned tensor has an embedding for each
  `unique` action, so we also need to return a mapping from the original ``(batch_index,
  action_index)`` to our new ``global_action_index``, so that we can get the right action
  embedding during decoding.
  
  Returns
  -------
  action_embeddings : ``torch.Tensor``
      Has shape ``(num_unique_actions, action_embedding_dim)``.
  output_action_embeddings : ``torch.Tensor``
      Has shape ``(num_unique_actions, action_embedding_dim)``.
  action_biases : ``torch.Tensor``
      Has shape ``(num_unique_actions, 1)``.
  action_map : ``Dict[Tuple[int, int], int]``
      Maps ``(batch_index, action_index)`` in the input action list to ``action_index`` in
      the ``action_embeddings`` tensor.  All non-embeddable actions get mapped to `-1` here.
docstr_tok: ["Given","all","of","the","possible","actions","for","all","batch","instances",",","produce","an","embedding","for","them",".","There","will","be","significant","overlap","in","this","list",",","as","the","production","rules","from","the","grammar","are","shared","across","all","batch","instances",".","Our","returned","tensor","has","an","embedding","for","each","`","unique","`","action",",","so","we","also","need","to","return","a","mapping","from","the","original","``","(","batch_index",",","action_index",")","``","to","our","new","``","global_action_index","``",",","so","that","we","can","get","the","right","action","embedding","during","decoding",".","Returns","--","--","--","-","action_embeddings",":","``","torch.Tensor","``","Has","shape","``","(","num_unique_actions",",","action_embedding_dim",")","``",".","output_action_embeddings",":","``","torch.Tensor","``","Has","shape","``","(","num_unique_actions",",","action_embedding_dim",")","``",".","action_biases",":","``","torch.Tensor","``","Has","shape","``","(","num_unique_actions",",","1",")","``",".","action_map",":","``","Dict","[","Tuple","[","int",",","int","]",",","int","]","``","Maps","``","(","batch_index",",","action_index",")","``","in","the","input","action","list","to","``","action_index","``","in","the","``","action_embeddings","``","tensor",".","All","non-embeddable","actions","get","mapped","to","`","-1","`","here","."]
code: def _embed_actions(self, actions):
      """
      Given all of the possible actions for all batch instances, produce an embedding for them.
      There will be significant overlap in this list, as the production rules from the grammar
      are shared across all batch instances.  Our returned tensor has an embedding for each
      `unique` action, so we also need to return a mapping from the original ``(batch_index,
      action_index)`` to our new ``global_action_index``, so that we can get the right action
      embedding during decoding.
  
      Returns
      -------
      action_embeddings : ``torch.Tensor``
          Has shape ``(num_unique_actions, action_embedding_dim)``.
      output_action_embeddings : ``torch.Tensor``
          Has shape ``(num_unique_actions, action_embedding_dim)``.
      action_biases : ``torch.Tensor``
          Has shape ``(num_unique_actions, 1)``.
      action_map : ``Dict[Tuple[int, int], int]``
          Maps ``(batch_index, action_index)`` in the input action list to ``action_index`` in
          the ``action_embeddings`` tensor.  All non-embeddable actions get mapped to `-1` here.
      """
      # TODO(mattg): This whole action pipeline might be a whole lot more complicated than it
      # needs to be.  We used to embed actions differently (using some crazy ideas about
      # embedding the LHS and RHS separately); we could probably get away with simplifying things
      # further now that we're just doing a simple embedding for global actions.  But I'm leaving
      # it like this for now to have a minimal change to go from the LHS/RHS embedding to a
      # single action embedding.
      embedded_actions = self._action_embedder.weight
      output_embedded_actions = self._output_action_embedder.weight
      action_biases = self._action_biases.weight
  
      # Now we just need to make a map from `(batch_index, action_index)` to
      # `global_action_index`.  global_action_ids has the list of all unique actions; here we're
      # going over all of the actions for each batch instance so we can map them to the global
      # action ids.
      action_vocab = self.vocab.get_token_to_index_vocabulary(
          self._rule_namespace
      )
      action_map = {}
      for batch_index, instance_actions in enumerate(actions):
          for action_index, action in enumerate(instance_actions):
              if not action[0]:
                  # This rule is padding.
                  continue
              global_action_id = action_vocab.get(action[0], -1)
              action_map[(batch_index, action_index)] = global_action_id
      return (
          embedded_actions,
          output_embedded_actions,
          action_biases,
          action_map,
      )
  
imports: from __future__ import absolute_import
  import torch
  from allennlp.common.checks import check_dimensions_match
  from allennlp.common.util import pad_sequence_to_length
  from allennlp.data import Vocabulary
  from allennlp.data.fields.production_rule_field import ProductionRuleArray
  from allennlp.models.model import Model
  from allennlp.models.semantic_parsing.wikitables.wikitables_decoder_state import WikiTablesDecoderState
  from allennlp.modules import Embedding, Seq2SeqEncoder, Seq2VecEncoder, TextFieldEmbedder, TimeDistributed
  from allennlp.modules.seq2vec_encoders import BagOfEmbeddingsEncoder
  from allennlp.nn import util
  from allennlp.nn.decoding import GrammarState, RnnState, ChecklistState
  from allennlp.semparse.type_declarations import type_declaration
  from allennlp.semparse.type_declarations.type_declaration import START_SYMBOL
  from allennlp.semparse.worlds import WikiTablesWorld
  from allennlp.training.metrics import Average, WikiTablesAccuracy
label_desc: Use image node_id 9 for calling the WikiTablesSemanticParser obj's underlying member method code with example usage: obj._embed_actions(actions) and returns: embedded_actions,  output_embedded_actions,  action_biases,  action_map