python - Attention Layer throwing TypeError: Permute layer does not support masking in Keras -


i have been following post in order implement attention layer on lstm model.

code attention layer:

def attention_3d_block(inputs):     # inputs.shape = (batch_size, time_steps, input_dim)     input_dim = int(inputs.shape[2])     = permute((2, 1))(inputs)     = reshape((input_dim, time_steps))(a)     = dense(time_steps, activation='softmax')(a)     if single_attention_vector:         = lambda(lambda x: k.mean(x, axis=1), name='dim_reduction')(a)         = repeatvector(input_dim)(a)     a_probs = permute((2, 1), name='attention_vec')(a)     output_attention_mul = merge([inputs, a_probs], name='attention_mul', mode='mul')     return output_attention_mul 

the error get:

file "main_copy.py", line 244, in model = create_model(x_vocab_len, x_max_len, y_vocab_len, y_max_len, hidden_dim, layer_num) file "main_copy.py", line 189, in create_model attention_mul = attention_3d_block(temp) file "main_copy.py", line 124, in attention_3d_block = permute((2, 1))(inputs) file "/root/.virtualenvs/keras_tf/lib/python3.5/site-packages/keras/engine/topology.py", line 597, in call output_mask = self.compute_mask(inputs, previous_mask) file "/root/.virtualenvs/keras_tf/lib/python3.5/site-packages/keras/engine/topology.py", line 744, in compute_mask str(mask)) typeerror: layer permute_1 not support masking, passed input_mask: tensor("merge_2/all:0", shape=(?, 15), dtype=bool)

i went through thread says:

it small change in keras source code (set supports_masking class variable in lambda layer true instead of false). otherwise there isn't way this. masking isn't necessary though. 

where can set supports_masking variable true? also, there other solution this?


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -