class_docstr: This class implements beam search over transition sequences given an initial ``DecoderState``,
  a ``DecoderStep``, and a list of allowed transition sequences.  We will do a beam search `over
  the list of allowed sequences` and return the highest scoring states found by the beam.  This
  is only actually a `beam search` if your beam size is smaller than the list of allowed
  transition sequences; otherwise, we are just scoring and sorting the sequences using a prefix
  tree.
  
  The initial ``DecoderState`` is assumed to be `batched`.  The value we return from the search
  is a dictionary from batch indices to ranked finished states.
  
  IMPORTANT: We assume that the ``DecoderStep`` that you are using returns possible next states
  in sorted order, so we do not do an additional sort inside of
  ``ConstrainedBeamSearch.search()``.  If you're implementing your own ``DecoderStep``, you must
  ensure that you've sorted the states that you return.
  
  Parameters
  ----------
  beam_size : ``int``
      The beam size to use.
  allowed_sequences : ``torch.Tensor``
      A ``(batch_size, num_sequences, sequence_length)`` tensor containing the transition
      sequences that we will search in.  The values in this tensor must match whatever the
      ``DecoderState`` keeps in its ``action_history`` variable (typically this is action
      indices).
  allowed_sequence_mask : ``torch.Tensor``
      A ``(batch_size, num_sequences, sequence_length)`` tensor indicating whether each entry in
      the ``allowed_sequences`` tensor is padding.  The allowed sequences could be padded both on
      the ``num_sequences`` dimension and the ``sequence_length`` dimension.
code: def __init__(
      self, beam_size, allowed_sequences, allowed_sequence_mask
  ):
      self._beam_size = beam_size
      self._allowed_transitions = util.construct_prefix_tree(
          allowed_sequences, allowed_sequence_mask
      )
  
file_path: magnitude/pymagnitude/third_party/allennlp/nn/decoding/constrained_beam_search.py
imports: from __future__ import absolute_import
  from collections import defaultdict
  import torch
  from allennlp.nn.decoding import util
  from allennlp.nn.decoding.decoder_step import DecoderStep
  from allennlp.nn.decoding.decoder_state import DecoderState
label_desc: Use image node_id 1 to create a new ConstrainedBeamSearch object from inherited base classes: object with example: obj = ConstrainedBeamSearch(beam_size, allowed_sequences, allowed_sequence_mask)