Week 2 Exercise 7

Pretty stuck, any pointers?

{moderator edit - solution code removed}

t_x = np.array([[9, 2, 5, 0, 0],

            [7, 5, 0, 0 ,0]])

print("softmax(x) = " + str(softmax(t_x)))

​

softmax_test(softmax)

softmax(x) = [[5.06442745e+02 4.61816006e-01 9.27582244e+00 6.25000000e-02
6.25000000e-02]
[9.13860965e+01 1.23677633e+01 8.33333333e-02 8.33333333e-02
8.33333333e-02]]
Error: Wrong output
2 Tests passed
1 Tests failed


AssertionError Traceback (most recent call last)
in
3 print("softmax(x) = " + str(softmax(t_x)))
4
----> 5 softmax_test(softmax)

~/work/release/W2A1/public_tests.py in softmax_test(target)
195 ]
196
β†’ 197 test(test_cases, target)
198
199 def L1_test(target):

~/work/release/W2A1/test_utils.py in test(test_cases, target)
24 print(β€˜\033[92m’, success," Tests passed")
25 print(β€˜\033[91m’, len(test_cases) - success, " Tests failed")
β€”> 26 raise AssertionError(β€œNot all tests were passed for {}. Check your equations and avoid using global variables inside the function.”.format(target.name))

AssertionError: Not all tests were passed for softmax. Check your equations and avoid using global variables inside the function.

You are summing x, but take another look at what is in the denominator of the formula for softmax: the sums are of e^x, right?

6 Likes

Thanks for the tip, I was making the same mistake and not understanding why one test fails. Now I wonder how the other two tests passed in the first place :slight_smile:

You can examine the test by clicking β€œFile β†’ Open” and then open the file public_tests.py. What I will guess you find is that the first two tests check the data type and shape of the answer. That is a pretty low bar for full correctness. :nerd_face: