W2_A1_Optional exercise_AssertionError: Not all tests were passed for softmax

Can’t find the issue here. i set x_exp=exp(x) and divided s=x_exp/x_sum the output shows wrong.

Output:
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.

Notice that several your values are quite large, e.g. 5.06 * 10^2 and 9.1 * 10. The point of softmax is that all the values are between 0 and 1 and they add up to 1 for each “sample”, right? That is achieved by dividing the values by the sum of the values.

Please have another look at the formula and compare that to your code.

2 Likes

Thank you so much. I got it right.

@paulinpaloalto always looks at the errors and gives precisely instructions.