Chapter 17
layers/softmax
github.com/openfluke/welvet/layers/softmax✅
Why it exists
Classification heads and attention need stable softmax variants, including sparse/Gumbel/Entmax for research paths.
What it is
Weightless layer; KindStandard/Temperature/Grid/Hierarchical/Gumbel/Masked/Sparse/… WebGPU covers std family; exotic kinds hard-error on GPU (no silent host).
Go example
Run:
cd welvet/examples/17-softmax && source ../env.sh && go run .package main
import (
"fmt"
"github.com/openfluke/welvet/core"
"github.com/openfluke/welvet/layers/softmax"
)
func main() {
l, err := softmax.New(softmax.Config{Dim: 4, Kind: softmax.KindStandard})
if err != nil {
panic(err)
}
x := core.NewTensor[float32](1, 4)
copy(x.Data, []float32{2, 1, 0.1, -1})
_, y, err := softmax.Forward(l, x)
fmt.Println(y.Data, err)
}
Output
[0.6380664 0.23473153 0.09543471 0.031767454] <nil>