-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add bulk transformations functionality
- Loading branch information
Dmitry Rubinstein
committed
Aug 8, 2023
1 parent
777cf46
commit c1c3077
Showing
10 changed files
with
207 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
defmodule Tokenizers.Encoding.Transformation do | ||
@moduledoc """ | ||
Module containing handy functions to build the transformations list. | ||
This list is aplied to an encoding using `Tokenizers.Encoding.transform/2`. | ||
""" | ||
|
||
@type t :: [ | ||
{:pad, {non_neg_integer(), Tokenizers.Encoding.padding_opts()}}, | ||
{:truncate, {non_neg_integer(), Tokenizers.Encoding.truncation_opts()}}, | ||
{:set_sequence_id, non_neg_integer()} | ||
] | ||
|
||
@doc """ | ||
Generates the padding transformation. | ||
Check `Tokenizers.Encoding.pad/3` for more information. | ||
""" | ||
@spec pad(non_neg_integer(), Tokenizers.Encoding.padding_opts()) :: | ||
{:pad, {non_neg_integer(), Tokenizers.Encoding.padding_opts()}} | ||
def pad(target_length, opts \\ []) do | ||
{:pad, {target_length, opts}} | ||
end | ||
|
||
@doc """ | ||
Generates the truncation transformation. | ||
Check `Tokenizers.Encoding.truncate/3` for more information. | ||
""" | ||
@spec truncate(non_neg_integer(), Tokenizers.Encoding.truncation_opts()) :: | ||
{:truncate, {non_neg_integer(), Tokenizers.Encoding.truncation_opts()}} | ||
def truncate(max_length, opts \\ []) do | ||
{:truncate, {max_length, opts}} | ||
end | ||
|
||
@doc """ | ||
Generates the set_sequence_id transformation. | ||
Check `Tokenizers.Encoding.set_sequence_id/2` for more information. | ||
""" | ||
@spec set_sequence_id(non_neg_integer()) :: | ||
{:set_sequence_id, non_neg_integer()} | ||
def set_sequence_id(id) do | ||
{:set_sequence_id, id} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.