C5W1: Jazz music generation, function "music_inference_model"


All previous tests are passed, and I think my code is correct. I read some topics regarding problems with dimensions, but they did not fix my problem.

tf.math.argmax (x = tf.math.argmax(x,axis=-1)) is not returning the dimensions it should and I do not understand why:

after argmax: (None, 1) , must be (None,)
after one_hot: (None, 1, 90) , must be (None, 90)

Since the “1” gets added, the function raises the following error in the line “x = RepeatVector(1)(x)”:

ValueError: Input 0 of layer repeat_vector is incompatible with the layer: expected ndim=2, found ndim=3. Full shape received: [None, 1, 90]

What might be incorrect?

Kind regards,


Hi, @Sara_Valiente!

Try with tf.squeeze, as it is shown in the Tensorflow documentation.

I think that tf.squeeze(output, 1) should return what you want in the one-hot encoding vector

Hello @alvaroramajo!

Thank you for your help; I inserted the tf.squeeze in the argamax argument instead, since I think that was the root of the problem, and now the function appears to be working well. However, I still get an error one cell after, in the comparator. Any clue why that might be happening?

I’ll paste my code for clarity.

{moderator edit - solution code removed}

Thank you in advance!


@Sara_Valiente please check what size does x variable have before RepeatVector(1) and try to use tf.squeeze there to get the tensor size you want

tf.squeeze() is not needed in this assignment.

The problem is you’re using the wrong parameter when you call tf.math.argmax().
The instructions say:
# Select the next value according to "out",

That was it! What a silly mistake. Thank you both @alvaroramajo @TMosh!!