r"""The forward function. Args: ``hg_ui`` (``eg.Hypergraph``): The hypergraph structure that users as vertices. ``hg_iu`` (``eg.Hypergraph``): The hypergraph structure that items as vertices.
(
self, hg_ui: Hypergraph, hg_iu: Hypergraph
)
| 53 | nn.init.constant_(W_bi.bias, 0) |
| 54 | |
| 55 | def forward( |
| 56 | self, hg_ui: Hypergraph, hg_iu: Hypergraph |
| 57 | ) -> Tuple[torch.Tensor, torch.Tensor]: |
| 58 | r"""The forward function. |
| 59 | |
| 60 | Args: |
| 61 | ``hg_ui`` (``eg.Hypergraph``): The hypergraph structure that users as vertices. |
| 62 | ``hg_iu`` (``eg.Hypergraph``): The hypergraph structure that items as vertices. |
| 63 | """ |
| 64 | u_embs = self.u_embedding.weight |
| 65 | i_embs = self.i_embedding.weight |
| 66 | all_embs = torch.cat([u_embs, i_embs], dim=0) |
| 67 | |
| 68 | embs_list = [all_embs] |
| 69 | for _idx in range(self.num_layers): |
| 70 | u_embs, i_embs = torch.split( |
| 71 | all_embs, [self.num_users, self.num_items], dim=0 |
| 72 | ) |
| 73 | # ========================================================================================== |
| 74 | # Two JHConv Layers for users and items, respectively. |
| 75 | u_embs = hg_ui.smoothing_with_HGNN(u_embs) |
| 76 | i_embs = hg_iu.smoothing_with_HGNN(i_embs) |
| 77 | g_embs = torch.cat([u_embs, i_embs], dim=0) |
| 78 | sum_embs = F.leaky_relu( |
| 79 | self.W_gc[_idx](g_embs) + g_embs, negative_slope=0.2 |
| 80 | ) |
| 81 | # ========================================================================================== |
| 82 | |
| 83 | bi_embs = all_embs * g_embs |
| 84 | bi_embs = F.leaky_relu(self.W_bi[_idx](bi_embs), negative_slope=0.2) |
| 85 | |
| 86 | all_embs = sum_embs + bi_embs |
| 87 | all_embs = F.dropout(all_embs, p=self.drop_rate, training=self.training) |
| 88 | all_embs = F.normalize(all_embs, p=2, dim=1) |
| 89 | |
| 90 | embs_list.append(all_embs) |
| 91 | embs = torch.stack(embs_list, dim=1) |
| 92 | embs = torch.mean(embs, dim=1) |
| 93 | |
| 94 | u_embs, i_embs = torch.split(embs, [self.num_users, self.num_items], dim=0) |
| 95 | return u_embs, i_embs |
nothing calls this directly
no test coverage detected