目录

简介

代码

pos_score = tf.matmul(uc_emb, pos_emb, transpose_b=True)
neg_score = tf.matmul(uc_emb, neg_emb, transpose_b=True)
x = tf.reduce_sum(tf.multiply(uc_emb, (pos_emb - neg_emb)), 1, keep_dims=True)
bpr_loss = - tf.reduce_mean(tf.log(tf.nn.sigmoid(x) + 1e-10))
bpr_loss = tf.reduce_mean(tf.maximum(0.0, 1.0 + pos_score - neg_score))
reg_loss = tf.reduce_sum(tf.square(uc_emb)) + tf.reduce_sum(tf.square(pos_emb)) + tf.reduce_sum(tf.square(neg_emb))

参考

  • https://github.com/ljpzzz/machinelearning/blob/master/classic-machine-learning/bpr.ipynb