UNQ_C1 : djmodel - Ex 2 in Week 1



After this function, which returns ‘model, the variable, ’model’ is assigned as :
model = djmodel(Tx=30, LSTM_cell=LSTM_cell, densor=densor, reshaper=reshaper)

Now, when the next unit, ‘#Unit Test’ is run, I get this in the output:

Test failed at index 1
Expected value

[‘TensorFlowOpLayer’, [(None, 90)], 0]

does not match the input value:

[‘Lambda’, (None, 90), 0]

AssertionError Traceback (most recent call last)
2 output = summary(model)
----> 3 comparator(output, djmodel_out)

~/work/W1A3/test_utils.py in comparator(learner, instructor)
24 “\n\n does not match the input value: \n\n”,
25 colored(f"{b}", “red”))
—> 26 raise AssertionError(“Error in test”)
27 print(colored(“All tests passed!”, “green”))

AssertionError: Error in test

The next unit,
“# Check your model
model.summary()” , however, runs and gives an ‘expected’ output.
And the trouble is that after compiling and initialising the hidden state and cell state, the code for ‘training the model’:
history = model.fit([X, a0, c0], list(Y), epochs=100, verbose = 0),
Does not succeed, and ‘history’ is ‘not defined’.

QUESTION: Has djmodel been correctly done?

It sounds like something is wrong with your djmodel. I would start by investigating the first error about the unexpected Lambda function. For starters, are you sure you are running this on the course website and not in some local environment? If the latter, there are never any guarantees because of “versionitis” problems.

Also it might shed some light if you showed us the actual exception trace you get from running the model.fit cell.

Hi @Anantha ,

There is problem with your djmodel() code. The assertion error is raised because the two arguments for comparator(), output and djmodel_out did not match during test. So, you need to check the ‘For’ loop within the djmodel() and make sure the correct parameters are passed.

Dear Paul,
thanks for your reply. I started a new instance, and djmodel works- the unit test and model.summary, with no errors. Optimies, with Adam and model.compile, initialise, train and history - work fine, loss dropping from 29.xxx to 6.xxx, and the descending plot.
The problem is now with the ‘inference model’.
As parameters of LSTM_cell, I have used (x,[a,c]), ‘out’ comes from densor(a) and to ‘outputs’, i append ‘out’. ‘x’ is the maximum from ‘out’, using argmax and with tf.one_hot, I have tried with (x,n_values) as well as (x,90). And the parameter for RepeatVector(1) is x, it should convert x, which is (None,90) to (None,1,90).
However, there an error, which ends with:
" ValueError: Graph disconnected: cannot obtain value for tensor Tensor(“input_3:0”, shape=(None, 1, 90), dtype=float32) at layer “lstm”. The following previous layers were accessed without issue: "
While I am ‘following instructions’, the internals of what is going on is quite unclear!
Request help, and some resource to help me understand.

Hi @Anantha

When creating the inference_model instance, the inputs should be [x0,a0, c0].

Thank you.
I had used [x0, a0,c0] as input, but, as it did not work, I shifted to [x,a0,c0] in view of the instruction:

model = Model(inputs=[input_x, initial_hidden_state, initial_cell_state], outputs=the_outputs)
Now, again with input as [x0,a0,co], i get this attribute error:

It should be c0, not co.

Yes, of course, sir, a typo in the mail. But c0 I the code

No mistake in the code. It was c0. The mistake was in my mail.
Kindly respond to the question

For creating the inference_model instance:
inteference_model = Model(inputs=[x0,a0,c0], outputs=outputs)

What attribute error did you get when your input is set to [x0,a0,c0]?


This is the attribute error:

Hi @Anantha

Could you post the code for music_inference_model() in a direct message to me, I’ll have a look for you.

Where do I find your direct email, please?

If you click on my icon, a dialogue box will appear, and you should find a blue ‘message’ box on the top right corner.

Dear Kin,
hope you received the direct message

Hi @Anantha ,

I have not received your direct message. How did you send it?

I used the “message” and the “email” prompts seen on clicking your icon. Shall they again