| 174 | Attention Layer: input shape should be[batch_size, seq_length, feature_dim] |
| 175 | """ |
| 176 | def __init__(self, |
| 177 | out_dim, |
| 178 | activation=tf.nn.elu, |
| 179 | activation_out=lambda x: x, |
| 180 | hidden_dim=[], |
| 181 | head_num=[1], |
| 182 | **kwargs): |
| 183 | super(AttLayer, self).__init__(**kwargs) |
| 184 | self.hidden_dim = hidden_dim |
| 185 | self.out_dim = out_dim |
| 186 | self.head_num = head_num |
| 187 | self.activation = activation |
| 188 | self.activation_out = activation_out |
| 189 | if len(head_num) < 1 or len(head_num) != len(hidden_dim) + 1: |
| 190 | raise ValueError('head_num must be greater than 1 and greater' |
| 191 | ' than hidden, got {},{}'.format(str(head_num), |
| 192 | str(hidden_dim))) |
| 193 | |
| 194 | def call(self, inputs): |
| 195 | rank = inputs.shape.ndims |