Course 5 Week 2 Emojify Exercise 1 Problem

Hi guys,

I have a problem with exercise 1. When I compute the average of the word vector, I get this error.

What I do is that I loop over the number of words in a sentence and then, if the word is found in the dictionary, I add its vector representation to avg. But I get this error

ValueError: operands could not be broadcast together with shapes (50,) (2,) (50,)

Could someone help me please? :sweat_smile: I’ve been trying to figure this out for hours.


Hi, I have the same problem in this exercise. Do you figure it out?

Same issue. Need help

Hi, I got the same problem… still stuck. Can someone help out?


Hey guys, I was getting the error because I was incorrectly initializing the average word vector. That’s why the test crashed.

1 Like

@tischroe I think I might have a similar issue. Can you help me with proper initialization of average word vector

@kumarsaurabh sure! You need to initialize the average word vector avg with zeros. The mistake I made was to hardcode the shape (50) instead of using a variable.
So you need to initialize the average word vector with word_to_vec_map[any_word].shape.


Hi tischroe, thanks for your reply. Do you mean that np.zeros((50,)) is not correct?

Also, for the avg I run this code , but I do not what’s the problem here. Would do pleas help me?

if count > 0:
# Get the average. But only if count > 0
avg = avg / len(words)

AssertionError: Divide between count not len(words

@simamh Hi! Yes I thought it was but it isn’t. I guess this is the problem with the assert statements in the test unit. You just need to use the shape property on the word_to_vec_map[any_word] dictionary.


Also I made that mistake of dividing by len and not count. This is why I got this error.

tischroe Many thanks I passed the test

Great news! You’re welcome :slight_smile:

Hi! I cannot pass this test. Could you show how you use word_to_vec_map[any_word].shape?

Thank you very much! I passed the test!

can you help me out how to do it?
I’ve initialized avg as the shape of word_to_vec_map[any_word].shape yet it gives me an error stating float’ object has no attribute ‘shape’ .

Hi @ish-kumar,

you can use:

Hi. I fixed the shape but still doesn’t work :frowning: is there anything wrong in this last part??

for w in words:
        if w in word_to_vec_map:
            avg += word_to_vec_map[w]
            count +=1

    if count > 0:
        avg = avg / count

Hi @keks1208,

The statement for accessing the vector is incorrect.

As word_to_vec_map is a dictionary object with ‘key to value’ pairing; so, to access the values of the word vector, it needs to be called as follows:


where w contains the word, and the word_to_vec_map.get() would return the vector of that word containing the values.

1 Like

@Kic Hi, thanks for your advice. However, I am still getting the same error :frowning:
The error is ‘check that you are finding the 4 words’.

Hi @keks1208 ,

That is an assertion error from the testcase. You need to check the logic of your code. Print statement is very helpful in debugging. Drop a few of those print statements to see if you could track and isolate the problem.

1 Like