shibing624 / text2vec

text2vec, text to vector. 文本向量表征工具,把文本转化为向量矩阵,实现了Word2Vec、RankBM25、Sentence-BERT、CoSENT等文本表征、文本相似度计算模型,开箱即用。
https://pypi.org/project/text2vec/
Apache License 2.0
4.39k stars 392 forks source link

关于cosnet中loss的不解 #112

Closed lightislost closed 1 year ago

lightislost commented 1 year ago

Describe the Question

Please provide a clear and concise description of what the question is.

https://github.com/shibing624/text2vec/blob/a1ba1df243755167622a148de0aae46972d203b7/text2vec/cosent_model.py#L150C1-L150C46 CODE: y_pred = y_pred - (1 - y_true) * 1e12

这里 y_pred 减去 后面 (1-y_true) 的含义是什么呀?

我看y_pred是所有两两向量之间的余弦值,那我理解loss接下来应该只用选出负例-正例的向量差项就可以了吧?为什么是减去 后面 (1-y_true) 呢?

望解惑