| 430 | |
| 431 | |
| 432 | def forward(self, user_x, item_x, ui_graph, iu_graph): |
| 433 | # print('inputs:', inputs) |
| 434 | # x, support = inputs |
| 435 | # if self.training and self.is_sparse_inputs: |
| 436 | # x = sparse_dropout(x, self.dropout, self.num_features_nonzero) |
| 437 | # elif self.training: |
| 438 | user_x = F.dropout(user_x, self.dropout) |
| 439 | item_x = F.dropout(item_x, self.dropout) |
| 440 | # convolve |
| 441 | if not self.featureless: # if it has features x |
| 442 | if self.is_sparse_inputs: |
| 443 | xw = torch.sparse.mm(user_x, self.user_weight) |
| 444 | xw = torch.sparse.mm(item_x, self.item_weight) |
| 445 | else: |
| 446 | xw_user = torch.mm(user_x, self.user_weight) |
| 447 | xw_item = torch.mm(item_x, self.item_weight) |
| 448 | else: |
| 449 | xw = self.weight |
| 450 | out_user = torch.sparse.mm(ui_graph, xw_item) |
| 451 | out_item = torch.sparse.mm(iu_graph, xw_user) |
| 452 | |
| 453 | if self.bias is not None: |
| 454 | out += self.bias |
| 455 | return self.activation(out_user), self.activation(out_item) |
| 456 | |
| 457 | |
| 458 | def sparse_dropout(x, rate, noise_shape): |