Loss.one_hot: def of bendtorch-core@0.1.0.0 Import: import bendtorch-core@0.1.0.0/src/autograd/loss.bend as Loss Lines 296-308 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=296&end_line=308 import Base import bendtorch-core@0.1.0.0/src/tensor/core.bend as Core # The one-hot rows of the targets, [rows, columns]: 1.0 where the column is # the row's target, +0.0 elsewhere. The [rows, 1] targets and the [1, columns] # class numbers broadcast against each other with Matches, which compares # their words. With no rows the one-hot rows are empty, and the class # numbers are not built: [1, columns] could exceed the capacity that # [0, columns] does not. def one_hot(+targets: List<&2, U32>, +rows: Nat, +columns: Nat) -> Result<&2, &1, Core.Error, Core.Dynamic>: match rows: case 0n: Core.construct([0, U32.from_nat(columns)], Nil{}) case 1n+less: one_hot_pair(Core.construct([U32.from_nat(1n+less), 1], as_words(targets)), Core.construct([1, U32.from_nat(columns)], classes(columns, 0n))) Uses (11): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat 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=Base/base.bend&name=U32.from_nat https://jend.leeeet.dev/definition.txt?path=bendtorch-core@0.1.0.0/src/autograd/loss.bend&name=as_words https://jend.leeeet.dev/definition.txt?path=bendtorch-core@0.1.0.0/src/autograd/loss.bend&name=classes https://jend.leeeet.dev/definition.txt?path=bendtorch-core@0.1.0.0/src/autograd/loss.bend&name=one_hot_pair 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=Error https://jend.leeeet.dev/definition.txt?path=bendtorch-core@0.1.0.0/src/tensor/core.bend&name=construct