| 29 | raise NotImplementedError |
| 30 | |
| 31 | def __call__(self, inputs, label=None, graph_index=None): |
| 32 | if isinstance(inputs, dict): |
| 33 | label = inputs['graph_label'] |
| 34 | graph_index = inputs['node_graph_idx'] |
| 35 | inputs = inputs['node_idx'] |
| 36 | assert (label is not None or graph_index is not None) |
| 37 | graph_index = tf.cast(graph_index, tf.int32) |
| 38 | embedding = self.embed(inputs, graph_index) |
| 39 | logit = self.out_fc(embedding) |
| 40 | label = tf.cast(label, tf.float32) |
| 41 | |
| 42 | _, acc = tf.metrics.accuracy( |
| 43 | label, tf.floor(tf.nn.sigmoid(logit) + 0.5)) |
| 44 | loss = tf.nn.sigmoid_cross_entropy_with_logits( |
| 45 | labels=label, logits=logit) |
| 46 | loss = tf.reduce_mean(loss) |
| 47 | return (embedding, loss, 'accuracy', acc) |