Open SuryaVikram opened 3 years ago
Hello, thank you for sharing this.
I am getting this error when am trying to run this in Colab "ValueError: The first argument to Layer.call must always be passed."
Layer.call
This is my model code: from attention import AttentionLayer
from keras import backend as K K.clear_session() latent_dim = 100 embedding_dim=100
encoder_inputs = Input(shape=(max_len_text,)) enc_emb = Embedding(x_voc_size, latent_dim,trainable=True)(encoder_inputs)
encoder_lstm1 = LSTM(latent_dim,return_sequences=True,return_state=True) encoder_output1, state_h1, state_c1 = encoder_lstm1(enc_emb)
encoder_lstm2 = LSTM(latent_dim,return_sequences=True,return_state=True) encoder_output2, state_h2, state_c2 = encoder_lstm2(encoder_output1)
encoder_lstm3=LSTM(latent_dim, return_state=True, return_sequences=True) encoder_outputs, state_h, state_c= encoder_lstm3(encoder_output2)
decoder_inputs = Input(shape=(None,)) dec_emb_layer = Embedding(y_voc_size, latent_dim,trainable=True) dec_emb = dec_emb_layer(decoder_inputs)
decoder_lstm = LSTM(latent_dim, return_sequences=True, return_state=True) decoder_outputs,decoder_fwd_state, decoder_back_state = decoder_lstm(dec_emb,initial_state=[state_h, state_c])
attn_layer = AttentionLayer(name='attention_layer') attn_out, attn_states = attn_layer()([encoder_outputs, decoder_outputs])
decoder_concat_input = Concatenate(axis=-1, name='concat_layer')([decoder_outputs, attn_out])
decoder_dense = TimeDistributed(Dense(y_voc_size, activation='softmax')) decoder_outputs = decoder_dense(decoder_outputs)
model = Model([encoder_inputs, decoder_inputs], decoder_outputs) model.summary()
Please advice if I am missing something, thank you
attn_layer() - Should you have () here?
Hello, thank you for sharing this.
I am getting this error when am trying to run this in Colab "ValueError: The first argument to
Layer.call
must always be passed."This is my model code: from attention import AttentionLayer
from keras import backend as K K.clear_session() latent_dim = 100 embedding_dim=100
Encoder
encoder_inputs = Input(shape=(max_len_text,)) enc_emb = Embedding(x_voc_size, latent_dim,trainable=True)(encoder_inputs)
LSTM 1
encoder_lstm1 = LSTM(latent_dim,return_sequences=True,return_state=True) encoder_output1, state_h1, state_c1 = encoder_lstm1(enc_emb)
LSTM 2
encoder_lstm2 = LSTM(latent_dim,return_sequences=True,return_state=True) encoder_output2, state_h2, state_c2 = encoder_lstm2(encoder_output1)
LSTM 3
encoder_lstm3=LSTM(latent_dim, return_state=True, return_sequences=True) encoder_outputs, state_h, state_c= encoder_lstm3(encoder_output2)
Set up the decoder.
decoder_inputs = Input(shape=(None,)) dec_emb_layer = Embedding(y_voc_size, latent_dim,trainable=True) dec_emb = dec_emb_layer(decoder_inputs)
LSTM using encoder_states as initial state
decoder_lstm = LSTM(latent_dim, return_sequences=True, return_state=True) decoder_outputs,decoder_fwd_state, decoder_back_state = decoder_lstm(dec_emb,initial_state=[state_h, state_c])
Attention Layer
attn_layer = AttentionLayer(name='attention_layer') attn_out, attn_states = attn_layer()([encoder_outputs, decoder_outputs])
Concat attention output and decoder LSTM output
decoder_concat_input = Concatenate(axis=-1, name='concat_layer')([decoder_outputs, attn_out])
Dense layer
decoder_dense = TimeDistributed(Dense(y_voc_size, activation='softmax')) decoder_outputs = decoder_dense(decoder_outputs)
Define the model
model = Model([encoder_inputs, decoder_inputs], decoder_outputs) model.summary()
Please advice if I am missing something, thank you