Class OnlySecondStrategy
Truncation strategy that only truncates the second sequence. The first sequence length is preserved, and the second sequence is adjusted to fit within the maximum length.
Implements
Inherited Members
Namespace: Unity.InferenceEngine.Tokenization.Truncators.Strategies
Assembly: Unity.InferenceEngine.Tokenization.dll
Syntax
public class OnlySecondStrategy : ITruncationStrategy
Properties
Instance
Gets the singleton instance of the OnlySecondStrategy.
Declaration
public static ITruncationStrategy Instance { get; }
Property Value
| Type | Description |
|---|---|
| ITruncationStrategy |
Methods
GetTruncationLength(int, IReadOnlyList<Token>, IReadOnlyList<Token>)
Calculates the truncation lengths for two token sequences, truncating only the second sequence.
Declaration
public (int lengthA, int lengthB) GetTruncationLength(int maxLength, IReadOnlyList<Token> tokensA, IReadOnlyList<Token> tokensB)
Parameters
| Type | Name | Description |
|---|---|---|
| int | maxLength | The maximum combined length allowed for both sequences. |
| IReadOnlyList<Token> | tokensA | The first sequence of tokens. This sequence will not be truncated. |
| IReadOnlyList<Token> | tokensB | The second sequence of tokens to be truncated (optional). |
Returns
| Type | Description |
|---|---|
| (int, int) | A tuple containing the preserved length for sequence A and the truncated length for sequence B. |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown when sequence B cannot be truncated to fit within the maximum length after preserving sequence A, or when the calculated length for sequence B is zero while sequence B has tokens. |