class_docstr: BERT model ("Bidirectional Encoder Representations from Transformers").
class_docstr_tok: ["BERT","model","(","``","Bidirectional","Encoder","Representations","from","Transformers","''",")","."]
docstr: Get loss and logits for the next sentence prediction.
code: def get_next_sentence_output(self, labels):
      """Get loss and logits for the next sentence prediction."""
      class_dim = mtf.Dimension("class", 2)
      input_tensor = self.get_pooled_output()
      # Simple binary classification. Note that 0 is "next sentence" and 1 is
      # "random sentence". This weight matrix is not used after pre-training.
      logits = mtf.layers.dense(
          input_tensor,
          reduced_dims=[self.model_dim],
          new_dims=[class_dim],
          kernel_initializer=self.dense_initializer,
          name="cls/seq_relationship",
          use_bias=self.config.use_bias,
      )
      per_example_loss = mtf.layers.softmax_cross_entropy_with_logits(
          logits, labels, class_dim, z_loss=1e-4
      )
      loss = mtf.reduce_mean(per_example_loss)
      return (loss, per_example_loss, logits)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  import copy
  import json
  import math
  import re
  import mesh_tensorflow
  import mesh_tensorflow.transformer.moe
  import six
  import tensorflow.compat.v1
label_desc: Use image node_id 6 for calling the BertModel obj's underlying member method code with example usage: obj.get_next_sentence_output(labels) and returns: loss,  per_example_loss,  logits