| 750 | |
| 751 | class LayerEncoder(SageEncoder): |
| 752 | def agg(self, inputs): |
| 753 | use_att = True |
| 754 | use_group = False |
| 755 | group_num = 5 |
| 756 | seq_len = tf.shape(inputs)[1] |
| 757 | split_size = [seq_len // group_num] * (group_num - 1) + [-1] |
| 758 | group_values = tf.split(inputs, split_size, 1) |
| 759 | group_hidden = tf.concat([tf.expand_dims(tf.reduce_sum(i, 1), 1) |
| 760 | for i in group_values], 1) |
| 761 | rank = inputs.shape.ndims |
| 762 | if rank == 2: |
| 763 | return inputs |
| 764 | if use_att: |
| 765 | att_layer = layers.AttLayer( |
| 766 | self.feature_dim, hidden_dim=[128], head_num=[2, 2]) |
| 767 | if use_group: |
| 768 | return att_layer(group_hidden) |
| 769 | else: |
| 770 | return att_layer(inputs) |
| 771 | return tf.reduce_mean(inputs, axis=1) |
| 772 | |
| 773 | def call(self, inputs): |
| 774 | samples = euler_ops.sample_fanout( |