Packages

Fast Hugging Face tokenizer.json, OpenAI tiktoken, and SentencePiece model bindings for Elixir via the IREE tokenizer runtime

Current section

Files

Jump to
iree_tokenizers lib iree tokenizers encoding transformation.ex
Raw

lib/iree/tokenizers/encoding/transformation.ex

defmodule IREE.Tokenizers.Encoding.Transformation do
@moduledoc """
Helpers for building transformation lists passed to
`IREE.Tokenizers.Encoding.transform/2` or the `:encoding_transformations`
option on encode functions.
"""
@typedoc """
A single encoding transformation.
"""
@type t ::
{:pad, {non_neg_integer(), keyword()}}
| {:truncate, {non_neg_integer(), keyword()}}
| {:set_sequence_id, non_neg_integer()}
@doc """
Builds a padding transformation.
"""
@spec pad(non_neg_integer(), keyword()) :: t()
def pad(target_length, opts \\ []), do: {:pad, {target_length, opts}}
@doc """
Builds a truncation transformation.
"""
@spec truncate(non_neg_integer(), keyword()) :: t()
def truncate(max_length, opts \\ []), do: {:truncate, {max_length, opts}}
@doc """
Builds a transformation that replaces all sequence IDs with the given value.
"""
@spec set_sequence_id(non_neg_integer()) :: t()
def set_sequence_id(id), do: {:set_sequence_id, id}
end