class_docstr: The implementation of Biaffine Dependency Parser.
  
  References:
      - Timothy Dozat and Christopher D. Manning. 2017.
        `Deep Biaffine Attention for Neural Dependency Parsing`_.
  
  .. _Deep Biaffine Attention for Neural Dependency Parsing:
      https://openreview.net/forum?id=Hk95PK9le
class_docstr_tok: ["The","implementation","of","Biaffine","Dependency","Parser",".","References",":","-","Timothy","Dozat","and","Christopher","D.","Manning",".","2017",".","`","Deep","Biaffine","Attention","for","Neural","Dependency","Parsing","`","_",".","..","_Deep","Biaffine","Attention","for","Neural","Dependency","Parsing",":","https",":","\/\/openreview.net\/forum","?","id=Hk95PK9le"]
code: def __init__(
      self,
      n_words=None,
      pad_index=0,
      unk_index=1,
      n_feats=None,
      n_rels=None,
      feat="char",
      n_embed=50,
      n_feat_embed=100,
      n_char_embed=50,
      bert=None,
      n_bert_layers=4,
      embed_dropout=0.33,
      max_len=None,
      mix_dropout=0.0,
      embeddings=[],
      embed=False,
      n_lstm_hidden=400,
      n_lstm_layers=3,
      lstm_dropout=0.33,
      n_mlp_arc=500,
      n_mlp_rel=100,
      mlp_dropout=0.33,
      feat_pad_index=0,
      init_pre_train=False,
      transform=None,
  ):
      super(DependencyParser, self).__init__()
      self.embed = embed
      self.feat = feat
      self.embeddings = embeddings
      if len(self.embeddings) > 0:
          print(self.embeddings[0])
      self.args = {
          "n_words": n_words,
          "pad_index": pad_index,
          "unk_index": unk_index,
          "n_feats": n_feats,
          "n_rels": n_rels,
          "feat_pad_index": feat_pad_index,
          "feat": feat,
          "tree": False,
          "proj": False,
          "punct": False,
      }
  
      if init_pre_train:
          return
  
      # the embedding layer
      self.word_embed = nn.Embedding(
          num_embeddings=n_words, embedding_dim=n_embed
      )
      if feat == "char":
          self.feat_embed = CharLSTM(
              n_chars=n_feats,
              n_embed=n_char_embed,
              n_out=n_feat_embed,
              pad_index=feat_pad_index,
          )
      elif feat == "bert":
          self.feat_embed = BertEmbedding(
              model=bert,
              n_layers=n_bert_layers,
              n_out=n_feat_embed,
              pad_index=feat_pad_index,
              max_len=max_len,
              dropout=mix_dropout,
          )
          self.n_feat_embed = self.feat_embed.n_out
      elif feat == "tag":
          self.feat_embed = nn.Embedding(
              num_embeddings=n_feats, embedding_dim=n_feat_embed
          )
      else:
          raise RuntimeError(
              "The feat type should be in ['char', 'bert', 'tag']."
          )
      self.embed_dropout = IndependentDropout(p=embed_dropout)
  
      # the lstm layer
      self.lstm = BiLSTM(
          input_size=n_embed + n_feat_embed,
          hidden_size=n_lstm_hidden,
          num_layers=n_lstm_layers,
          dropout=lstm_dropout,
      )
      self.lstm_dropout = SharedDropout(p=lstm_dropout)
  
      # the MLP layers
      self.mlp_arc_d = MLP(
          n_in=n_lstm_hidden * 2, n_out=n_mlp_arc, dropout=mlp_dropout
      )
      self.mlp_arc_h = MLP(
          n_in=n_lstm_hidden * 2, n_out=n_mlp_arc, dropout=mlp_dropout
      )
      self.mlp_rel_d = MLP(
          n_in=n_lstm_hidden * 2, n_out=n_mlp_rel, dropout=mlp_dropout
      )
      self.mlp_rel_h = MLP(
          n_in=n_lstm_hidden * 2, n_out=n_mlp_rel, dropout=mlp_dropout
      )
  
      # the Biaffine layers
      self.arc_attn = Biaffine(
          n_in=n_mlp_arc, bias_x=True, bias_y=False
      )
      self.rel_attn = Biaffine(
          n_in=n_mlp_rel, n_out=n_rels, bias_x=True, bias_y=True
      )
      self.criterion = nn.CrossEntropyLoss()
      self.pad_index = pad_index
      self.unk_index = unk_index
  
      self.transform = transform
      feat = self.feat
      if feat in ("char", "bert"):
          self.WORD, self.FEAT = self.transform.FORM
      else:
          self.WORD, self.FEAT = (
              self.transform.FORM,
              self.transform.CPOS,
          )
      self.ARC, self.REL = self.transform.HEAD, self.transform.DEPREL
      self.puncts = torch.tensor(
          [i for s, i in self.WORD.vocab.stoi.items() if ispunct(s)]
      ).to(device)
  
imports: import os
  from datetime import datetime
  from underthesea.utils import logger
  from underthesea.utils.sp_data import Dataset
  from underthesea.utils.sp_field import Field
  from underthesea.utils.sp_fn import ispunct
  from underthesea.utils.sp_init import PRETRAINED
  from underthesea.utils.sp_metric import AttachmentMetric
  import torch
  import torch.nn
  from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence
  from underthesea.transforms.conll import CoNLL
  from underthesea.modules.base import CharLSTM, IndependentDropout, BiLSTM, SharedDropout, MLP, Biaffine
  from underthesea.modules.bert import BertEmbedding
  from underthesea.utils.sp_alg import eisner, mst
  import underthesea.modules.nn
  from underthesea.utils.util_deep_learning import device
label_desc: Use image node_id 1 to create a new DependencyParser object from inherited base classes: underthesea.modules.nn with example: obj = DependencyParser(n_words, pad_index, unk_index, n_feats, n_rels, feat, n_embed, n_feat_embed, n_char_embed, bert, n_bert_layers, embed_dropout, max_len, mix_dropout, embeddings, embed, n_lstm_hidden, n_lstm_layers, lstm_dropout, n_mlp_arc, n_mlp_rel, mlp_dropout, feat_pad_index, init_pre_train, transform)