TorchTokenGeneration¶
- class probly.representation.text_generation.torch.TorchTokenGeneration(sequences: Tensor, transition_scores: Tensor)[source]¶
Bases:
TorchAxisProtected[Tensor]Generated token sequences and token transition scores.
Shape:
batch_shape.sequencesstores token ids with a protected trailing sequence axis.transition_scoresstores generated-token log probabilities with a protected trailing generated-token axis.- clone(*, memory_format: memory_format = torch.preserve_format) Self[source]¶
Return a copy of the array.
- cpu(memory_format: memory_format = torch.preserve_format) Self[source]¶
Move the array to the CPU.
- cuda(device: device | str | None = None, non_blocking: bool = False, memory_format: memory_format = torch.preserve_format) Self[source]¶
Move the array to the GPU.
- gather(dim: int, index: Tensor) Self[source]¶
Return a copy with gathered protected values along a batch dimension.
- permitted_functions = {}¶
- permute(*dims: Size | int | tuple[int] | list[int]) Self[source]¶
Return a permuted version of the array.
- protected_values(func: Callable | None = None) dict[str, TorchProtectedValue] | None[source]¶
Return all protected field values as-is.
Optionally takes the torch function that triggered the call for context. This can be used to conditionally modify the returned values or prevent them from being accessed.
- sequences: torch.Tensor¶
- size(dim: int | None = None) int | Size[source]¶
Return the size of the array along the given dimension.
- to_device(device: Literal['cpu'], /, *, stream: int | Any | None = None) Self[source]¶
Move the array to a device.
- to_text(tokenizer: PreTrainedTokenizerBase, *, length_normalization: bool = False, stop_token_ids: set[int] | None = None, skip_special_tokens: bool = True, **decode_kwargs: Any) TorchTextGeneration[source]¶
Decode token sequences and sum transition scores into log-likelihoods.
- Parameters:
tokenizer – Tokenizer exposing
batch_decode.length_normalization – Whether log likelihoods should be averaged over scored tokens.
stop_token_ids – Explicit stop token ids. If omitted, tokenizer EOS and padding ids are used.
skip_special_tokens – Whether special tokens should be omitted while decoding.
**decode_kwargs – Additional keyword arguments forwarded to
batch_decode.
- Returns:
The decoded text generation representation.
- transition_scores: torch.Tensor¶