AssertionError: Wrong values in outd
I got error at Exercise 8, class Transformer(tf.keras.Model):
Here is my error at last line of code. Please help me find error and fix this
call self.decoder with the appropriate arguments to get the decoder output
dec_output, attention_weights = self.decoder(tar, enc_output, training, look_ahead_mask, dec_padding_mask)
pass decoder output through a linear layer and softmax (~2 lines)
final_output = self.final_layer(dec_output) # (batch_size, tar_seq_len, target_vocab_size)
AssertionError Traceback (most recent call last)
in
63
64
â> 65 Transformer_test(Transformer)
in Transformer_test(target)
47 assert np.allclose(translation[0, 0, 0:8],
48 [[0.02664799, 0.02222014, 0.01641812, 0.02407483,
â> 49 0.04251551, 0.02240461, 0.01556584, 0.03741234]]), âWrong values in outdâ
50
51 keys = list(weights.keys())
AssertionError: Wrong values in outd
{mentor edit: the answer given is now obsolete}
1 Like
I have the same problem. Something is confusing: they request two Dense layers at the end, but only one is instantiated in the constructor. Also the comment in the code says â~2 lines of codeâ, so I added an additional Dense layer with linear activation (before the softmax):
final_output = Dense(dec_output.shape[-1], activation=âlinearâ)(dec_output)
final_output = self.final_layer(final_output) # (batch_size, tar_seq_len, target_vocab_size)
of course I tried with and without and in both cases I have the same error posted in this thread.
I did submit anyways as you suggested, and yes, I passed with 87% but the error is still there
TMosh
July 19, 2021, 1:24am
4
@carlosrv19 ,
I think you mis-read the instructions. Youâre not asked to add two Dense layers. The ~2 means âapproximately 2â lines of code, but you really only need one.
In total, you only add three lines of code in this function, and all of them are calls to methods defined in the constructor:
self.encoder(âŚ)
self.decoder(âŚ)
self.final_layer(âŚ)_
Thanks @TMosh . Yes, obviously I tried that before. Same result. I will check though.
TMosh
July 20, 2021, 11:06pm
7
I canât think of any good reason to use two lines of code there, since youâre given the exact function you need in the constructor.
I suspect the comment about using two lines is just wrong.
In my case the issue was caused by passing the wrong first parameter to self.decoder
. After correcting, issue was resolved
4 Likes
walrus
August 8, 2021, 3:09am
9
Thanks for the explanation
NN3
October 15, 2022, 9:12am
10
Isnât it required to pass the decoder output through a linear transformation layer before the Softmax layer, as per the architecture?
TMosh
October 18, 2022, 5:19am
11
Please identify which architecture youâre discussing specifically.
A screen capture image would be helpful, along with a reference to where you found it in the course materials.
NN3
October 18, 2022, 1:44pm
12
I am referring to the Transformer network architecture. Even in assignment, the figure shows linear layer followed by softmax layer.
TMosh
October 18, 2022, 2:23pm
13
Is this what youâre discussing? (screen capture from the assignment notebook):
TMosh
October 18, 2022, 2:32pm
14
Oh, I see, I missed your reference to âExercise 8â in the thread title.
So itâs this figure youâre referring to (at the red arrow):
Technically thatâs not part of the Decoder. Thatâs the top layer in the Transformer object.
Itâs referred to here in this cell, as part of the Transformer objectâs call() method.