class_docstr: **Biaffine Dependency Parser** 实现。
  论文参考 `Deep Biaffine Attention for Neural Dependency Parsing (Dozat and Manning, 2016) <https://arxiv.org/abs/1611.01734>`_ 。
  
  :param embed: 单词词典，支持以下几种输入类型：
  
          - ``tuple(num_embedings, embedding_dim)``，即 embedding 的大小和每个词的维度，此时将随机初始化一个 :class:`torch.nn.Embedding` 实例；
          - :class:`torch.nn.Embedding` 或 **fastNLP** 的 ``Embedding`` 对象，此时就以传入的对象作为 embedding；
          - :class:`numpy.ndarray` ，将使用传入的 ndarray 作为 Embedding 初始化；
          - :class:`torch.Tensor`，此时将使用传入的值作为 Embedding 初始化；
  
  :param pos_vocab_size: part-of-speech 词典大小
  :param pos_emb_dim: part-of-speech 向量维度
  :param num_label: 边的类别个数
  :param rnn_layers: rnn encoder 的层数
  :param rnn_hidden_size: rnn encoder 的隐状态维度
  :param arc_mlp_size: 边预测的 MLP 维度
  :param label_mlp_size: 类别预测的 MLP 维度
  :param dropout: dropout 概率
  :param encoder: encoder 类别，可选 ``['lstm', 'var-lstm', 'transformer']``。
  :param use_greedy_infer: 是否在 inference 时使用 :meth:`贪心算法 <GraphParser.greedy_decoder>` ，若为 ``False`` ，
      将使用更加精确但相对缓慢的 :meth:`MST算法 <GraphParser.mst_decoder>` 。
class_docstr_tok: ["*","*","Biaffine","Dependency","Parser","*","*","\u5b9e\u73b0\u3002","\u8bba\u6587\u53c2\u8003","`","Deep","Biaffine","Attention","for","Neural","Dependency","Parsing","(","Dozat","and","Manning",",","2016",")","<","https",":","\/\/arxiv.org\/abs\/1611.01734",">","`","_","\u3002",":","param","embed",":","\u5355\u8bcd\u8bcd\u5178\uff0c\u652f\u6301\u4ee5\u4e0b\u51e0\u79cd\u8f93\u5165\u7c7b\u578b\uff1a","-","``","tuple","(","num_embedings",",","embedding_dim",")","``","\uff0c\u5373","embedding","\u7684\u5927\u5c0f\u548c\u6bcf\u4e2a\u8bcd\u7684\u7ef4\u5ea6\uff0c\u6b64\u65f6\u5c06\u968f\u673a\u521d\u59cb\u5316\u4e00\u4e2a",":","class",":","`","torch.nn.Embedding","`","\u5b9e\u4f8b\uff1b","-",":","class",":","`","torch.nn.Embedding","`","\u6216","*","*","fastNLP","*","*","\u7684","``","Embedding","``","\u5bf9\u8c61\uff0c\u6b64\u65f6\u5c31\u4ee5\u4f20\u5165\u7684\u5bf9\u8c61\u4f5c\u4e3a","embedding\uff1b","-",":","class",":","`","numpy.ndarray","`","\uff0c\u5c06\u4f7f\u7528\u4f20\u5165\u7684","ndarray","\u4f5c\u4e3a","Embedding","\u521d\u59cb\u5316\uff1b","-",":","class",":","`","torch.Tensor","`","\uff0c\u6b64\u65f6\u5c06\u4f7f\u7528\u4f20\u5165\u7684\u503c\u4f5c\u4e3a","Embedding","\u521d\u59cb\u5316\uff1b",":","param","pos_vocab_size",":","part-of-speech","\u8bcd\u5178\u5927\u5c0f",":","param","pos_emb_dim",":","part-of-speech","\u5411\u91cf\u7ef4\u5ea6",":","param","num_label",":","\u8fb9\u7684\u7c7b\u522b\u4e2a\u6570",":","param","rnn_layers",":","rnn","encoder","\u7684\u5c42\u6570",":","param","rnn_hidden_size",":","rnn","encoder","\u7684\u9690\u72b6\u6001\u7ef4\u5ea6",":","param","arc_mlp_size",":","\u8fb9\u9884\u6d4b\u7684","MLP","\u7ef4\u5ea6",":","param","label_mlp_size",":","\u7c7b\u522b\u9884\u6d4b\u7684","MLP","\u7ef4\u5ea6",":","param","dropout",":","dropout","\u6982\u7387",":","param","encoder",":","encoder","\u7c7b\u522b\uff0c\u53ef\u9009","``","[","'lstm","'",",","'var-lstm","'",",","'transformer","'","]","``","\u3002",":","param","use_greedy_infer",":","\u662f\u5426\u5728","inference","\u65f6\u4f7f\u7528",":","meth",":","`","\u8d2a\u5fc3\u7b97\u6cd5","<","GraphParser.greedy_decoder",">","`","\uff0c\u82e5\u4e3a","``","False","``","\uff0c","\u5c06\u4f7f\u7528\u66f4\u52a0\u7cbe\u786e\u4f46\u76f8\u5bf9\u7f13\u6162\u7684",":","meth",":","`","MST\u7b97\u6cd5","<","GraphParser.mst_decoder",">","`","\u3002"]
code: def __init__(
      self,
      embed,
      pos_vocab_size,
      pos_emb_dim,
      num_label,
      rnn_layers=1,
      rnn_hidden_size=200,
      arc_mlp_size=100,
      label_mlp_size=100,
      dropout=0.3,
      encoder="lstm",
      use_greedy_infer=False,
  ):
      super(BiaffineParser, self).__init__()
      rnn_out_size = 2 * rnn_hidden_size
      word_hid_dim = pos_hid_dim = rnn_hidden_size
      self.word_embedding = get_embeddings(embed)
      word_emb_dim = self.word_embedding.embedding_dim
      self.pos_embedding = nn.Embedding(
          num_embeddings=pos_vocab_size, embedding_dim=pos_emb_dim
      )
      self.word_fc = nn.Linear(word_emb_dim, word_hid_dim)
      self.pos_fc = nn.Linear(pos_emb_dim, pos_hid_dim)
      self.word_norm = nn.LayerNorm(word_hid_dim)
      self.pos_norm = nn.LayerNorm(pos_hid_dim)
      self.encoder_name = encoder
      self.max_len = 512
      if encoder == "var-lstm":
          self.encoder = VarLSTM(
              input_size=word_hid_dim + pos_hid_dim,
              hidden_size=rnn_hidden_size,
              num_layers=rnn_layers,
              bias=True,
              batch_first=True,
              input_dropout=dropout,
              hidden_dropout=dropout,
              bidirectional=True,
          )
      elif encoder == "lstm":
          self.encoder = nn.LSTM(
              input_size=word_hid_dim + pos_hid_dim,
              hidden_size=rnn_hidden_size,
              num_layers=rnn_layers,
              bias=True,
              batch_first=True,
              dropout=dropout,
              bidirectional=True,
          )
      elif encoder == "transformer":
          n_head = 16
          d_k = d_v = int(rnn_out_size / n_head)
          if (d_k * n_head) != rnn_out_size:
              raise ValueError(
                  "Unsupported rnn_out_size: {} for transformer".format(
                      rnn_out_size
                  )
              )
          self.position_emb = nn.Embedding(
              num_embeddings=self.max_len,
              embedding_dim=rnn_out_size,
          )
          self.encoder = TransformerEncoder(
              num_layers=rnn_layers,
              d_model=rnn_out_size,
              n_head=n_head,
              dim_ff=1024,
              dropout=dropout,
          )
      else:
          raise ValueError(
              "Unsupported encoder type: {}".format(encoder)
          )
  
      self.mlp = nn.Sequential(
          nn.Linear(
              rnn_out_size, arc_mlp_size * 2 + label_mlp_size * 2
          ),
          nn.ELU(),
          TimestepDropout(p=dropout),
      )
      self.arc_mlp_size = arc_mlp_size
      self.label_mlp_size = label_mlp_size
      self.arc_predictor = ArcBiaffine(arc_mlp_size, bias=True)
      self.label_predictor = LabelBilinear(
          label_mlp_size, label_mlp_size, num_label, bias=True
      )
      self.use_greedy_infer = use_greedy_infer
      self.reset_parameters()
      self.dropout = dropout
  
imports: from collections import defaultdict
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from ...core.utils import seq_len_to_mask
  from ...embeddings.torch.utils import get_embeddings
  from ...modules.torch.dropout import TimestepDropout
  from ...modules.torch.encoder.transformer import TransformerEncoder
  from ...modules.torch.encoder.variational_rnn import VarLSTM
label_desc: Use image node_id 1 to create a new BiaffineParser object from inherited base classes: GraphParser with example: obj = BiaffineParser(embed, pos_vocab_size, pos_emb_dim, num_label, rnn_layers, rnn_hidden_size, arc_mlp_size, label_mlp_size, dropout, encoder, use_greedy_infer)