public static KerasSymbol Softmax(KerasSymbol x, int axis = -1) { var ndim = K.NDim(x); if (ndim == 2) { return(K.Softmax(x)); } else if (ndim > 2) { var e = K.Exp(x - K.Max(x, axis: axis, keepdims: true)); var s = K.Sum(e, axis: axis, keepdims: true); return(e / s); } else if (ndim == 0) { // x dim is not inferred yet return(K.Softmax(x)); } else { throw new Exception($"Cannot apply softmax to a tensor that is 1D. Received input: {x}"); } }