Table of Contents

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

lastHiddenState ReadOnlySpan<float>

One row of the output tensor, [sequenceLength, dimensions], row-major.

attentionMask ReadOnlySpan<long>

That row's mask, [sequenceLength]. 1 real, 0 padding.

sequenceLength int

The padded width.

dimensions int

The embedding width.

destination Span<float>

Where the pooled vector is written. At least dimensions long.