class_docstr: The Recurrent Neural Network Grammar (RNNG) parser from
  Dyer et al.: https://arxiv.org/abs/1602.07776 and
  Gupta et al.: https://arxiv.org/abs/1810.07942d.
  RNNG is a neural constituency parsing algorithm that
  explicitly models compositional structure of a sentence.
  It is able to learn about hierarchical relationship among the words and
  phrases in a given sentence thereby learning the underlying tree structure.
  The paper proposes generative as well as discriminative approaches.
  In PyText we have implemented the discriminative approach for modeling
  intent slot models.
  It is a top-down shift-reduce parser than can output
  trees with non-terminals (intent and slot labels) and terminals (tokens)
docstr: Used for restricting the set of possible action predictions
  
  Args:
      state (ParserState): The state of the stack, buffer and action
  
  Returns:
      List[int] : indices of the valid actions
code: def valid_actions(self, state: ParserState) -> List[int]:
      """Used for restricting the set of possible action predictions
  
      Args:
          state (ParserState): The state of the stack, buffer and action
  
      Returns:
          List[int] : indices of the valid actions
  
      """
      valid_actions: List[int] = []
      is_open_NT = state.is_open_NT
      num_open_NT = state.num_open_NT
      stack = state.stack_stackrnn
      buffer = state.buffer_stackrnn
  
      # Can REDUCE if
      # 1. Top of multi-element stack is not an NT, and
      # 2. Two open NTs on stack, or buffer is empty
      if (
          is_open_NT and not is_open_NT[-1] and not len(is_open_NT) == 1
      ) and (num_open_NT >= 2 or len(buffer) == 0):
          assert len(stack) > 0
          valid_actions.append(self.reduce_idx)
  
      if len(buffer) > 0 and num_open_NT < self.max_open_NT:
          last_open_NT = None
          try:
              last_open_NT = stack.element_from_top(
                  is_open_NT[::-1].index(True)
              )
          except ValueError:
              pass
  
          if (
              not self.training
          ) or self.constraints_intent_slot_nesting:
              # if stack is empty or the last open NT is slot
              if (
                  not last_open_NT
              ) or last_open_NT.node in self.valid_SL_idxs:
                  valid_actions += self.valid_IN_idxs
              elif last_open_NT.node in self.valid_IN_idxs:
                  if (
                      self.constraints_no_slots_inside_unsupported
                      and state.found_unsupported
                  ):
                      pass
                  else:
                      valid_actions += self.valid_SL_idxs
          else:
              valid_actions += self.valid_IN_idxs
              valid_actions += self.valid_SL_idxs
  
      elif (not self.training) and num_open_NT >= self.max_open_NT:
          print(
              "not predicting NT because buffer len is "
              + str(len(buffer))
              + " and num open NTs is "
              + str(num_open_NT)
          )
  
      # Can SHIFT if
      # 1. Buffer is non-empty, and
      # 2. At least one open NT on stack
      if len(buffer) > 0 and num_open_NT >= 1:
          valid_actions.append(self.shift_idx)
  
      return valid_actions
  
imports: from enum import Enum
  from typing import Dict, List, Optional, Tuple
  import numpy
  import pytext.utils.cuda
  import torch
  import torch.nn
  import torch.nn.functional
  from pytext.common.constants import Stage
  from pytext.config import ConfigBase
  from pytext.config.component import ComponentType
  from pytext.data import CommonMetadata
  from pytext.data.tensorizers import AnnotationNumberizer, Tensorizer, TokenTensorizer
  from pytext.data.utils import pad_and_tensorize
  from pytext.models import BaseModel, Model
  from pytext.models.embeddings import EmbeddingList
  from pytext.models.embeddings.word_embedding import WordEmbedding
  from pytext.models.module import create_module
  from pytext.models.representations.bilstm import BiLSTM
  from pytext.models.semantic_parsers.rnng.rnng_data_structures import CompositionalNN, CompositionalSummationNN, Element, ParserState
  from pytext.utils.usage import log_class_usage
label_desc: Use image node_id 4 for calling the RNNGParserBase obj's underlying member method code with example usage: obj.valid_actions(state) and returns: valid_actions