I would recommend to scale down the problem and verify each step of your calculations.
I.e. if your code predicts a 0% accuracy, check some output samples and compare them to the ground truth label. If some are right, your accuracy calculation seems to be wrong.
The same applies for your out of bounds probabilities: print each output separately, calculate the expected result manually and compare it to your formula.
I’m hesitant to help much further, as I believe that you would learn the most by digging into the code and debug it.