class_docstr: Ernie Model for Masked Languate Model pretrain
class_docstr_tok: ["Ernie","Model","for","Masked","Languate","Model","pretrain"]
docstr: Args:
      nsp_labels (optional, `Variable` of shape [batch_size]):
          labels for `next sentence prediction` tasks
      mlm_pos (optional, `Variable` of shape [n_mask, 2]):
          index of mask_id in `src_ids`, can be obtained from `fluid.layers.where(src_ids==mask_id)`
      labels (optional, `Variable` of shape [n_mask]):
          labels for `mask language model` tasks, the original token indices in masked position in `src_ids`
  Returns:
      loss (`Variable` of shape []):
          total_loss of `next sentence prediction` and `masked language model`
      mlm_loss (`Variable` of shape []):
          loss for `masked language model` task
      nsp_loss (`Variable` of shape []):
          loss for `next sentence prediction` task
docstr_tok: ["Args",":","nsp_labels","(","optional",",","`","Variable","`","of","shape","[","batch_size","]",")",":","labels","for","`","next","sentence","prediction","`","tasks","mlm_pos","(","optional",",","`","Variable","`","of","shape","[","n_mask",",","2","]",")",":","index","of","mask_id","in","`","src_ids","`",",","can","be","obtained","from","`","fluid.layers.where","(","src_ids==mask_id",")","`","labels","(","optional",",","`","Variable","`","of","shape","[","n_mask","]",")",":","labels","for","`","mask","language","model","`","tasks",",","the","original","token","indices","in","masked","position","in","`","src_ids","`","Returns",":","loss","(","`","Variable","`","of","shape","[","]",")",":","total_loss","of","`","next","sentence","prediction","`","and","`","masked","language","model","`","mlm_loss","(","`","Variable","`","of","shape","[","]",")",":","loss","for","`","masked","language","model","`","task","nsp_loss","(","`","Variable","`","of","shape","[","]",")",":","loss","for","`","next","sentence","prediction","`","task"]
code: def forward(self, *args, **kwargs):
      """
      Args:
          nsp_labels (optional, `Variable` of shape [batch_size]):
              labels for `next sentence prediction` tasks
          mlm_pos (optional, `Variable` of shape [n_mask, 2]):
              index of mask_id in `src_ids`, can be obtained from `fluid.layers.where(src_ids==mask_id)`
          labels (optional, `Variable` of shape [n_mask]):
              labels for `mask language model` tasks, the original token indices in masked position in `src_ids`
      Returns:
          loss (`Variable` of shape []):
              total_loss of `next sentence prediction` and `masked language model`
          mlm_loss (`Variable` of shape []):
              loss for `masked language model` task
          nsp_loss (`Variable` of shape []):
              loss for `next sentence prediction` task
      """
  
      mlm_labels = kwargs.pop("labels")
      mlm_pos = kwargs.pop("mlm_pos")
      nsp_labels = kwargs.pop("nsp_labels")
      pooled, encoded = super(ErnieModelForPretraining, self).forward(
          *args, **kwargs
      )
      if len(mlm_labels.shape) != 1:
          mlm_labels = mlm_labels.squeeze()
      if len(nsp_labels.shape) == 1:
          nsp_labels = nsp_labels.squeeze()
  
      nsp_loss = self.pooler_heads[0](pooled, nsp_labels)
  
      encoded_2d = encoded.gather_nd(mlm_pos)
      encoded_2d = self.act(self.mlm(encoded_2d))
      encoded_2d = self.mlm_ln(encoded_2d)
      logits_2d = (
          encoded_2d.matmul(self.word_emb.weight, transpose_y=True)
          + self.mlm_bias
      )
      mlm_loss = F.cross_entropy(logits_2d, mlm_labels)
      total_loss = mlm_loss + nsp_loss
      return total_loss, mlm_loss, nsp_loss
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  import json
  import logging
  import math
  import six
  import numpy
  import paddle
  from paddle import nn
  from paddle.nn import functional
  from disco_diffusion_ernievil_base.vit_b_16x.ernievil2.transformers.file_utils import _fetch_from_remote, add_docstring
label_desc: Use image node_id 2 for calling the ErnieModelForPretraining obj's underlying member method code with example usage: obj.forward() and returns: total_loss,  mlm_loss,  nsp_loss