C5W2A2 Non Implemented Error

I am having problems with how to propagate sentence_indices through the embedding layer. I am calling the embedding_layer(sentence_indices) as a function of the sentence_indices. However, I am getting an

NotImplementedError: NotImplementedError: Cannot convert a symbolic Tensor (dense_3/BiasAdd:0) to a numpy array. This error may indicate that you’re trying to pass a Tensor to a NumPy call, which is not supported.

The hints say this is allowed. So what is the issue?

I am just on my phone and can’t read the assignment, but passing a tensor to a numpy call is allowed if you first convert it to a numpy array, right? Remember how to do that? The point is that it doesn’t “just happen”.:nerd_face:

1 Like

As @paulinpaloalto mentioned, the error you’re experiencing usually happens when you try to pass a symbolic tensor (in TensorFlow) to a function that expects a NumPy array. In the case of propagating sentence_indices through the embedding layer, it appears that there is an operation where you’re inadvertently passing a symbolic tensor to a NumPy function, which is not supported in TensorFlow.

@Steven22 @nadtriana @paulinpaloalto I am going to go out on a bit of a limb here guys… But I looked up the assignment… I am not sure where Numpy plays into this situation at all.

What I would suggest is recall we have ‘this’:

pretrained_embedding_layer

and then also ‘this’:

embedding_layer

available to us.

I’m leaving out all the params, but that is why it is a ‘hint’.

2 Likes

Correct. The mentioned error may be due to manipulating the tensor with NumPy operations, which shouldn’t be necessary here.

2 Likes

Ok. Totally lost. I’m not even sure where to start. So I’m lost with Keras. Not well explained (or even at all in the lectures). I’m posting my error codes from the results of the code activation.

NotImplementedError 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)
45 X = Dense(units=5)(X)
46 # Add a softmax activation
—> 47 X = Activation(softmax)(X)
48 # Create Model instance which converts sentence_indices into X.
49 model = Model(embeddings,X)

/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)
1115 try:
1116 with ops.enable_auto_cast_variables(self._compute_dtype_object):
→ 1117 outputs = call_fn(cast_inputs, *args, **kwargs)
1118
1119 except errors.OperatorNotAllowedInGraphError as e:

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/layers/core.py in call(self, inputs)
425
426 def call(self, inputs):
→ 427 return self.activation(inputs)
428
429 def compute_output_shape(self, input_shape):

~/work/W2A2/emo_utils.py in softmax(x)
27 def softmax(x):
28 “”“Compute softmax values for each sets of scores in x.”“”
—> 29 e_x = np.exp(x - np.max(x))
30 return e_x / e_x.sum()
31

<array_function internals> in amax(*args, **kwargs)

/opt/conda/lib/python3.7/site-packages/numpy/core/fromnumeric.py in amax(a, axis, out, keepdims, initial, where)
2666 “”"
2667 return _wrapreduction(a, np.maximum, ‘max’, axis, None, out,
→ 2668 keepdims=keepdims, initial=initial, where=where)
2669
2670

/opt/conda/lib/python3.7/site-packages/numpy/core/fromnumeric.py in _wrapreduction(obj, ufunc, method, axis, dtype, out, **kwargs)
88 return reduction(axis=axis, out=out, **passkwargs)
89
—> 90 return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
91
92

/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in array(self)
846 “Cannot convert a symbolic Tensor ({}) to a numpy array.”
847 " This error may indicate that you’re trying to pass a Tensor to"
→ 848 " a NumPy call, which is not supported".format(self.name))
849
850 def len(self):

NotImplementedError: Cannot convert a symbolic Tensor (dense_7/BiasAdd:0) to a numpy array. This error may indicate that you’re trying to pass a Tensor to a NumPy call, which is not supported

I finally figured it out. I had forgot to enclose the activation function in the Activation layer in quotes.

2 Likes