code: def forward(
      self,
      input_ids,
      token_type_ids=None,
      attention_mask=None,
      masked_lm_labels=None,
      next_sentence_label=None,
  ):
      sequence_output, pooled_output = self.bert(
          input_ids,
          token_type_ids,
          attention_mask,
          output_all_encoded_layers=False,
      )
      prediction_scores, seq_relationship_score = self.cls(
          sequence_output, pooled_output
      )
  
      if (
          masked_lm_labels is not None
          and next_sentence_label is not None
      ):
          loss_fct = CrossEntropyLoss(ignore_index=-1)
          next_sentence_loss = loss_fct(
              seq_relationship_score.view(-1, 2),
              next_sentence_label.view(-1),
          )
          masked_lm_loss = loss_fct(
              prediction_scores.view(-1, self.config.vocab_size),
              masked_lm_labels.view(-1),
          )
          total_loss = masked_lm_loss + next_sentence_loss
          return total_loss
      else:
          return prediction_scores, seq_relationship_score
  
imports: import torch
  import torch.nn
  from torch.nn import CrossEntropyLoss, MSELoss
  from turing.utils import TorchTuple
  from pytorch_pretrained_bert.modeling import BertModel
  from pytorch_pretrained_bert.modeling import BertPreTrainingHeads, PreTrainedBertModel, BertPreTrainingHeads
  from pytorch_pretrained_bert.file_utils import PYTORCH_PRETRAINED_BERT_CACHE
label_desc: Use image node_id 2 for calling the BertPretrainingLoss obj's underlying member method code with example usage: obj.forward(input_ids, token_type_ids, attention_mask, masked_lm_labels, next_sentence_label) and returns: total_loss, prediction_scores,  seq_relationship_score