Help: Error in helper file won't allow me to complete the assignment - Emojify

Below are the particulars of the error(s):
Course: Sequence Models
Week: 2
Assignment: Emojify (2nd assignment)
Error origination file: ~/work/W2A2/emo_utils.py
Error type: AttributeError
Error message: ‘list’ object has no attribute ‘shape’
First occurrence: Function - model_test
Second occurence: Cell after Function - pretrained_embedding_layer_test

This most likely means the error is in your model() function, or one of the other functions that model() uses - such as sentence_to_avg() - or the arguments you’re passing to sentence_to_avg().

Thank you for your response *@*TMosh. I’ve followed the instructions and believe my code meets them. My functions have passed the unit tests. I have uploaded the work file along with the screenshots of the functions and their outputs.

Function: Sentence to Average

{moderator edit - solution code removed}

Error Screenshot: Next line

{moderator edit - solution code removed}

I got around the issue by converting variable n_h into a numpy array in the function model.
Since I do not have access to the helper file emo_utils.py, I cannot do the same there.

File: emo_utils.py (unmodifiable)
Function: Predict

I believe the issue originates here.

Sorry, but the issue originates in the fact that you added this cell to the notebook:


That has the effect of resetting the global definition of the word_to_vec_map dictionary in a way that makes the dictionary entries python lists, when they should be numpy arrays.

That is the instance that is used by the cell that is failing when you run the model function.

Notice that in the various test cases where they do something similar to your added cell, they then postprocess the dictionary entries to make them numpy arrays.

1 Like

Thank you for your response @paulinpaloalto. I removed the conversion to a numpy array and it worked. Thank you.

1 Like