AssertionError 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)
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)
21 assert np.allclose(avg, [0, 0]), “Average of no words must give an array of zeros”
Thank you @TMosh for you reply
I am still facing the error
avg =
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.
0. 0.]
AssertionError 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)
15 avg = target(“a a_nw c_w a_s”, word_to_vec_map)
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)”
AssertionError: Check that you are finding the 4 words
I have looped on words in for loop, used word_to_vec_map[w] in if for condition and calculated the average for word_to_vec_map[w]
Print statement is very helpful for debugging. Use print statement to print out what is in words, and check if your code is able to find those words in the word_to_vec_map. Also print the value for avg as each word is found.
Thank you @Kic for your reply
I have included the print statements before the if condition and for avg before and after computing. But still I am unable to find the issue.
AssertionError 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)
15 avg = target(“a a_nw c_w a_s”, word_to_vec_map)
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)”
AssertionError: Check that you are finding the 4 words
for w in words:
print(w)
# Check that word exists in word_to_vec_map
if w in word_to_vec_map[w]:
print(avg)
avg += word_to_vec_map[w]
print(avg)
# Increment count
count +=1
if count > 0:
# Get the average. But only if count > 0
avg = avg / len(words)
Hi @Kic
I am sorry I have changed the code but the same issue persists.
for w in words:
print(w)
# Check that word exists in word_to_vec_map
if w in word_to_vec_map[w]:
print(avg)
avg = avg + word_to_vec_map[w]
print(avg)
# Increment count
count = count + 1
print(count)
if count > 0:
# Get the average. But only if count > 0
avg = avg/count
Am I assigning the value avg wrong or wrong identations? I have used this for avg, Please suggest me here
avg = np.zeros(word_to_vec_map[any_word].shape)
Hi @Kic
Sorry, I have tried everything, even tried updating the latest version but nothing worked out. Still the same issue persists nothing has changed
Please help me
The input sentence has been broken up into words successfully. So there is no problem in that.
But what value did you get for avg and count when printed out?
Hi @Kic
Still the same error with no change, I mean even if I include any print statement inside the if statement it is not executing may be this is because the if condition is not getting satisfied so the statements inside the if condition are not executing. That’s what I understood, I may be wrong
If you move those print statements out, then you would be able to see what those values are.
I noticed your code is still using len of words which should be count
AssertionError 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)
15 avg = target(“a a_nw c_w a_s”, word_to_vec_map)
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)”
AssertionError: Check that you are finding the 4 words
Pro-tip: If anyone faces this issue even after going through all the related threads and doing everything correctly, write the whole code from scratch for this section yourself. The issue is somehow solved.
Solution:
In the for loop of “for w in words”, each “w” should be checked in the whole list of list(word_to_vec_map.keys()) not just in a single word(any_word). Therefore :
Replace:
for w in words:
if w in any_word:
To:
for w in words:
if w in list(word_to_vec_map.keys()):