TextEncoder
- class TextEncoder(*args, **kwargs)[source]
Bases:
Module
An encoder for text.
Initialize internal Module state, shared by both nn.Module and ScriptModule.
Methods Summary
encode_all
(labels[, batch_size])Encode all labels (inference mode & batched).
forward
(labels)Encode a batch of text.
forward_normalized
(texts)Encode a batch of text.
Methods Documentation
- encode_all(labels: Sequence[str], batch_size: int | None = None) Tensor [source]
Encode all labels (inference mode & batched).
- Parameters:
batch_size (int | None) – the batch size to use for encoding the labels.
batch_size=1
means that the labels are encoded one-by-one, whilebatch_size=len(labels)
would correspond to encoding all at once. Larger batch sizes increase memory requirements, but may be computationally more efficient. batch_size can also be set to None to enable automatic batch size maximization for the employed hardware.
- Returns:
shape: (len(labels), dim) a tensor representing the encodings for all labels
- Return type: