Skip to main content

Module math

Module math 

Source
Expand description

Pure dense/sparse math helpers (testable without ORT).

ConstantsΒ§

SPECIAL_TOKENS πŸ”’
CLS, PAD, SEP/EOS, UNK β€” excluded from sparse output.

FunctionsΒ§

median_usize πŸ”’
Computes the median of a Vec<usize> in-place (sorts the slice).
normalize_l2 πŸ”’
L2-normalizes vec in place. If the norm is zero, leaves the vector unchanged.
sparse_maxpool πŸ”’
Max-pools sparse scores by vocabulary token ID, excluding special tokens and tokens masked by the attention mask.
sparse_project πŸ”’
Projects a single token’s hidden state through the sparse-linear layer.