def call(self, inputs): batch_size = tf.shape(inputs)[0] neighbors = euler_ops.sample_neighbor( inputs, self.edge_type, self.nb_num)[0] node_feats = euler_ops.get_dense_feature( tf.reshape(inputs, [-1]), [self.feature_idx], [self.feature_dim])[0] neighbor_feats = euler_ops.get_dense_feature( tf.reshape(neighbors, [-1]), [self.feature_idx], [self.feature_dim])[0] node_feats = tf.reshape(node_feats, [batch_size, 1, self.feature_dim]) neighbor_feats = tf.reshape( neighbor_feats, [batch_size, self.nb_num, self.feature_dim]) nbs = tf.concat([node_feats, neighbor_feats], 1) topk, _ = tf.nn.top_k(tf.transpose(neighbor_feats, [0, 2, 1]), k=self.k) topk = tf.transpose(topk, [0, 2, 1]) topk = tf.concat([node_feats, topk], 1) hidden = tf.layers.conv1d(topk, self.hidden_dim, self.k // 2 + 1, use_bias=True) out = tf.layers.conv1d(hidden, self.out_dim, self.k // 2 + 1, use_bias=True) out = tf.slice(out, [0, 0, 0], [batch_size, 1, self.out_dim]) return tf.reshape(out, [batch_size, self.out_dim])
def call(self, inputs): batch_size = inputs.shape[0] neighbors = euler_ops.sample_neighbor(inputs, [self.edge_type], self.nb_num)[0] node_feats = euler_ops.get_dense_feature(tf.reshape(inputs, [-1]), [self.feature_idx], [self.feature_dim])[0] neighbor_feats = euler_ops.get_dense_feature( tf.reshape(neighbors, [-1]), [self.feature_idx], [self.feature_dim])[0] node_feats = tf.reshape(node_feats, [batch_size, 1, self.feature_dim]) neighbor_feats = tf.reshape( neighbor_feats, [batch_size, self.nb_num, self.feature_dim]) seq = tf.concat([node_feats, neighbor_feats], 1) #[bz,nb+1,fdim] hidden = [] for i in range(0, self.head_num): #hidden_val = self.att_head_v2(tf.reshape(inputs,[batch_size,1]),neighbors) hidden_val = self.att_head(seq, self.hidden_dim, tf.nn.elu) print('hidden shape', hidden_val.shape) hidden_val = tf.reshape( hidden_val, [batch_size, self.nb_num + 1, self.hidden_dim]) hidden.append(hidden_val) h_1 = tf.concat(hidden, -1) out = [] for i in range(0, self.head_num): out_val = self.att_head(h_1, self.out_dim, tf.nn.elu) out_val = tf.reshape(out_val, [batch_size, self.nb_num + 1, self.out_dim]) out.append(out_val) out = tf.add_n(out) / self.head_num out = tf.reshape(out, [batch_size, self.nb_num + 1, self.out_dim]) out = tf.slice(out, [0, 0, 0], [batch_size, 1, self.out_dim]) print('out shape', out.shape) return tf.reshape(out, [batch_size, self.out_dim])
def call(self, inputs): embeddings = [] if self.use_id: embeddings.append(self.embedding(inputs)) if self.use_feature: feature = euler_ops.get_dense_feature(inputs, [self.feature_idx], [self.feature_dim])[0] embeddings.append(self.dense(feature)) return tf.add_n(embeddings)
def node_encoder(self, inputs): if self.use_id: id_embedding = self.embedding(inputs) if not self.use_feature: return id_embedding feature = euler_ops.get_dense_feature(inputs, [self.feature_idx], [self.feature_dim])[0] if self.use_id: feature = tf.concat([feature, id_embedding], 1) return feature
def call(self, inputs): labels = euler_ops.get_dense_feature(inputs, [self.label_idx], [self.label_dim])[0] if self.label_dim == 1: labels = tf.one_hot(tf.to_int64(tf.squeeze(labels)), self.num_classes) embedding = self.encoder(inputs) predictions, loss = self.decoder(embedding, labels) f1 = metrics.f1_score(labels, predictions, name='f1') return ModelOutput(embedding=embedding, loss=loss, metric_name='f1', metric=f1)
def node_encoder(self, inputs): embeddings = [] if self.use_id: embeddings.append(self.id_layer(inputs)) if self.use_feature: from_feature = euler_ops.get_dense_feature(inputs, [self.feature_idx], [self.feature_dim])[0] if self.use_residual: from_feature = self.feature_layer(from_feature) embeddings.append(from_feature) if self.use_residual: return tf.add_n(embeddings) else: return tf.concat(embeddings, 1)
def call(self, inputs): input_shape = inputs.shape inputs = tf.reshape(inputs, [-1]) embeddings = [] if self.use_id: embeddings.append(self.embedding(inputs)) if self.use_feature: features = euler_ops.get_dense_feature(inputs, self.feature_idx, self.feature_dim) features = tf.concat(features, -1) if self.combiner == 'add': features = self.dense(features) embeddings.append(features) if self.use_sparse_feature: default_values = [ max_id + 1 for max_id in self.sparse_feature_max_id ] sparse_features = euler_ops.get_sparse_feature( inputs, self.sparse_feature_idx, default_values=default_values) embeddings.extend([ sparse_embedding(sparse_feature) for sparse_embedding, sparse_feature in zip( self.sparse_embeddings, sparse_features) ]) if self.combiner == 'add': embedding = tf.add_n(embeddings) else: embedding = tf.concat(embeddings, -1) if self.dim: embedding = self.dense(embedding) output_shape = input_shape.concatenate(self.output_dim) output_shape = [ d if d is not None else -1 for d in output_shape.as_list() ] return tf.reshape(embedding, output_shape)