# Jazz improvisation notebook: issue with predict_and_sample

So according to cell 3: We have n_values=90 and T_y=30

Everything up to the cell for “Predict and sample” works and passes its test.

However, the inference model seems to output predictions of the wrong size:

``````    ### START CODE HERE ###
# Step 1: Use your inference model to predict an output sequence given x_initializer, a_initializer and c_initializer.
pred = inference_model.predict([ x_initializer, a_initializer, c_initializer])
# Step 2: Convert "pred" into an np.array() of indices with the maximum probabilities
print(pred.shape)
print(pred[0].shape)
``````

output is:

``````(1, 90)
(90,)
``````

This is not what you’re supposed to get according to step 1. What am I doing wrong? Could my model be wrong while still passing tests?

When I use your “print(pred.shape)” test, I get an attribute error:
AttributeError: ‘list’ object has no attribute ‘shape’

I had to use print(np.shape(pred)) to get the shape to display with my code.

There may be a problem with your music_inference_model() function.

print(np.shape(pred))
This gave me (50, 1, 90)

print(np.shape(pred[0]))
This gave me (1, 90)

Here’s my inference model…

``````# 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. Use "x", not "x0" (≈1 line)
a, _, c = LSTM_cell(inputs=x,initial_state=[a,c])

# Step 2.B: Apply Dense layer to the hidden state output of the LSTM_cell (≈1 line)
out = densor(c)
# Step 2.C: Append the prediction "out" to "outputs". out.shape = (None, 90) (≈1 line)
outputs.append(out)

# Step 2.D:
# Select the next value according to "out",
# Set "x" to be the one-hot representation of the selected value
# See instructions above.
x = tf.math.argmax(out, axis=-1)
x = tf.one_hot(x, depth=n_values)
# Step 2.E:
# Use RepeatVector(1) to convert x into a tensor with shape=(None, 1, 90)
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=out)``````

In the end of the function music_inference_model you create a model inference_model, the last argument model should be outputs not out
this worked for me hopefully it will work for you

``````inference_model = Model(inputs=[x0, a0, c0], outputs=outputs)
``````
1 Like

Hi @incenate ,

The problem is in step 2. It should be the hidden state, a, to be passed to densor(), not c.