Exercise 3 of DLS C5, week 1 assigned programming 3

After using prediction to calculate pred, the shape of pred is always (1,90), not (1, T_y, n_values) as expected. Where is my mistake?2024-11-19T16:00:00Z

Please note that we can’t see your notebook, but please don’t publish your code here. Let’s try to debug this by showing the output we get.

If you mean the predict_and_sample function in the Jazz Improvisation assignment, I added some print statements to my code to show the shapes of various objects and here’s what I get when I run the test cell for that function:

len(pred) = 50
type(pred) = <class 'list'>
indices.shape = (50, 1)
results.shape = (50, 90)
np.argmax(results[12]) = 61
np.argmax(results[17]) = 7
list(indices[12:18]) = [array([61]), array([81]), array([21]), array([39]), array([54]), array([7])]

How does that compare to what you are getting?

My result is quite different from yours, as blow:
shape of pred: (1, 90)
length of pred: 1
type of pred: <class ‘numpy.ndarray’>

How would you propose me to make it right?

Well, some debugging will be required. I calculated the pred value by invoking the “predict()” method of the inference_model that was defined earlier. Maybe you did that in a different way.

What are the actual values you got for the indices? Please show the full output you get from running that cell that calls predict_and_sample.

As the length of pred is wrong as 1, not 50, the calculation for the indices can’t continue at all. The root cause is with coding about using predict(). But I don’t know how to make it right. I just copied the codes from the hints in Step 1 of Exercise 3-predict_and_sample. Did I miss something important?

Maybe it’s time to just look at your code. We can’t do that here on a public thread, but please check your DMs for a message from me about how to proceed with that.