C5 W1 A3: Jazz Improvisation with LSTM (Problem and Tips)

Hi @eag ,
Your case is misused python position argument. In python, if you are not sure function arguments orders or you don’t provide all arguments in order, you may want to use keyword argument rather than position argument.
Please take a look Step 2.A below, and use keyword argument if you can’t provide arguments in order.

1 Like

Hi @Thomas , @hafezgh ,
It looks like your model is different from what the assignment expected. One way to debug the problem is compare model architectures, you can print out models’ summary by:

print('my model:', summary(model))
print('expected model:', djmodel_out)

and check the different part.
According to your error message, I guess the difference is somewhere around Reshape layer. Please check Step 2.B:
image

The function has provided Reshape layer object for you, and expected to use it.
image

1 Like

Hi @Thomas , @hafezgh ,
Here is a clue for you.
image
To get the output y<t>, we apply Dense layer with softmax activation function on the LSTM hidden state a<t>. Please check if you implemented it in the same way.

2 Likes

How did you use RepeatVector function i.e syntax?

Can you explained that more plainly?, I have been studying linear algebra for a year and did a manual with the basics of python and I have managed to get to the fifth course but I do not have formal training as a computer scientist.

Hi @eag,
For instance, if we have a function:

def my_lstm(inputs, mask=None, training=None, initial_state=None):

If you only provide inputs and initial_state, you’ve to use keyword argument, like below.

    # [Wrong] it becomes mask=[a,b], others are default values
    my_lstm(x, [a, b])

    # [Correct]
    my_lstm(x, initial_state=[a, b])
1 Like

Like this a, _, c = LSTM_cell(x, initial_state[a, c]). It does not work either.

Thx! Problem solved!

Hi @eag ,
initial_state is not an variable, it’s a function argument. You can check here to see how to use keyword argument in python.

I had the same problem (i.e. TensorFlowOpLayer) and had to downgrade tensorflow to version 2.3.0 to solve this.

2 Likes

I have a complete different error:
Test failed
Expected value

 ['TensorFlowOpLayer', [(None,)], 0] 

 does not match the input value: 

 ['RepeatVector', (None, 1, 90), 0, 1]

I have exactly the same issue:
AttributeError: The layer “lstm” has multiple inbound nodes, with different output shapes. Hence the notion of “output shape” is ill-defined for the layer. Use get_output_shape_at(node_index) instead.

Any guesses on how to figure it out?

Many thanks

For djmodel(). check these common issues:

  • slicing X correctly.
  • using the “reshaper()” and “densor()” functions with the appropriate arguments.
  • used LSTM_cell() with the appropriate “inputs=” and “initial_state=[… ]” arguments.

For music_inference_model(), the common errors are:

  • Instruction 2.D tells you for argmax, use the arguments ‘out’ and ‘axis=-1’, and it says for onehot to use the arguments ‘x’ and ‘depth=n_values’.
  • Instruction 2.E gives you the exact code to use for RepeatVector.

For the inference_model = Model(…):

  • Step 3 says to use the initial values that were created earlier in the function. Those arguments go inside the square brackets. And use “outputs=outputs”.

For predict_and_sample()

  • In Step 2, use “axis=-1”.
  • In Step 3, use n_values for the number of classes.

========

After all that, if you still get an error about a layer having “multiple inbound nodes”, then try…

  1. save your notebook.
  2. go to the “Kernel” menu in the Notebook, and reset the kernel.
  3. then from the “Cell” menu, re-run all of the cells.

This often seems to clear errors that you’ve fixed but the kernel hasn’t noticed.

18 Likes

I have an error:

The layer "reshape" has multiple inbound nodes, with different output shapes. Hence the notion of "output shape" is ill-defined for the layer. Use get_output_shape_at(node_index) instead

Posting here in case someone will hit the same error.

And managed to solve it only after found this advice and then restarted the kernel and re-executed all the cells (without any modification to the code)

May be it’s worth noting in the notebook that one may need to re-run all cells in case of strange errors.

7 Likes

+1 to restarting kernel and rerunning all the cells :smiley:

9 Likes

If u can check the above few cell with respect to this code u will see reshaper(x) which reshape the matrix into (1,90) not reshapor.

Hello,

I appear to be getting a unique error from the rest of the comments on this page with code below.

{moderator edit - solution code removed}

It shows “TypeError: int() argument must be a string, a bytes-like object or a number, not ‘NoneType’”

check this line. in above cell u can see it function is to reshape the list in 1,90 shape. Call reshaper in correct format. Hint: assign the value of reshaper(x) in variable.

1 Like

Myself as well. Very frustrating to spend all that time debugging when the code is correct! I recommend others to do this as well.

1 Like

Hi @Dalkhat ,
I am also facing the same issue. It would be great if you could share the solution.
Thanks.