in complete_analogy(word_a, word_b, word_c, word_to_vec_map)
21 ### START CODE HERE ###
22 # Get the word embeddings e_a, e_b and e_c (≈1-3 lines)
—> 23 e_a, e_b, e_c = word_to_vec_map[“a”], word_to_vec_map[“b”], word_to_vec_map[“c”]
24 ### END CODE HERE ###
25
In you call to word_to_vec_map, you are passing hard coded value to the function. It should be the input parameters to the function complete_analogy(), ‘word_a’, ‘word_b’ and ‘word_c’.
Many thanks sir. this really helped. however , on the cosine-similarity i did; cosine_sim = cosine_similarity(e_b - e_a, w - e_c) but i have the error below;
—> 39 cosine_sim = cosine_similarity(e_b-e_a, e_w-e_c)
40
41 # If the cosine_sim is more than the max_cosine_sim seen so far,
TypeError: unsupported operand type(s) for -: ‘list’ and ‘list’
in complete_analogy(word_a, word_b, word_c, word_to_vec_map)
39 ### START CODE HERE ###
40 # Compute cosine similarity between the vector (e_b - e_a) and the vector ((w’s vector representation) - e_c) (≈1 line)
—> 41 cosine_sim = cosine_similarity(e_b-e_a, word_to_vec_map[w]-e_c)
42
43 # If the cosine_sim is more than the max_cosine_sim seen so far,
TypeError: unsupported operand type(s) for -: ‘str’ and ‘str’
cosine_similarity() is defined to have 2 input vectors, but your code didn’t reflect that. To make it into vector, just add a pair of bracket to each of the parameters. Here is what it would look like:
cosine_similarity((e_b-e_a), (word_to_vec_map[w]-e_c))