code: def get_next_sentence_output(
      bert_config, input_tensor, labels, global_batch_size
  ):
      """Get loss and log probs for the next sentence prediction."""
  
      # Simple binary classification. Note that 0 is "next sentence" and 1 is
      # "random sentence". This weight matrix is not used after pre-training.
      with tf.variable_scope("cls/seq_relationship"):
          output_weights = tf.get_variable(
              "output_weights",
              shape=[2, bert_config.hidden_size],
              initializer=modeling.create_initializer(
                  bert_config.initializer_range
              ),
          )
          output_bias = tf.get_variable(
              "output_bias",
              shape=[2],
              initializer=tf.zeros_initializer(),
          )
  
          logits = tf.matmul(
              input_tensor, output_weights, transpose_b=True
          )
          logits = tf.nn.bias_add(logits, output_bias)
          log_probs = tf.nn.log_softmax(logits, axis=-1)
          labels = tf.reshape(labels, [-1])
          one_hot_labels = tf.one_hot(labels, depth=2, dtype=tf.float32)
          per_example_loss = -tf.reduce_sum(
              one_hot_labels * log_probs, axis=-1
          )
  
          # loss = tf.reduce_mean(per_example_loss)
          scaled_per_example_loss = per_example_loss * (
              1.0 / global_batch_size
          )
          scaled_loss = tf.nn.compute_average_loss(
              per_example_loss, global_batch_size=global_batch_size
          )
  
          return (scaled_loss, per_example_loss, log_probs)
  
file_path: BigDL/python/orca/example/learn/tf/bert/run_pretraining.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  import os
  import absl
  import sys
  import modeling
  import optimization
  import tensorflow.compat.v1
  from bigdl.orca.learn.tf.tf_estimator import TFEstimator
label_desc: Use image node_id 3 for calling a global function with example usage: get_next_sentence_output(bert_config, input_tensor, labels, global_batch_size) and returns: scaled_loss,  per_example_loss,  log_probs