code: public static void normalizeExp(Map<String, Double> predictionScores)
      {
          Set<Map.Entry<String, Double>> entrySet = predictionScores.entrySet();
          double max = Double.NEGATIVE_INFINITY;
          for (Map.Entry<String, Double> entry : entrySet)
          {
              max = Math.max(max, entry.getValue());
          }
  
          double sum = 0.0;
          //通过减去最大值防止浮点数溢出
          for (Map.Entry<String, Double> entry : entrySet)
          {
              Double value = Math.exp(entry.getValue() - max);
              entry.setValue(value);
  
              sum += value;
          }
  
          if (sum != 0.0)
          {
              for (Map.Entry<String, Double> entry : entrySet)
              {
                  predictionScores.put(entry.getKey(), entry.getValue() / sum);
              }
          }
      }
docs: 使用log-sum-exp技巧来归一化一组对数值
  
  @param predictionScores