C5W2A2: Emotify v2 model failed, output doesn't match expected

Hello all, I am unsure what exactly happened here. Even as I successfully setup the LSTM layer

X = LSTM(units = 128, return_sequences=True)(embeddings)

the output of my model shows up to be dense and linear (the default from tf website is tanh).

Any clues as to why this might be the case? Any suggestion is appreciated.

Test failed 
 Expected value 

 ['LSTM', (None, 128), 131584, (None, 4, 128), 'tanh', False] 

 does not match the input value: 

 ['Dense', (None, 4, 128), 16512, 'linear']
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-100-6d1e00d1aa10> in <module>
     22 
     23 
---> 24 Emojify_V2_test(Emojify_V2)

<ipython-input-100-6d1e00d1aa10> in Emojify_V2_test(target)
     19 
     20     expectedModel = [['InputLayer', [(None, 4)], 0], ['Embedding', (None, 4, 2), 30], ['LSTM', (None, 4, 128), 67072, (None, 4, 2), 'tanh', True], ['Dropout', (None, 4, 128), 0, 0.5], ['LSTM', (None, 128), 131584, (None, 4, 128), 'tanh', False], ['Dropout', (None, 128), 0, 0.5], ['Dense', (None, 5), 645, 'linear'], ['Activation', (None, 5), 0]]
---> 21     comparator(summary(model), expectedModel)
     22 
     23 

~/work/W2A2/test_utils.py in comparator(learner, instructor)
     21                   "\n\n does not match the input value: \n\n",
     22                   colored(f"{a}", "red"))
---> 23             raise AssertionError("Error in test")
     24     print(colored("All tests passed!", "green"))
     25 

AssertionError: Error in test

If you could create a model successfully, its layer should be like this.

['InputLayer', [(None, 10)], 0],
 ['Embedding', (None, 10, 50), 20000050],
 ['LSTM', (None, 10, 128), 91648, (None, 10, 50), 'tanh', True],
 ['Dropout', (None, 10, 128), 0, 0.5],
 ['LSTM', (None, 128), 131584, (None, 10, 128), 'tanh', False],
 ['Dropout', (None, 128), 0, 0.5],
 ['Dense', (None, 5), 645, 'linear'],
 ['Activation', (None, 5), 0]]

The error is 5th layer (4th in Python), 2nd LSTM layer. In you case, Dense is there instead. Please double check your model with summary(model) or model.summary().

Just one addition… In the test, comparator checks with the following layers. Since parameters to create a model is slightly different, some parameters are different. But, basic layer structure is same.

[['InputLayer', [(None, 4)], 0],
 ['Embedding', (None, 4, 2), 30],
 ['LSTM', (None, 4, 128), 67072, (None, 4, 2), 'tanh', True],
 ['Dropout', (None, 4, 128), 0, 0.5],
 ['LSTM', (None, 128), 131584, (None, 4, 128), 'tanh', False],
 ['Dropout', (None, 128), 0, 0.5],
 ['Dense', (None, 5), 645, 'linear'],
 ['Activation', (None, 5), 0]]

[ For debugging ]

If you run cells sequentially, there is a chance that model is not created at that time. So, neither model.summary nor summary(model) may work. In that case, you may want to “temporary” create a model to check layers with;

model = Emojify_V2((maxLen,), word_to_vec_map, word_to_index)

Thanks a lot! Problem solved