Skip to main content

zero_padded_rows

Function zero_padded_rows 

Source
pub fn zero_padded_rows(embeddings: &Tensor, mask: &Tensor) -> Result<Tensor>
Expand description

Zero every row of embeddings that sits at a padded position.

embeddings is (batch, seq_len, d), mask is (batch, seq_len) with 1 at real tokens. A padded query still produces a full output row — the key-side mask only stops other positions attending to it — and that row is arbitrary rather than meaningfully zero. Zeroing it makes PlmRunner::embed_batch deterministic regardless of what each architecture happens to compute there, so pooling over the sequence axis does not silently mix garbage into the result.