Course 5 Week 2 Exercise 5 - Emojify_V2

Hi,

I’ve been stuck on this for a while. I am getting the following error

NotImplementedError                       Traceback (most recent call last)
<ipython-input-86-bb78fe22f36c> in <module>
     28 
     29 
---> 30 Emojify_V2_test(Emojify_V2)

<ipython-input-86-bb78fe22f36c> 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\""

<ipython-input-85-f2660e0ebfeb> in Emojify_V2(input_shape, word_to_vec_map, word_to_index)
     43     print('shape of X:', X.shape)
     44     print('type of X:', type(X))
---> 45     X = softmax(X)
     46 
     47     # Create Model instance which converts sentence_indices into X.

~/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_5/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 printed what is being sent to softmax and shapes of X and see the following

input shape (4,)
shape of X: (None, 5)
type of X: <class 'tensorflow.python.framework.ops.Tensor'>

I’ve gone through the a similar error and its suggested solution but no luck. Appreciate some guidance on this.

notice the error for difference
softmax(X) and softmax(x)

one is tensor and one is numpy call @auserhasnoname

check instructions before the grade cell which mentions

It should output a softmax probability vector of shape (m, C = 5). You may need Input(shape = …, dtype = ‘…’), LSTM(), Dropout(), Dense(), and Activation()

So for code line add softmax activation, your code softmax(X) doesn’t hold true for tensor function

There are two different parts to this assignment: the first part is done completely in numpy. And the softmax utility function is for use by the numpy part of the code. Then in the Emojify_V2 section, we switch to using TF/Keras. There we can’t directly call the numpy softmax function: we need to use the TF activation version of softmax.

2 Likes

Appreciate the feedback Deepti, Paul. Totally missed that. Fixed that and it worked

1 Like