MCPcopy Create free account
hub / github.com/HKUDS/PromptMM / forward

Method forward

codes/Models.py:338–367  ·  view source on GitHub ↗
(self, adj)

Source from the content-addressed store, hash-verified

336 return self.user_id_embedding, self.item_id_embedding
337
338 def forward(self, adj):
339
340 # # teacher_feat_dict = { 'item_image':t_i_image_embed.deteach(),'item_text':t_i_text_embed.deteach(),'user_image':t_u_image_embed.deteach(),'user_text':t_u_text_embed.deteach() }
341 # tmp_feat_dict = {}
342 # for index,value in enumerate(teacher_feat_dict.keys()):
343 # tmp_feat_dict[value] = self.feat_trans(teacher_feat_dict[value])
344 # u_g_embeddings = self.user_id_embedding.weight + args.model_cat_rate*F.normalize(tmp_feat_dict['user_image'], p=2, dim=1) + args.model_cat_rate*F.normalize(tmp_feat_dict['user_text'], p=2, dim=1)
345 # i_g_embeddings = self.item_id_embedding.weight + args.model_cat_rate*F.normalize(tmp_feat_dict['item_image'], p=2, dim=1) + args.model_cat_rate*F.normalize(tmp_feat_dict['item_text'], p=2, dim=1)
346 # ego_embeddings = torch.cat((u_g_embeddings, i_g_embeddings), dim=0)
347
348 # self.user_id_embedding_pre = nn.Embedding.from_pretrained(pre_u_embed, freeze=False)
349 # self.item_id_embedding_pre = nn.Embedding.from_pretrained(pre_i_embed, freeze=False)
350
351 ego_embeddings = torch.cat((self.user_id_embedding.weight+self.user_id_embedding_pre.weight, self.item_id_embedding.weight+self.item_id_embedding_pre.weight), dim=0)
352 # ego_embeddings = torch.cat((self.user_id_embedding.weight, self.item_id_embedding.weight), dim=0)
353 all_embeddings = [ego_embeddings]
354 for i in range(self.n_ui_layers):
355 side_embeddings = torch.sparse.mm(adj, ego_embeddings)
356 ego_embeddings = side_embeddings
357 all_embeddings += [ego_embeddings]
358 all_embeddings = torch.stack(all_embeddings, dim=1)
359 all_embeddings = all_embeddings.mean(dim=1, keepdim=False)
360 u_g_embeddings, i_g_embeddings = torch.split(all_embeddings, [self.n_users, self.n_items], dim=0)
361 # u_g_embeddings += teacher_feat_dict['user_image'] + teacher_feat_dict['user_text']
362 # i_g_embeddings += teacher_feat_dict['item_image'] + teacher_feat_dict['item_text']
363 # u_g_embeddings = u_g_embeddings + args.model_cat_rate*F.normalize(teacher_feat_dict['user_image'], p=2, dim=1) + args.model_cat_rate*F.normalize(teacher_feat_dict['user_text'], p=2, dim=1)
364 # i_g_embeddings = i_g_embeddings + args.model_cat_rate*F.normalize(teacher_feat_dict['item_image'], p=2, dim=1) + args.model_cat_rate*F.normalize(teacher_feat_dict['item_text'], p=2, dim=1)
365
366 return u_g_embeddings, i_g_embeddings
367 # return self.user_id_embedding.weight, self.item_id_embedding.weight
368
369
370

Callers

nothing calls this directly

Calls 1

mmMethod · 0.45

Tested by

no test coverage detected