SentenceEncoder class

Inheritance

Constructors

SentenceEncoder({required int vocabSize, required int maxSeqLen, required int embedDim, int numLayers = 4, int numHeads = 4, double dropoutP = 0.0, PoolingMode pooling = PoolingMode.mean, bool normalize = true, double eps = 1e-12, Device device = Device.CPU, int seed = 0})
SentenceEncoder.wrap(TokenEncoder backbone, {PoolingMode pooling = PoolingMode.mean, bool normalize = true, double eps = 1e-12})
Wrap an already-constructed backbone. Useful for loading a pretrained transformer and swapping the pooling head.

Properties

backbone TokenEncoder
final
embedDim int
no setter
eps double
final
hashCode int
The hash code for this object.
no setterinherited
normalize bool
final
pooling PoolingMode
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
training bool
Whether this module is in training mode. Layers that behave differently between training and inference (e.g. Dropout) read this flag in their call method. Defaults to training mode.
getter/setter pairinherited

Methods

call(Tensor tokens) Tensor
Encode a single sequence of token indices [seqLen] to a [1, embedDim] sentence embedding.
encodeBatch(List<Tensor> tokenSequences) Tensor
Encode a batch of token sequences and stack the results into a single [N, embedDim] tensor. Each sequence still runs through the backbone independently (the transformer here does not batch over a leading dimension), so this is a convenience wrapper — still differentiable when called under a live grad tape.
eval() → void
Put this module (and any registered submodules) into evaluation mode.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
parameters() List<Tensor>
Trainable tensors owned by this module (and its submodules).
override
submodules() List<Module>
Submodules owned by this module. Subclasses that compose other modules should override this so train() / eval() propagate. Default: empty.
override
toString() String
A string representation of this object.
inherited
train() → void
Put this module (and any registered submodules) into training mode.
inherited
zeroGrad() → void
Zero every parameter's gradient. Safe to call before each backward.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited