I am having trouble in 'jazz Improvisation with LSTM" exercise no 3

hello everyone. I am having trouble in 'jazz Improvisation with LSTM" exercise no 3
The step 2d States this:
Convert the last output into a new input for the next time step. You will do this in 2 substeps:
Get the index of the maximum value of the predicted output using tf.math.argmax along the last axis.
Convert the index into its n_values-one-hot encoding using tf.one_hot .

My code for that step is:

x = tf.math.argmax(out,axis = ?)
x = tf.one_hot(x)

I am having trouble to set the last axis to which i get the following error:

“Attempt to convert a value (<tensorflow.python.keras.layers.core.Dense object at 0x7f153e5fd2d0>) with an unsupported type (<class ‘tensorflow.python.keras.layers.core.Dense’>) to a Tensor.”

1 Like

Remember that selecting the last index in Python can be done by using -1 (as opposed to 0, 1, 2, 3, ... or whatever the last index might be when counting from 0 and up).

For the tf.one_hot() call, I suggest you search other posts in this forum for the depth parameter. That definitely helped me in solving the Assignment :wink:

Thankyou very much i tried using -1 already but still i get the same error at that line

Hi Mohit,

It looks like you pass Dense layer object to tf.math.argmax function. I guess you misunderstood the function parameters denseor:

def music_inference_model(LSTM_cell, densor, Ty=100):

densor is a layer object rather than value. To get its output, you’ve to use it like function call, e.g., densor(some_val)

Thankyou for taking time and helping me solve the problem was really helpful :slightly_smiling_face: