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? I’ve been trying to figure this out for hours.
@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.
@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.
Hey!
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’ .
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.