0

I am facing an error while taking Input where Embedding is my first layer. It is unable to find the tensor of shape (,9) although I have clearly mentioned the shape in Input(). Can someone help me out of this?

Code is as follows:

def model_3(src_vocab, tar_vocab, src_timesteps, tar_timesteps, n_units):

    _nput = Input(shape=[src_timesteps], dtype='int32')
    embedding = Embedding(input_dim = src_vocab, output_dim = n_units, input_length=src_timesteps, mask_zero=False)(_nput)
    activations = LSTM(n_units, return_sequences=True)(embedding)
    attention = Dense(1, activation='tanh')(activations)
    attention = Flatten()(attention)
    attention = Activation('softmax')(attention)
    attention = RepeatVector(tar_timesteps)(attention)
    activations = Permute([2,1])(activations)
    sent_representation = dot([attention,activations], axes=-1)
    sent_representation = LSTM(n_units, return_sequences=True)(sent_representation)
    sent_representation = TimeDistributed(Dense(tar_vocab, activation='softmax'))(sent_representation)
    model = Model(input=_nput,output=sent) 
    model.compile(optimizer='adam', loss='categorical_crossentropy')
    print(model.summary())
    plot_model(model, to_file='model.png', show_shapes=True)
Matus Dubrava
  • 13,637
  • 2
  • 38
  • 54
  • Hello! Does your question answer this?https://stackoverflow.com/questions/46155868/keras-embedding-layer –  Dec 20 '19 at 13:14
  • No actually. I understood the post, but isn't giving clarity in this particular problem. The Error I am getting is as follows: ValueError: Graph disconnected: cannot obtain value for tensor Tensor("input_15:0", shape=(?, 9), dtype=int32) at layer "input_15". The following previous layers were accessed without issue: [] – Ritam Majumdar Dec 20 '19 at 13:22
  • ```model = Model(input=_nput,output=sent) ``` what is ```sent``` it is not there in your code? If you meant ```sent_representation``` this code is not throwing any error. Please post your full error trace. – Vivek Mehta Dec 20 '19 at 13:36
  • Got the error. I wrote "input" instead of "inputs" while creating the model, hence the whole input fiasco. Also, I meant sent_representation. – Ritam Majumdar Dec 22 '19 at 03:14
  • Try to change the shape in the Input layer like: `shape=(src_timesteps,)` . Pay attention to the comma inside the tuple. – Aris F. Dec 22 '19 at 09:13

0 Answers0