def ce_grad

bend-ml-autograd@0.1.1.0 · main.bend:291

import bend-ml-autograd@0.1.1.0/main.bend as BendMlAutograd
import Base
import bend-ml-tensor@0.1.0.0/main.bend as T

291# gradient of the loss with respect to the logits: (softmax - one-hot) / n
292def ce_grad(+n: Nat, +c: Nat, logits: T.Mat<n, c>, labels: List<&2, Nat>) -> T.Mat<n, c>:
293  T.Mat.scale(n, c, (1.0 / F32.from_nat(n) : F32), T.Mat.sub(n, c, T.Mat.softmax(n, c, logits), T.Mat{onehot.rows(labels, c)}))

Uses (10)

Used by (0)

No other definition uses this definition.