core/nn/sentence/sentence_encoder library

Sentence-Transformers style embedder.

A SentenceEncoder wraps a TextTransformer backbone with a pooling step (mean over tokens or the first "CLS"-style token) and an optional row-wise L2 normalization, producing a single [1, embedDim] sentence embedding per input.

Matches the recipe from github.com/huggingface/sentence-transformers: backbone output [seqLen, D] → pool → optional normalize → dense embedding suitable for cosine-similarity search and reranking.

Classes

SentenceEncoder
TokenEncoder
Anything that maps [seqLen] token indices to a [seqLen, embedDim] feature matrix and reports its output width. Both TextTransformer and the BERT-style BertModel implement this so SentenceEncoder and CrossEncoder can wrap either backbone.

Enums

PoolingMode

Functions

l2NormalizeRow(Tensor x, {double eps = 1e-12}) Tensor
Row-wise L2 normalize a [1, D] tensor.
poolTokens(Tensor tokenFeatures, PoolingMode mode) Tensor
Pool a token feature matrix [seqLen, embedDim] to a sentence vector [1, embedDim].