Package ai.djl.huggingface.tokenizers
Class HuggingFaceTokenizer.Builder
- java.lang.Object
-
- ai.djl.huggingface.tokenizers.HuggingFaceTokenizer.Builder
-
- Enclosing class:
- HuggingFaceTokenizer
public static final class HuggingFaceTokenizer.Builder extends java.lang.ObjectThe builder for creating huggingface tokenizer.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HuggingFaceTokenizerbuild()Builds the translator.voidconfigure(java.util.Map<java.lang.String,?> arguments)Configures the builder with the arguments.HuggingFaceTokenizer.BuilderoptAddSpecialTokens(boolean addSpecialTokens)Sets if add special tokens.HuggingFaceTokenizer.BuilderoptManager(ai.djl.ndarray.NDManager manager)Sets the optional manager used to manage the lifecycle of the tokenizer.HuggingFaceTokenizer.BuilderoptMaxLength(int maxLength)Sets maxLength for padding and truncation.HuggingFaceTokenizer.BuilderoptPadding(boolean enabled)Enables or Disables default padding behavior for the tokenizer.HuggingFaceTokenizer.BuilderoptPadToMaxLength()Enables padding to pad sequences to previously specified maxLength, or modelMaxLength if not specified.HuggingFaceTokenizer.BuilderoptPadToMultipleOf(int padToMultipleOf)Sets padToMultipleOf for padding.HuggingFaceTokenizer.BuilderoptStride(int stride)Sets the stride to use in overflow overlap when truncating sequences longer than the model supports.HuggingFaceTokenizer.BuilderoptTokenizerName(java.lang.String tokenizerName)Sets the name of the tokenizer.HuggingFaceTokenizer.BuilderoptTokenizerPath(java.nio.file.Path tokenizerPath)Sets the file path of the tokenizer.HuggingFaceTokenizer.BuilderoptTruncateFirstOnly()Enables truncation to only truncate the first item.HuggingFaceTokenizer.BuilderoptTruncateSecondOnly()Enables truncation to only truncate the second item.HuggingFaceTokenizer.BuilderoptTruncation(boolean enabled)Enables or Disables default truncation behavior for the tokenizer.
-
-
-
Method Detail
-
optManager
public HuggingFaceTokenizer.Builder optManager(ai.djl.ndarray.NDManager manager)
Sets the optional manager used to manage the lifecycle of the tokenizer.- Parameters:
manager- theNDManager- Returns:
- this builder
-
optTokenizerName
public HuggingFaceTokenizer.Builder optTokenizerName(java.lang.String tokenizerName)
Sets the name of the tokenizer.- Parameters:
tokenizerName- the name of the tokenizer- Returns:
- this builder
-
optTokenizerPath
public HuggingFaceTokenizer.Builder optTokenizerPath(java.nio.file.Path tokenizerPath)
Sets the file path of the tokenizer.- Parameters:
tokenizerPath- the path of the tokenizer- Returns:
- this builder
-
optAddSpecialTokens
public HuggingFaceTokenizer.Builder optAddSpecialTokens(boolean addSpecialTokens)
Sets if add special tokens.- Parameters:
addSpecialTokens- true to add special tokens- Returns:
- this builder
-
optTruncation
public HuggingFaceTokenizer.Builder optTruncation(boolean enabled)
Enables or Disables default truncation behavior for the tokenizer.- Parameters:
enabled- whether to enable default truncation behavior- Returns:
- this builder
-
optTruncateFirstOnly
public HuggingFaceTokenizer.Builder optTruncateFirstOnly()
Enables truncation to only truncate the first item.- Returns:
- this builder
-
optTruncateSecondOnly
public HuggingFaceTokenizer.Builder optTruncateSecondOnly()
Enables truncation to only truncate the second item.- Returns:
- this builder
-
optPadding
public HuggingFaceTokenizer.Builder optPadding(boolean enabled)
Enables or Disables default padding behavior for the tokenizer.- Parameters:
enabled- whether to enable default padding behavior- Returns:
- this builder
-
optPadToMaxLength
public HuggingFaceTokenizer.Builder optPadToMaxLength()
Enables padding to pad sequences to previously specified maxLength, or modelMaxLength if not specified.- Returns:
- this builder
-
optMaxLength
public HuggingFaceTokenizer.Builder optMaxLength(int maxLength)
Sets maxLength for padding and truncation.- Parameters:
maxLength- the length to truncate and/or pad sequences to- Returns:
- this builder
-
optPadToMultipleOf
public HuggingFaceTokenizer.Builder optPadToMultipleOf(int padToMultipleOf)
Sets padToMultipleOf for padding.- Parameters:
padToMultipleOf- the multiple of sequences should be padded to- Returns:
- this builder
-
optStride
public HuggingFaceTokenizer.Builder optStride(int stride)
Sets the stride to use in overflow overlap when truncating sequences longer than the model supports.- Parameters:
stride- the number of tokens to overlap when truncating long sequences- Returns:
- this builder
-
configure
public void configure(java.util.Map<java.lang.String,?> arguments)
Configures the builder with the arguments.- Parameters:
arguments- the arguments
-
build
public HuggingFaceTokenizer build() throws java.io.IOException
Builds the translator.- Returns:
- the new translator
- Throws:
java.io.IOException- when IO operation fails in loading a resource
-
-