(
    FLAGS, features, n_class, is_training)
Loss for downstream classification tasks.
Loss for downstream classification tasks.
Loss for downstream classification tasks .
def get_classification_loss(
    FLAGS, features, n_class, is_training):
  """Loss for downstream classification tasks."""

  bsz_per_core = tf.shape(features["input_ids"])[0]

  inp = tf.transpose(features["input_ids"], [1, 0])
  seg_id = tf.transpose(features["segment_ids"], [1, 0])
  inp_mask = tf.transpose(features["input_mask"], [1, 0])
  label = tf.reshape(features["label_ids"], [bsz_per_core])

  xlnet_config = xlnet.XLNetConfig(json_path=FLAGS.model_config_path)
  run_config = xlnet.create_run_config(is_training, True, FLAGS)

  xlnet_model = xlnet.XLNetModel(
      xlnet_config=xlnet_config,
      run_config=run_config,
      input_ids=inp,
      seg_ids=seg_id,
      input_mask=inp_mask)

  summary = xlnet_model.get_pooled_out(FLAGS.summary_type, FLAGS.use_summ_proj)

  with tf.variable_scope("model", reuse=tf.AUTO_REUSE):

    if FLAGS.cls_scope is not None and FLAGS.cls_scope:
      cls_scope = "classification_{}".format(FLAGS.cls_scope)
    else:
      cls_scope = "classification_{}".format(FLAGS.task_name.lower())

    per_example_loss, logits = modeling.classification_loss(
        hidden=summary,
        labels=label,
        n_class=n_class,
        initializer=xlnet_model.get_initializer(),
        scope=cls_scope,
        return_logits=True)

    total_loss = tf.reduce_mean(per_example_loss)

    return total_loss, per_example_loss, logits
def get_classification_loss ( FLAGS , features , n_class , is_training ) : bsz_per_core = tf . shape ( features [ "input_ids" ] ) [ 0 ] inp = tf . transpose ( features [ "input_ids" ] , [ 1 , 0 ] ) seg_id = tf . transpose ( features [ "segment_ids" ] , [ 1 , 0 ] ) inp_mask = tf . transpose ( features [ "input_mask" ] , [ 1 , 0 ] ) label = tf . reshape ( features [ "label_ids" ] , [ bsz_per_core ] ) xlnet_config = xlnet . XLNetConfig ( json_path = FLAGS . model_config_path ) run_config = xlnet . create_run_config ( is_training , True , FLAGS ) xlnet_model = xlnet . XLNetModel ( xlnet_config = xlnet_config , run_config = run_config , input_ids = inp , seg_ids = seg_id , input_mask = inp_mask ) summary = xlnet_model . get_pooled_out ( FLAGS . summary_type , FLAGS . use_summ_proj ) with tf . variable_scope ( "model" , reuse = tf . AUTO_REUSE ) : if FLAGS . cls_scope is not None and FLAGS . cls_scope : cls_scope = "classification_{}" . format ( FLAGS . cls_scope ) else : cls_scope = "classification_{}" . format ( FLAGS . task_name . lower ( ) ) per_example_loss , logits = modeling . classification_loss ( hidden = summary , labels = label , n_class = n_class , initializer = xlnet_model . get_initializer ( ) , scope = cls_scope , return_logits = True ) total_loss = tf . reduce_mean ( per_example_loss ) return total_loss , per_example_loss , logits