(self, x, attribute_feat=None, attribute_label=None)
| 802 | nn.init.constant_(m.bias, 0) |
| 803 | |
| 804 | def forward(self, x, attribute_feat=None, attribute_label=None): |
| 805 | if attribute_label is not None: |
| 806 | x_out = [] |
| 807 | adj = self.create_compositional_graph(attribute_label) |
| 808 | attribute_feat_tensor = torch.stack(attribute_feat, dim=1) |
| 809 | for _x, _att_f, _adj in zip(x, attribute_feat_tensor, adj): |
| 810 | _vertex = torch.cat((_att_f, _x.unsqueeze(0)), dim=0) |
| 811 | after_vertex = self.gcn(_vertex, _adj) |
| 812 | x_out.append(after_vertex[-1]) |
| 813 | x_out = torch.stack(x_out, dim=0) |
| 814 | return x_out |
| 815 | else: |
| 816 | l2norm_head_embedding_list = [] |
| 817 | for _att_f in attribute_feat: |
| 818 | l2norm_head_embedding_list.append(F.normalize(_att_f)) |
| 819 | a = torch.stack(l2norm_head_embedding_list, dim=1) # 64*28*384 |
| 820 | l2_x = F.normalize(x) |
| 821 | b = torch.unsqueeze(l2_x, dim=2) # 64*384*1 |
| 822 | ab = F.softmax(torch.bmm(a, b), dim=1) # 64*28*1 |
| 823 | a_t = torch.transpose(a, dim0=1, dim1=2) # 64*384*28 |
| 824 | a_t_ab = torch.bmm(a_t, ab) |
| 825 | a_t_ab = a_t_ab.squeeze() |
| 826 | return a_t_ab |
| 827 | |
| 828 | def create_compositional_graph(self, attribute_label): |
| 829 | att_num = attribute_label.size(1) |
nothing calls this directly
no test coverage detected