Loss.cross_entropy: def of bendtorch-core@0.1.0.0 Import: import bendtorch-core@0.1.0.0/src/autograd/loss.bend as Loss Lines 415-426 of bendtorch-core@0.1.0.0/src/autograd/loss.bend: https://jend.leeeet.dev/read.txt?path=bendtorch-core@0.1.0.0/src/autograd/loss.bend&start_line=415&end_line=426 import Base import bendtorch-core@0.1.0.0/src/tensor/core.bend as Core # PyTorch's cross_entropy(logits, targets) with mean reduction, for logits # of [rows, columns] and one class index below `columns` per row. Per row, # the stable log_softmax: m = the row maximum (max_step), shifted = x - m, # lse = log of the sum of exp(shifted) in ascending order from +0.0, and # lp = shifted - lse, PyTorch's (x - max) - log(sum). The loss is the sum of # -lp at each row's target, in row order from +0.0, divided by the rows. # The logits come back unchanged, next to the loss, lp and the one-hot rows # of the targets, which the backward reads. Logits that are not of rank 2 # fail with NotLogits (107); a target count other than the rows or a target # at or past `columns` with TargetOutOfRange (108). def cross_entropy(logits: Core.Dynamic, +targets: List<&2, U32>) -> Core.Dynamic & Result<&2, &1, Error, Recorded>: ce_shaped(targets, Core.shape(logits)) Uses (9): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Pair https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Result https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32 https://jend.leeeet.dev/definition.txt?path=bendtorch-core@0.1.0.0/src/autograd/loss.bend&name=Error https://jend.leeeet.dev/definition.txt?path=bendtorch-core@0.1.0.0/src/autograd/loss.bend&name=Recorded https://jend.leeeet.dev/definition.txt?path=bendtorch-core@0.1.0.0/src/autograd/loss.bend&name=ce_shaped https://jend.leeeet.dev/definition.txt?path=bendtorch-core@0.1.0.0/src/tensor/core.bend&name=Dynamic https://jend.leeeet.dev/definition.txt?path=bendtorch-core@0.1.0.0/src/tensor/core.bend&name=shape