C2_W4_Assignment UNQ_C2 GRADED FUNCTION: softmax

Hi
My softmax funtion output doesn’t match the expected output, no sure what’s wrong with it, and why do the expected outputs not sum p to 1?

Here is my softmax implementation:

# UNIT TEST COMMENT: Candidate for Table Driven Tests
# UNQ_C2 GRADED FUNCTION: softmax
def softmax(z):
  # mentor edit: code removed

and the output of the test:

Test the function

tmp = np.array([[1,2,3],
[1,1,1]
])
tmp_sm = softmax(tmp)
display(tmp_sm)

array([[0.09003057, 0.24472847, 0.66524096],
[0.33333333, 0.33333333, 0.33333333]])

array([[0.5       , 0.73105858, 0.88079708],
       [0.5       , 0.26894142, 0.11920292]])



When creating a post, please add:
* Week # must be added in the tags option of the post.
* Link to the classroom item you are referring to:
* Description (include relevant info but please do not post solution code or your entire notebook)

https://www.coursera.org/learn/probabilistic-models-in-nlp/programming/OrMrl/word-embeddings/lab?workspaceGatewayHost=hub.labs.coursera.org&path=%2Fnotebooks%2FC2_W4_Assignment.ipynb

Compare your code using around np.exp() with the equation you’re implementing. If I recall correctly, you may be missing a negative sign.

Also, please don’t post your code on the forum. That’s not allowed by the Code of Conduct.

Noted, thanks for pointing that out

I tried with a negative sign before z, but still not working…and my question still, why is the expected output in the assignment doesn’t sum up to 1.0?

The values in each row do add to 1.0.