Week1 Assignment 3 UNQ_C2

Hello I’ve followed the instructions and can’t figure out why m code doesn’t work. Below is the error message, please take a look, thank you.

Hi @Qingyang_Li ,

You got wrong in shaping your input. Let me give you a hint. Try reshaping your input data. Create a new code cell and check shape of your data and then after checking make sure you don’t do that in a cell which is used for grading. Check the expected shape and reshape it accordingly.

I think this should solve your query. If any more doubts please ask.

Regards,
Harsh Der

Your invocation of LSTM_cell looks correct to me, so as Harsh says, the problem must be that the inputs to do not have right shape. They gave you the definition of the reshaper function and the comments in the template code indicate where to apply it. Please give the instructions and the comments in the template code another careful read through and see if that helps.

Hello Paul:
Thanks for replying. The template for question 2 does not have a reshaper spot but I’ve added it to the invocation as _, a, c = LSTM_cell(inputs = reshaper(x), initial_state=[a, c])
it still gives the same error.

Here’s is what the template code looks like:

    # Step 2: Loop over tx
    for t in range(None):
        
        # Step 2.A: select the "t"th time step vector from X. 
        x = None
        # Step 2.B: Use reshaper to reshape x to be (1, n_values) (≈1 line)
        x = None
        # Step 2.C: Perform one step of the LSTM_cell
        a, _, c = None
        # Step 2.D: Apply densor to the hidden state output of LSTM_Cell
        out = None
        # Step 2.E: add the output to "outputs"
        None

See the comment there about reshaper? Of course your method should also work. Are you sure you actually clicked “Shift-Enter” on the function after you changed it? If you don’t do that, it just runs the old code again. Here’s a thread which talks about how the notebooks work.

Hi Paul:
I believe that is the template for question 1 because it is looping over Tx. Maybe I accidentally deleted the reshaper layer part of the comment in question 2?
But let me check the input shape again and see if I can get it to work. Thanks.

Oh, sorry, I didn’t notice that you were on question 2. In that case, they give you the shape in the initialization, right? So you don’t need to call reshaper, but I’ll bet what is happening is that you fail on the second iteration of the for loop. In other words, the rest of your code in the loop after the LSTM_cell must not correctly format x, so you fail the second time through.

Instead of printing x, try this right before the call to LSTM_cell:

print(f"x.shape {x.shape}")

If my theory is right, you’ll see it correct the first time, then incorrect the second time, followed by the exception getting thrown. But at least now you know where to look for the mistake.

Hi Paul:
I got the inistantiation cell (cell 95) to run but in the summary cell I am getting another error:


So confused that I think I understand what is going on but I can’t get it right.

It means your implementation of music_inference_model is incorrect. Please compare your code with the instructions given to you.

RIght! In particular pay attention to the inputs you specified for LSTM_cell and the shapes of those objects. The error message is pretty clear that the shapes do not match.

I think my mistake was I used the wrong shape for the x_one_hot, I was able to get credit after I changed it. Thanks for helping me out.