def create_model_bilin(model, labels, num_choices):
  """Creates a classification model.

  Args:
    model: the BERT model from modeling.py
    labels: ground truth paragraph order
    num_choices: number of negatives samples + 1

  Returns:
    tuple of (loss, per_example_loss, logits, probabilities) for model
  """

  output_layer = model.get_pooled_output()

  hidden_size = output_layer.shape[-1].value

  with tf.variable_scope("cpc_loss"):
    output = tf.reshape(output_layer, (-1, num_choices + 1, hidden_size))
    contexts = output[:, 0, :]
    targets = output[:, 1:, :]

    softmax_weights = tf.get_variable(
        "cpc_weights", [8, hidden_size, hidden_size],
        initializer=tf.truncated_normal_initializer(stddev=0.02))

    softmax_weights = softmax_weights[4:5]

    context_encoded = tf.matmul(softmax_weights, contexts, transpose_b=True)
    context_encoded = tf.transpose(context_encoded, perm=[2, 0, 1])

    logits = tf.matmul(targets, context_encoded, transpose_b=True)
    logits = tf.transpose(logits, perm=[0, 2, 1])
    logits = tf.squeeze(logits, axis=[1])
    # labels = tf.squeeze(labels, axis=[1])

    per_example_loss = tf.nn.sparse_softmax_cross_entropy_with_logits(
        logits=logits, labels=labels)
    probabilities = tf.nn.softmax(logits, axis=-1)
    loss = tf.reduce_mean(per_example_loss)

  return (loss, per_example_loss, logits, probabilities)
Creates a classification model.

  Args:
    model: the BERT model from modeling.py
    labels: ground truth paragraph order
    num_choices: number of negatives samples + 1

  Returns:
    tuple of (loss, per_example_loss, logits, probabilities) for model
  
language/conpono/evals/model_builder.py