1:BPR
获取user和item,然后传入forward()函数进行评分。
def predict(self, interaction):
user = interaction[self.USER_ID]
item = interaction[self.ITEM_ID]
user_e, item_e = self.forward(user, item)
return torch.mul(user_e, item_e).sum(dim=1)
2:XDeepFM
获取一批item将item传入,forward()函数,求出评分。
def predict(self, interaction):
return self.forward(interaction)
def forward(self, interaction):
# Get the output of CIN.
xdeepfm_input = self.concat_embed_input_fields(interaction) # [batch_size, num_field, embed_dim]
cin_output = self.compressed_interaction_network(xdeepfm_input)
cin_output = self.cin_linear(cin_output)
# Get the output of MLP layer.
batch_size = xdeepfm_input.shape[0]
dnn_output = self.mlp_layers(xdeepfm_input.view(batch_size, -1))
# Get predicted score.
y_p = self.first_order_linear(interaction) + cin_output + dnn_output
y = self.sigmoid(y_p)
return y.squeeze(1)
3:LightGCN
根据user和item传入forward()函数提取的embedding中,抽取相应的embedding,然后将u_e和i_e矩阵点乘,即可得到最后的得分。
def predict(self, interaction):