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"]
docstr: Args:
      words (torch.LongTensor): ``[batch_size, seq_len]``.
          Word indices.
      feats (torch.LongTensor):
          Feat indices.
          If feat is ``'char'`` or ``'bert'``, the size of feats should be ``[batch_size, seq_len, fix_len]``.
          if ``'tag'``, the size is ``[batch_size, seq_len]``.
  
  Returns:
      torch.Tensor, torch.Tensor:
          The first tensor of shape ``[batch_size, seq_len, seq_len]`` holds scores of all possible arcs.
          The second of shape ``[batch_size, seq_len, seq_len, n_labels]`` holds
          scores of all possible labels on each arc.
docstr_tok: ["Args",":","words","(","torch.LongTensor",")",":","``","[","batch_size",",","seq_len","]","``",".","Word","indices",".","feats","(","torch.LongTensor",")",":","Feat","indices",".","If","feat","is","``","'char","'","``","or","``","'bert","'","``",",","the","size","of","feats","should","be","``","[","batch_size",",","seq_len",",","fix_len","]","``",".","if","``","'tag","'","``",",","the","size","is","``","[","batch_size",",","seq_len","]","``",".","Returns",":","torch.Tensor",",","torch.Tensor",":","The","first","tensor","of","shape","``","[","batch_size",",","seq_len",",","seq_len","]","``","holds","scores","of","all","possible","arcs",".","The","second","of","shape","``","[","batch_size",",","seq_len",",","seq_len",",","n_labels","]","``","holds","scores","of","all","possible","labels","on","each","arc","."]
code: def forward(self, words, feats):
      r"""
      Args:
          words (torch.LongTensor): ``[batch_size, seq_len]``.
              Word indices.
          feats (torch.LongTensor):
              Feat indices.
              If feat is ``'char'`` or ``'bert'``, the size of feats should be ``[batch_size, seq_len, fix_len]``.
              if ``'tag'``, the size is ``[batch_size, seq_len]``.
  
      Returns:
          torch.Tensor, torch.Tensor:
              The first tensor of shape ``[batch_size, seq_len, seq_len]`` holds scores of all possible arcs.
              The second of shape ``[batch_size, seq_len, seq_len, n_labels]`` holds
              scores of all possible labels on each arc.
      """
  
      batch_size, seq_len = words.shape
      # get the mask and lengths of given batch
      mask = words.ne(self.pad_index)
      ext_words = words
      # set the indices larger than num_embeddings to unk_index
      if hasattr(self, "pretrained"):
          ext_mask = words.ge(self.word_embed.num_embeddings)
          ext_words = words.masked_fill(ext_mask, self.unk_index)
  
      # get outputs from embedding layers
      word_embed = self.word_embed(ext_words)
      if hasattr(self, "pretrained"):
          word_embed += self.pretrained(words)
      feat_embed = self.feat_embed(feats)
      word_embed, feat_embed = self.embed_dropout(
          word_embed, feat_embed
      )
      # concatenate the word and feat representations
      embed = torch.cat((word_embed, feat_embed), -1)
  
      x = pack_padded_sequence(embed, mask.sum(1), True, False)
      x, _ = self.lstm(x)
      x, _ = pad_packed_sequence(x, True, total_length=seq_len)
      x = self.lstm_dropout(x)
  
      # apply MLPs to the BiLSTM output states
      arc_d = self.mlp_arc_d(x)
      arc_h = self.mlp_arc_h(x)
      rel_d = self.mlp_rel_d(x)
      rel_h = self.mlp_rel_h(x)
  
      # [batch_size, seq_len, seq_len]
      s_arc = self.arc_attn(arc_d, arc_h)
      # [batch_size, seq_len, seq_len, n_rels]
      s_rel = self.rel_attn(rel_d, rel_h).permute(0, 2, 3, 1)
      # set the scores that exceed the length of each sentence to -inf
      s_arc.masked_fill_(~mask.unsqueeze(1), float("-inf"))
  
      return s_arc, s_rel
  
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 9 for calling the DependencyParser obj's underlying member method code with example usage: obj.forward(words, feats) and returns: s_arc,  s_rel