Method MeanPool
- Namespace
- Qavren.Edge.Embeddings.Onnx
- Assembly
- Qavren.Edge.Embeddings.Onnx.dll
MeanPool(ReadOnlySpan<float>, ReadOnlySpan<long>, int, int, Span<float>)
The masked mean: sum(h[t] * mask[t]) / max(1, sum(mask)). The denominator's
max(1, ...) is what keeps an all-padding row a defined zero vector rather than
dimensions NaNs.
public static void MeanPool(ReadOnlySpan<float> lastHiddenState, ReadOnlySpan<long> attentionMask, int sequenceLength, int dimensions, Span<float> destination)
Parameters
lastHiddenStateReadOnlySpan<float>One row of the output tensor,
[sequenceLength, dimensions], row-major.attentionMaskReadOnlySpan<long>That row's mask,
[sequenceLength]. 1 real, 0 padding.sequenceLengthintThe padded width.
dimensionsintThe embedding width.
destinationSpan<float>Where the pooled vector is written. At least
dimensionslong.