DLS course 5 week 2 assignment 2 emojify

I have finished the ‘sentence_to_avg’ function tests… this function included the variable ‘words’ which i attained by .lower() and .split of the given ‘sentence.’ Upon finishing this cell block I moved on to the cell block ‘model’ which I then get an error relating to the before mentioned .lower().

AttributeError Traceback (most recent call last)
in
28 print(“\033[92mAll tests passed!”)
29
—> 30 model_test(model)

in model_test(target)
20
21 np.random.seed(10)
—> 22 pred, W, b = model(X, Y, word_to_vec_map, 0.0025, 110)
23
24 assert W.shape == (2, 2), “W must be of shape 2 x 2”

in model(X, Y, word_to_vec_map, learning_rate, num_iterations)
45 ### START CODE HERE ### (≈ 4 lines of code)
46 # Average the word vectors of the words from the i’th training example
—> 47 avg = sentence_to_avg(X, word_to_vec_map)
48
49 # Forward propagate the avg through the softmax layer.

in sentence_to_avg(sentence, word_to_vec_map)
19 ### START CODE HERE ###
20 # Step 1: Split sentence into list of lower case words (≈ 1 line)
—> 21 words = sentence.lower().split()
22
23 # Initialize the average word vector, should have the same shape as your word vectors.

AttributeError: ‘numpy.ndarray’ object has no attribute ‘lower’

I’m not sure how I passed the first cell block if this is wrong unless the variable ‘words’ is unused in that first block. So the error doesn’t come up till the next block.

That line of code is inside a for-loop over the range of m.
That’s what this comment refers to:
# Average the word vectors of the words from the i'th training example
The ‘X’ variable there must be indexed - don’t use the entire X variable.

The error message:
AttributeError: ‘numpy.ndarray’ object has no attribute ‘lower’
… means that you’re passing an ndarray (the X vector) instead of a single element of X.

1 Like

Thank you, that makes sense!