Kindly help am getting the following error in the sentence_to_avg(sentence, word_to_vec_map) function in Course 5 Week 2 Assignment.
operands could not be broadcast together with shapes (50,) (2,) (50,) ',)
Kindly help am getting the following error in the sentence_to_avg(sentence, word_to_vec_map) function in Course 5 Week 2 Assignment.
operands could not be broadcast together with shapes (50,) (2,) (50,) ',)
I guess you might hard-code avg shape with 50, or use constant value 50 somewhere. Although the function comments say its return value avg is a ânumpy-array of shape (50,)â, you should use the shape of any word vector in word_to_vec_map. Because anyone call this function may pass in different arguments, just like the unit test in exercise.
Try starting your avg variable with this:
avg = np.zeros(word_to_vec_map[any_word].shape)
it got rid of that error for me. Now i am dealking with a bug in the auto grader. The notebook says everything is correct, but im not getting any points from the auto gradder
Hi dbiber.
I tried your method and got the right answerďź but why canât I use âwords[0]â instead of âany_wordâ. If i do that i will get the following error message.
*avg = *
KeyError Traceback (most recent call last)
in
25 print(â\033[92mAll tests passed!â)
26
â> 27 sentence_to_avg_test(sentence_to_avg)
28
29 # END UNIT TEST
in sentence_to_avg_test(target)
16 assert tuple(avg.shape) == tuple(word_to_vec_map[âaâ].shape), âCheck the shape of your avg arrayâ
17 assert np.allclose(avg, [1.25, 2.5]), âCheck that you are finding the 4 wordsâ
â> 18 avg = target(âlove a a_nw c_w a_sâ, word_to_vec_map)
19 assert np.allclose(avg, [1.25, 2.5]), âDivide by count, not len(words)â
20 avg = target(âloveâ, word_to_vec_map)
in sentence_to_avg(sentence, word_to_vec_map)
22
23 # Initialize the average word vector, should have the same shape as your word vectors.
â> 24 avg = np.zeros(word_to_vec_map[words[0]].shape)
25
26 # Initialize count to 0
KeyError: âloveâ
Hello Lijiang,
Please look at the implementation that you are try to do for:
#Initialize the average word vector, should have the same shape as your word vectors.
So, it should have the use of âany_wordâ in it.
I know that is not very clear from the given statement in the notebook that instructed you- âWhen creating the avg array of zeros, youâll want it to be a vector of the same shape as the other word vectors in the `word_to_vec_mapâ, but you need to make that out from the statement.
I will ask the staff to make this statement more clear for future references as I can see you all struggling to find the real solution.