Course 5 week 2 assignment 5 'Tensor' object is not callable

I’m a bit stuck Getting this error. Not sure if I’m even on the right track

TypeError Traceback (most recent call last)
in
28
29
—> 30 Emojify_V2_test(Emojify_V2)

in Emojify_V2_test(target)
20
21 maxLen = 4
—> 22 model = target((maxLen,), word_to_vec_map, word_to_index)
23
24 assert type(model) == Functional, “Make sure you have correctly created Model instance which converts "sentence_indices" into "X"”

in Emojify_V2(input_shape, word_to_vec_map, word_to_index)
21
22 # Create the embedding layer pretrained with GloVe Vectors (≈1 line)
—> 23 embedding_layer = pretrained_embedding_layer_test(sentence_indices)
24
25 # Propagate sentence_indices through your embedding layer

in pretrained_embedding_layer_test(target)
18
19 np.random.seed(1)
—> 20 embedding_layer = target(word_to_vec_map, word_to_index)
21
22 assert type(embedding_layer) == Embedding, “Wrong type”

TypeError: ‘Tensor’ object is not callable

Oops. Found an error pretrained_embedding_layer_test Should be pretrained_embedding_layer. Still not working though. Latest error
AttributeError Traceback (most recent call last)
in
28
29
—> 30 Emojify_V2_test(Emojify_V2)

in Emojify_V2_test(target)
20
21 maxLen = 4
—> 22 model = target((maxLen,), word_to_vec_map, word_to_index)
23
24 assert type(model) == Functional, “Make sure you have correctly created Model instance which converts "sentence_indices" into "X"”

in Emojify_V2(input_shape, word_to_vec_map, word_to_index)
21
22 # Create the embedding layer pretrained with GloVe Vectors (≈1 line)
—> 23 embedding_layer =pretrained_embedding_layer(sentence_indices,word_to_index)
24
25 # Propagate sentence_indices through your embedding layer

in pretrained_embedding_layer(word_to_vec_map, word_to_index)
15
16 vocab_size = len(word_to_index) + 1 # adding 1 to fit Keras embedding (requirement)
—> 17 any_word = list(word_to_vec_map.keys())[0]
18 emb_dim = word_to_vec_map[any_word].shape[0] # define dimensionality of your GloVe word vectors (= 50)
19

AttributeError: ‘Tensor’ object has no attribute ‘keys’

Found it. I have a new issue and will try to resolve by myself

That’s the wrong argument. You need to pass the word to vec map, not the sentence indices.

Thanks!

Still struggling with this one. If I set return_sequences= True that should return a bunch of sequences right? I tried True the first time and false the second time and got one error. This time I tried False then True. Now I get a different one. Getting this error now.
Expected value

[‘LSTM’, (None, 128), 131584, (None, 4, 128), ‘tanh’, False]

does not match the input value:

[‘Dense’, (None, 4, 5), 645, ‘linear’]

AssertionError Traceback (most recent call last)
in
28
29
—> 30 Emojify_V2_test(Emojify_V2)

in Emojify_V2_test(target)
25
26 expectedModel = [[‘InputLayer’, [(None, 4)], 0], [‘Embedding’, (None, 4, 2), 30], [‘LSTM’, (None, 4, 128), 67072, (None, 4, 2), ‘tanh’, True], [‘Dropout’, (None, 4, 128), 0, 0.5], [‘LSTM’, (None, 128), 131584, (None, 4, 128), ‘tanh’, False], [‘Dropout’, (None, 128), 0, 0.5], [‘Dense’, (None, 5), 645, ‘linear’], [‘Activation’, (None, 5), 0]]
—> 27 comparator(summary(model), expectedModel)
28
29

~/work/W2A2/test_utils.py in comparator(learner, instructor)
21 “\n\n does not match the input value: \n\n”,
22 colored(f"{a}", “red”))
—> 23 raise AssertionError(“Error in test”)
24 print(colored(“All tests passed!”, “green”))
25

AssertionError: Error in test

In Emojify_V2(), there are two LSTM layers:

  • The first has return_sequences as True
  • The second has return_sequences as False.

Neither one should specify any activation.

Thank you. So if I set the return_sequences= True the first time and return_sequences= False the second time. I get this error. Any idea what I should look at next? Input into LSTM is embeddings right?
Test failed
Expected value

[‘LSTM’, (None, 4, 128), 67072, (None, 4, 2), ‘tanh’, True]

does not match the input value:

[‘LSTM’, (None, 128), 67072, (None, 4, 2), ‘tanh’, False]

AssertionError Traceback (most recent call last)
in
28
29
—> 30 Emojify_V2_test(Emojify_V2)

in Emojify_V2_test(target)
25
26 expectedModel = [[‘InputLayer’, [(None, 4)], 0], [‘Embedding’, (None, 4, 2), 30], [‘LSTM’, (None, 4, 128), 67072, (None, 4, 2), ‘tanh’, True], [‘Dropout’, (None, 4, 128), 0, 0.5], [‘LSTM’, (None, 128), 131584, (None, 4, 128), ‘tanh’, False], [‘Dropout’, (None, 128), 0, 0.5], [‘Dense’, (None, 5), 645, ‘linear’], [‘Activation’, (None, 5), 0]]
—> 27 comparator(summary(model), expectedModel)
28
29

~/work/W2A2/test_utils.py in comparator(learner, instructor)
21 “\n\n does not match the input value: \n\n”,
22 colored(f"{a}", “red”))
—> 23 raise AssertionError(“Error in test”)
24 print(colored(“All tests passed!”, “green”))
25

AssertionError: Error in test

A bit more information. Maybe something is wrong with the second call of LSTM? I printed out some of shapes as the code progressed. In the error message is says my first tuple of the model is (None, 128) but should be (None, 4, 128), X3 is the third time X is defined in the code. It is the second call of LSTM. The shape changers to (None, 128) at that step. Any idea what I should be looking at? Rest of the error message is same as above.
input_shape (4,)
sentence_indices Tensor(“input_27:0”, shape=(None, 4), dtype=int32)
X1 (None, 4, 128)
X2 (None, 4, 128)
X3 (None, 128)
Test failed
Expected value

[‘LSTM’, (None, 4, 128), 67072, (None, 4, 2), ‘tanh’, True]

does not match the input value:

[‘LSTM’, (None, 128), 67072, (None, 4, 2), ‘tanh’, False

Please check your personal messages for instructions.

Update:
The issue was passing the wrong data to one of the layers.