code: private static void softmax(double[] prob) {
          double max = Double.NEGATIVE_INFINITY;
          for (int i = 0; i < prob.length; i++) {
              if (prob[i] > max) {
                  max = prob[i];
              }
          }
  
          double Z = 0.0;
          for (int i = 0; i < prob.length; i++) {
              double p = Math.exp(prob[i] - max);
              prob[i] = p;
              Z += p;
          }
  
          for (int i = 0; i < prob.length; i++) {
              prob[i] /= Z;
          }
      }
docs: Calculate softmax function without overflow.