class_docstr: The model which defines heads in syntax tree and dependencies for text tokens.
  Text token ids are fed into Transformer encoder, hidden states are passed into dense layers followed by
  two biaffine layers (first for prediction of pairwise probabilities of a token to be the head for other token,
  second - for prediction of syntax dependency of a token).
class_docstr_tok: ["The","model","which","defines","heads","in","syntax","tree","and","dependencies","for","text","tokens",".","Text","token","ids","are","fed","into","Transformer","encoder",",","hidden","states","are","passed","into","dense","layers","followed","by","two","biaffine","layers","(","first","for","prediction","of","pairwise","probabilities","of","a","token","to","be","the","head","for","other","token",",","second","-","for","prediction","of","syntax","dependency","of","a","token",")","."]
code: def __init__(
      self,
      n_deps: int,
      pretrained_bert: str,
      encoder_layer_ids: List[int] = (-1,),
      bert_config_file: Optional[str] = None,
      attention_probs_keep_prob: Optional[float] = None,
      hidden_keep_prob: Optional[float] = None,
      state_size: int = 256,
      device: str = "gpu",
  ):
      super().__init__()
  
      self.device = torch.device(
          "cuda"
          if torch.cuda.is_available() and device == "gpu"
          else "cpu"
      )
      self.n_deps = n_deps
      self.encoder_layer_ids = encoder_layer_ids
      self.state_size = state_size
      if pretrained_bert:
          logger.debug(f"From pretrained {pretrained_bert}.")
          config = AutoConfig.from_pretrained(
              pretrained_bert,
              output_attentions=False,
              output_hidden_states=False,
          )
          self.encoder = AutoModel.from_pretrained(
              pretrained_bert, config=config
          )
  
      elif bert_config_file and Path(bert_config_file).is_file():
          bert_config = AutoConfig.from_json_file(
              str(expand_path(bert_config_file))
          )
          if attention_probs_keep_prob is not None:
              bert_config.attention_probs_dropout_prob = (
                  1.0 - attention_probs_keep_prob
              )
          if hidden_keep_prob is not None:
              bert_config.hidden_dropout_prob = 1.0 - hidden_keep_prob
          self.encoder = AutoModel(config=bert_config)
      else:
          raise ConfigError("No pre-trained BERT model is given.")
  
      self.head_embs1 = torch.nn.Linear(config.hidden_size, state_size)
      self.dep_embs1 = torch.nn.Linear(config.hidden_size, state_size)
      self.head_embs2 = torch.nn.Linear(config.hidden_size, state_size)
      self.dep_embs2 = torch.nn.Linear(config.hidden_size, state_size)
      self.zero_emb1 = torch.nn.Parameter(
          torch.randn(
              state_size,
          ),
          requires_grad=True,
      )
      self.zero_emb2 = torch.nn.Parameter(
          torch.randn(
              state_size,
          ),
          requires_grad=True,
      )
      self.dropout = torch.nn.Dropout(config.hidden_dropout_prob)
      self.biaf_head = Biaffine(state_size, state_size, 1)
      self.biaf_dep = Biaffine(state_size, state_size, n_deps)
  
imports: import math
  from logging import getLogger
  from pathlib import Path
  from typing import List, Dict, Union, Optional, Tuple
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from transformers import AutoConfig, AutoModel
  from deeppavlov.core.commands.utils import expand_path
  from deeppavlov.core.common.errors import ConfigError
  from deeppavlov.core.common.registry import register
  from deeppavlov.core.models.torch_model import TorchModel
  from deeppavlov.models.torch_bert.torch_transformers_sequence_tagger import token_from_subtoken
label_desc: Use image node_id 1 to create a new SyntaxParserNetwork object from inherited base classes: torch.nn with example: obj = SyntaxParserNetwork(n_deps, pretrained_bert, encoder_layer_ids, bert_config_file, attention_probs_keep_prob, hidden_keep_prob, state_size, device)