shenweichen / DeepMatch

A deep matching model library for recommendations & advertising. It's easy to train models and to export representation vectors which can be used for ANN search.
https://deepmatch.readthedocs.io/en/latest/
Apache License 2.0
2.19k stars 525 forks source link

双塔模型在负样本negsample=0的时候,模型学到的是什么? #86

Closed CoGore closed 1 year ago

CoGore commented 1 year ago

各位大佬们,有一点不太理解的,当我把negsample设为0,这是相当于没有负样本给模型学习吗?如果是,为什么模型可以在没有负样本的情况下训练呢?如果不是,负样本是在哪个步骤生成的呢?

P.S. 我看源码DSSM应该是没用上NegativeSampler?我试过把num_sampled随意设成负数或者是字符串也不影响模型的运行,比如这样: sampler_config = NegativeSampler('inbatch',num_sampled='dfasdfas',item_name="item_id",item_count=item_count) model = DSSM(user_feature_columns, item_feature_columns,user_dnn_hidden_units=(128,64, embedding_dim), item_dnn_hidden_units=(64, embedding_dim,),loss_type='softmax',sampler_config=sampler_config) 所以顺便想问问,如果想在双塔模型生成in-batch的负样本,大佬们有什么好方法吗?

先谢谢大家了!

Mengyujun commented 1 year ago

in-batch的负样本就是拿这个batch内其他用户的正样本作为自己的负样本, 具体方法就是: batch内只保留点击正样本,然后分别过user塔和item塔,分别得到user矩阵A:【Batch_size, emb_dim】 以及 item矩阵B【Batch_size, emb_dim】, 然后作 矩阵乘法 A matmul B的转置,得到logit矩阵,label矩阵就是对角线为1的矩阵