Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tokenizer] Adds getters for HuggingfaceTokenizer #2958

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,53 @@ public void enableBatch() {
}
}

/**
* Returns the truncation policy.
*
* @return the truncation policy
*/
public String getTruncation() {
return truncation.name();
}

/**
* Returns the padding policy.
*
* @return the padding policy
*/
public String getPadding() {
return padding.name();
}

/**
* Returns the max token length.
*
* @return the max token length
*/
public int getMaxLength() {
return maxLength;
}

/**
* Returns the stride to use in overflow overlap when truncating sequences longer than the model
* supports.
*
* @return the stride to use in overflow overlap when truncating sequences longer than the model
* supports
*/
public int getStride() {
return stride;
}

/**
* Returns the padToMultipleOf for padding.
*
* @return the padToMultipleOf for padding
*/
public int getPadToMultipleOf() {
return padToMultipleOf;
}

/**
* Creates a builder to build a {@code HuggingFaceTokenizer}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ public void testTokenizer() throws IOException {
};

try (HuggingFaceTokenizer tokenizer = HuggingFaceTokenizer.newInstance("bert-base-cased")) {
Assert.assertEquals(tokenizer.getTruncation(), "DO_NOT_TRUNCATE");
Assert.assertEquals(tokenizer.getPadding(), "DO_NOT_PAD");
Assert.assertEquals(tokenizer.getMaxLength(), -1);
Assert.assertEquals(tokenizer.getStride(), 0);
Assert.assertEquals(tokenizer.getPadToMultipleOf(), 0);

List<String> ret = tokenizer.tokenize(input);
Assert.assertEquals(ret.toArray(Utils.EMPTY_ARRAY), expected);
Encoding encoding = tokenizer.encode(input);
Expand Down
Loading