Class OnlyFirstStrategy
Truncation strategy that only truncates the first sequence. The second sequence length is preserved, and the first 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 OnlyFirstStrategy : ITruncationStrategy
Properties
Instance
Gets the singleton instance of the OnlyFirstStrategy.
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 first 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 to be truncated. |
| IReadOnlyList<Token> | tokensB | The second sequence of tokens (optional). This sequence will not be truncated. |
Returns
| Type | Description |
|---|---|
| (int, int) | A tuple containing the truncated length for sequence A and the preserved length for sequence B. |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown when sequence A is too short to accommodate sequence B within the maximum length, or when the calculated length for sequence A is zero while sequence A has tokens. |