import tensorflow as tf

    y = output
    if add_bias:
        bias = tf.Variable([0.0])
        y = output + bias
    sig_y = tf.clip_by_value(tf.sigmoid(y), 0.001, 0.999) # avoid NaNs
    loss = -tf.reduce_sum(target*tf.log(sig_y) + (1-target)*tf.log(1-sig_y))
    return sig_y, loss


def ranking_margin_objective(output, margin=1.0):
