softmax static method

List<Value> softmax(
  1. List<Value> inputs
)

Implementation

static List<Value> softmax(List<Value> inputs) {
  double maxVal = inputs.map((n) => n.data).reduce(math.max);
  List<Value> expVals =
      inputs.map((n) => (n - Value(maxVal, {n}, "softmax")).exp()).toList();
  Value sumExp = expVals.reduce((a, b) => a + b);
  List<Value> softmaxOut = expVals.map((n) => n / sumExp).toList();

  return softmaxOut;
}