TypeError: one_hot() missing 1 required positional argument: 'depth' { DLS Course -5 Week-1 Assignment - Jazz Improvisation with LSTM }

Hi, I am getting Error TypeError: one_hot() missing 1 required positional argument: ‘depth’ while executing the music_inference_model function can someone please correct me where I am wrong. Below is my function.

# GRADED FUNCTION: music_inference_model

def music_inference_model(LSTM_cell, densor, Ty=100):
    Uses the trained "LSTM_cell" and "densor" from model() to generate a sequence of values.
    LSTM_cell -- the trained "LSTM_cell" from model(), Keras layer object
    densor -- the trained "densor" from model(), Keras layer object
    Ty -- integer, number of time steps to generate
    inference_model -- Keras model instance
    # Get the shape of input values
    n_values = densor.units
    # Get the number of the hidden state vector
    n_a = LSTM_cell.units
    # Define the input of your model with a shape 
    x0 = Input(shape=(1, n_values))
    # Define s0, initial hidden state for the decoder LSTM
    a0 = Input(shape=(n_a,), name='a0')
    c0 = Input(shape=(n_a,), name='c0')
    a = a0
    c = c0
    x = x0

    ### START CODE HERE ###
    # Step 1: Create an empty list of "outputs" to later store your predicted values (≈1 line)
    outputs = []
    # Step 2: Loop over Ty and generate a value at every time step
    for t in range(Ty):
        # Step 2.A: Perform one step of LSTM_cell (≈1 line)
        a, _, c = LSTM_cell(x, initial_state=[a, c])
        # Step 2.B: Apply Dense layer to the hidden state output of the LSTM_cell (≈1 line)
        out = densor(a)

        # Step 2.C: Append the prediction "out" to "outputs". out.shape = (None, 78) (≈1 line)

        index = tf.math.argmax(out,axis=-1) 
        x = tf.one_hot(index)
        x = RepeatVector(1)(x)
    # Step 3: Create model instance with the correct "inputs" and "outputs" (≈1 line)
    inference_model = Model(inputs=[x0, a0, c0], outputs=outputs)
    ### END CODE HERE ###
    return inference_model

inference_model = music_inference_model(LSTM_cell, densor, Ty = 50)


1 Like

Which week?
Which assignment?

Hi Sir,

It is DLS Course -5 (Sequence model), Week -1 , Assignment - Jazz Improvisation with LSTM.


The one_hot layer requires that you pass it a “depth=…” parameter. There is a hint in the second bullet item in instructions 2.D.

1 Like

Thanks Sir,

Resolved it.

1 Like

@TMosh There’s no hint in the newest version of this assignment. I have to look at the older version to get it.

Yes, the hint is still there. I have highlighted it in this excerpt:


@TMosh Ok. I didn’t read that carefully. Thank you. But I think the hint in the previous version is clearer for beginner like me.

1 Like

the depth is n_values

I was able to get the right answer thanks to this thread, but can someone please explain to me what we’re doing with this one-hot encoding and what the depth parameter is doing?

To be clear, I understand what a one-hot encoding is, but i’m not sure what these steps are doing.