对比损失(Contrastive Loss)学习【转载】

时间:2023-03-10 07:27:45
对比损失(Contrastive Loss)学习【转载】

转自:https://blog.csdn.net/autocyz/article/details/53149760

https://www.tensorflow.org/tutorials/representation/word2vec?hl=zh-cn

1.公式对比损失(Contrastive Loss)学习【转载】

//链接的博客里讲的很不错,当两个样本标签相同,即相似y=1,则欧式距离越大损失函数越大,反之,欧式距离越小,损失函数越小;

当两样本不相似时y=0,只有后一项,若欧式距离越小反而loss越大;欧式距离越大loss越小。

对比损失(Contrastive Loss)学习【转载】

噪声对比估计损失是基于逻辑回归模型进行定义的。为此,我们需要为词汇表中的每个字词定义权重和偏差(也称为 output weights,与 input embeddings 相对)。我们先进行定义。

nce_weights = tf.Variable(
tf.truncated_normal([vocabulary_size, embedding_size],
stddev=1.0 / math.sqrt(embedding_size)))
nce_biases = tf.Variable(tf.zeros([vocabulary_size]))