docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class SequenceDecoder

    A composite decoder that applies multiple decoders in sequence to process tokens. Each decoder in the sequence processes the output from the previous decoder, creating a pipeline for token transformation.

    Inheritance
    object
    SequenceDecoder
    Implements
    IDecoder
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Unity.InferenceEngine.Tokenization.Decoders
    Assembly: Unity.InferenceEngine.Tokenization.dll
    Syntax
    public class SequenceDecoder : IDecoder
    Remarks

    This class implements the Composite pattern to chain multiple decoders together. The decoders are applied in the order they are provided in the constructor. Object pooling is used internally to optimize memory allocation for intermediate results.

    Examples
    var decoder1 = new SomeDecoder();
    var decoder2 = new AnotherDecoder();
    var sequenceDecoder = new SequenceDecoder(decoder1, decoder2);
    
    var tokens = new List<string> { "token1", "token2" };
    var output = new List<string>();
    sequenceDecoder.Decode(tokens, output.AsOutput());

    Constructors

    SequenceDecoder(params IDecoder[])

    Initializes a new instance of the SequenceDecoder class with the specified sequence of decoders.

    Declaration
    public SequenceDecoder(params IDecoder[] decoders)
    Parameters
    Type Name Description
    IDecoder[] decoders

    A sequence of decoders to be applied in order. Each decoder will process the output from the previous decoder in the sequence.

    Remarks

    The decoders will be applied in the exact order they are provided. A copy of the decoder array is made internally to prevent external modifications.

    Exceptions
    Type Condition
    ArgumentNullException

    Thrown when decoders contains any null decoder instances.

    Methods

    Decode(IReadOnlyList<string>, Output<string>)

    Decodes the input tokens by applying each decoder in the sequence.

    Declaration
    public void Decode(IReadOnlyList<string> tokens, Output<string> output)
    Parameters
    Type Name Description
    IReadOnlyList<string> tokens

    The input tokens to be decoded. This collection is processed by the first decoder, and subsequent decoders process the output from the previous decoder.

    Output<string> output

    The output collection where the final decoded results will be added. This will contain the tokens after being processed by all decoders in sequence.

    Remarks

    The decoding process works as follows:

    1. The input tokens are copied to an intermediate buffer
    2. Each decoder in the sequence processes the current intermediate buffer
    3. The output of each decoder becomes the input for the next decoder
    4. The final result is added to the output collection

    Two intermediate List<string> instances are used and swapped between iterations to avoid unnecessary memory allocations. These lists are obtained from an object pool and automatically returned when the method completes.

    Examples
    var tokens = new List<string> { "Hello", "World" };
    var output = new List<string>();
    decoder.Decode(tokens, output.AsOutput());
    // output now contains the tokens processed by all decoders in sequence

    Implements

    IDecoder
    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)