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: Initialize the model
  
  Args:
  ablation : AblationParams
      Features/RNNs to use
  constraints : RNNGConstraints
      Constraints to use when computing valid actions
  lstm_num_layers : int
      number of layers in the LSTMs
  lstm_dim : int
      size of LSTM
  max_open_NT : int
      number of maximum open non-terminals allowed on the stack.
      After that, the only valid actions are SHIFT and REDUCE
  dropout : float
      dropout parameter
  beam_size : int
      beam size for beam search; run only during inference
  top_k : int
      top k results from beam search
  actions_vocab : Vocab (right now torchtext.vocab.Vocab)
      dictionary of actions
  shift_idx : int
      index of shift action
  reduce_idx : int
      index of reduce action
  ignore_subNTs_roots : List[int]
      for these top non-terminals, ignore loss for all subsequent actions
  valid_NT_idxs : List[int]
      indices of all non-terminals
  valid_IN_idxs : List[int]
      indices of intent non-terminals
  valid_SL_idxs : List[int]
      indices of slot non-terminals
  embedding : EmbeddingList
      embeddings for the tokens
  p_compositional : CompositionFunction
      Composition function to use to get embedding of a sub-tree
  
  
  Returns:
  None
code: def __init__(
      self,
      ablation: Config.AblationParams,
      constraints: Config.RNNGConstraints,
      lstm_num_layers: int,
      lstm_dim: int,
      max_open_NT: int,
      dropout: float,
      actions_vocab,
      shift_idx: int,
      reduce_idx: int,
      ignore_subNTs_roots: List[int],
      valid_NT_idxs: List[int],
      valid_IN_idxs: List[int],
      valid_SL_idxs: List[int],
      embedding: EmbeddingList,
      p_compositional,
  ) -> None:
      """
      Initialize the model
  
      Args:
      ablation : AblationParams
          Features/RNNs to use
      constraints : RNNGConstraints
          Constraints to use when computing valid actions
      lstm_num_layers : int
          number of layers in the LSTMs
      lstm_dim : int
          size of LSTM
      max_open_NT : int
          number of maximum open non-terminals allowed on the stack.
          After that, the only valid actions are SHIFT and REDUCE
      dropout : float
          dropout parameter
      beam_size : int
          beam size for beam search; run only during inference
      top_k : int
          top k results from beam search
      actions_vocab : Vocab (right now torchtext.vocab.Vocab)
          dictionary of actions
      shift_idx : int
          index of shift action
      reduce_idx : int
          index of reduce action
      ignore_subNTs_roots : List[int]
          for these top non-terminals, ignore loss for all subsequent actions
      valid_NT_idxs : List[int]
          indices of all non-terminals
      valid_IN_idxs : List[int]
          indices of intent non-terminals
      valid_SL_idxs : List[int]
          indices of slot non-terminals
      embedding : EmbeddingList
          embeddings for the tokens
      p_compositional : CompositionFunction
          Composition function to use to get embedding of a sub-tree
  
  
      Returns:
      None
  
  
      """
  
      super().__init__()
  
      self.embedding = embedding
      # self.embedding.config: FeatureConfig object cannot be pickled but,
      # we require the model to be pickled for passing from one worker process
      # for Hogwild training. Hence, setting the config to None
      self.embedding.config = None
  
      self.p_compositional = p_compositional
      self.ablation_use_last_open_NT_feature = (
          ablation.use_last_open_NT_feature
      )
      self.ablation_use_buffer = ablation.use_buffer
      self.ablation_use_stack = ablation.use_stack
      self.ablation_use_action = ablation.use_action
  
      self.constraints_intent_slot_nesting = (
          constraints.intent_slot_nesting
      )
      self.constraints_no_slots_inside_unsupported = (
          constraints.no_slots_inside_unsupported
      )
      self.constraints_ignore_loss_for_unsupported = (
          constraints.ignore_loss_for_unsupported
      )
  
      self.lstm_num_layers = lstm_num_layers
      self.lstm_dim = lstm_dim
      self.max_open_NT = max_open_NT
      self.actions_vocab = actions_vocab
      self.shift_idx = shift_idx
      self.reduce_idx = reduce_idx
      self.ignore_subNTs_roots = ignore_subNTs_roots
      self.valid_NT_idxs = valid_NT_idxs
      self.valid_IN_idxs = valid_IN_idxs
      self.valid_SL_idxs = valid_SL_idxs
  
      num_actions = len(actions_vocab)
      lstm_count = (
          ablation.use_buffer + ablation.use_stack + ablation.use_action
      )
      if lstm_count == 0:
          raise ValueError("Need at least one of the LSTMs to be true")
  
      self.action_linear = nn.Sequential(
          nn.Linear(
              lstm_count * lstm_dim
              + num_actions * ablation.use_last_open_NT_feature,
              lstm_dim,
          ),
          nn.ReLU(),
          nn.Linear(lstm_dim, num_actions),
      )
      self.dropout_layer = nn.Dropout(p=dropout)
      self.buff_rnn = nn.LSTM(
          embedding.embedding_dim,
          lstm_dim,
          num_layers=lstm_num_layers,
          dropout=dropout,
      )
      self.stack_rnn = nn.LSTM(
          lstm_dim,
          lstm_dim,
          num_layers=lstm_num_layers,
          dropout=dropout,
      )
      self.action_rnn = nn.LSTM(
          lstm_dim,
          lstm_dim,
          num_layers=lstm_num_layers,
          dropout=dropout,
      )
  
      self.actions_lookup = nn.Embedding(num_actions, lstm_dim)
      self.loss_func = nn.CrossEntropyLoss()
      log_class_usage(__class__)
  
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 2 to create a new RNNGParserBase object from inherited base classes: BaseModel with example: obj = RNNGParserBase(ablation, constraints, lstm_num_layers, lstm_dim, max_open_NT, dropout, actions_vocab, shift_idx, reduce_idx, ignore_subNTs_roots, valid_NT_idxs, valid_IN_idxs, valid_SL_idxs, embedding, p_compositional)