C5W2A2 Emoji Exercise 5 error

I get the value error message shown below. I’m stuck with finding what the reason could be. Any ideas?


ValueError 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)
25 # Propagate sentence_indices through your embedding layer
26 # (See additional hints in the instructions).
—> 27 embeddings = embedding_layer(sentence_indices)
28
29 # Propagate the embeddings through an LSTM layer with 128-dimensional hidden state

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in call(self, *args, **kwargs)
924 if _in_functional_construction_mode(self, inputs, args, kwargs, input_list):
925 return self._functional_construction_call(inputs, args, kwargs,
→ 926 input_list)
927
928 # Maintains info about the Layer.call stack.

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in _functional_construction_call(self, inputs, args, kwargs, input_list)
1096 # Build layer if applicable (if the build method has been
1097 # overridden).
→ 1098 self._maybe_build(inputs)
1099 cast_inputs = self._maybe_cast_inputs(inputs, input_list)
1100

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in _maybe_build(self, inputs)
2653 # Using init_scope since we want variable assignment in
2654 # set_weights to be treated like variable initialization.
→ 2655 self.set_weights(self._initial_weights)
2656 else:
2657 self.set_weights(self._initial_weights)

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in set_weights(self, weights)
1808 'with a weight list of length %s, but the layer was ’
1809 'expecting %s weights. Provided weights: s...'
→ 1810 (self.name, len(weights), expected_num_weights, str(weights)[:50]))
1811
1812 weight_index = 0

ValueError: You called set_weights(weights) on layer “embedding_18” with a weight list of length 15, but the layer was expecting 1 weights. Provided weights: [[ 3. 3.]
[ 3. 3.]
[ 2. 4.]
[ 3. 2.]
[ 3. …

1 Like

Der @dbodmer,

Please send me the code via DM (Direct Message).
You can do this by clicking on my name and then click Message.
Kindly note that sharing code in the community is against the code of conduct, so please do not post it here.


Keep Learning AI with DeepLearning.AI - Girijesh

Perhaps there is a problem in the “embedding_layer” object. That’s created by calling pretrained_embedding_layer() with the correct arguments.

Or the issue might be with the sentence_indices variable, which you get by using the Input() object.

So those are good places to start looking for problems.

embedding layer set_weights should have a single np.ndarray

Yes, but you get that for free by calling pretrained_embeddding_layer() with the correct arguments.

Found it. The issue was related to exercise 4 pretrained_embedding_layer. More specifically, to the following instruction: “4. Set the embedding weights to be equal to the embedding matrix. Note that this is part of the code is already completed for you and does not need to be modified!”

3 Likes