Stuck on predict_and_sample(), Q3 in Jazz Improvisation with LSTM

{moderator edit - solution code removed}

(upload://45FyPOclOXE3tmq8dQhnvFhTswJ.jpeg)
I’ve been working on this function (predict_and_sample) for a few hours now… would appreciate some help passing the testcase.

The first step in debugging is always to understand what the error is telling you. In this case it is telling you that your results value is the wrong shape. So the first question is “what shape is it?” Then the next question is “how did it get that way?” :nerd_face:

Notice that they tell you in the comments for Step 3 what the shape should be. So what shape did you actually get?

For reference, here’s what I see as the output of that test cell with some “telltale” print statements added to my function:

len(pred) = 50
indices.shape = (50, 1)
results.shape = (50, 90)
np.argmax(results[12]) = 0
np.argmax(results[17]) = 62
list(indices[12:18]) = [array([0]), array([33]), array([18]), array([69]), array([49]), array([62])]
1 Like

My code looks pretty much the same as yours, although you ignored the comment about converting pred to a numpy array before doing “argmax” on it. But I tried doing it your way and I still get the same answers. So I think this leaves us with the theory that it’s your model that is incorrect. Have you checked all the previous tests in the notebook to make sure everything is cool with the earlier code? Although we have seen cases in other notebooks in which the unit tests don’t catch everything …

1 Like

Thank you so much Paul! I just solved it with your help. Turns out it was a previous function, which was returning the last output rather than the list of outputs as a whole.

It’s great that you found the problem. Did the previous function that caused the problem still pass its test case with the bug you found? If so, we should beef up the test cases. If it passed the tests, please let me know which function it was so I can duplicate your results. Thanks!

Yes, the function still passed. It was when I made “outputs=out” in djmodel(). Hope that helps!