Skip to content

OPENNLP-1988: Read the vocabulary of a WordPiece tokenizer.json in opennlp-dl - #1319

Merged
rzo1 merged 1 commit into
apache:mainfrom
ai-pipestream:OPENNLP-1988-tokenizer-json
Oct 8, 2026
Merged

rzo1 merged 1 commit into
apache:mainfrom
ai-pipestream:OPENNLP-1988-tokenizer-json

Conversation

@krickert

@krickert krickert commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Accepts a Hugging Face tokenizer.json as the vocabulary file of the deep learning components. Part 3b of the regex removal series.

  • A tokenizer.json is recognized by its model.type. Only WordPiece is accepted; BPE, Unigram and other types are rejected by name, as is a continuing_subword_prefix other than ##.
  • model.vocab supplies the tokens. An entry of added_tokens missing from model.vocab is added with its id. A token or id conflict is rejected naming both, and a malformed entry is rejected at added_tokens[i].
  • normalizer.lowercase is read, and the constructors reject a file with a setting that disagrees with lowerCase, naming the file and both values. The other tokenizer settings are not read.
  • A flat vocab.json with a value that is not an id, or a config.json handed over as a vocabulary, fails with a message naming both accepted layouts.

Tests use a hand-written tokenizer.json fixture with encodings computed by hand, rejected Unigram, BPE, prefix and conflict files, and a byte order mark before a tokenizer.json read from disk. No Hugging Face material is copied. The vocabulary rules are documented once in the document categorizer chapter; the name finder chapter and the embedder section point to it.

OPENNLP-1988

@krickert

Copy link
Copy Markdown
Contributor Author

unstacked after the #1277 merge, so this shows only the tokenizer.json change.

A tokenizer.json is recognized by model.type and only WordPiece is accepted; added_tokens are read; normalizer.lowercase must agree with lowerCase or the file is rejected; the other tokenizer settings are not read.

Eval build: https://ci-builds.apache.org/job/OpenNLP/job/eval-tests-configurable/89/

@krickert
krickert marked this pull request as ready for review September 30, 2026 03:06
@krickert

Copy link
Copy Markdown
Contributor Author

Eval build was successful

@krickert krickert changed the title OPENNLP-1988: Read the vocabulary of a WordPiece tokenizer.json in opennlp-dl OPENNLP-1988 (3b/10): Read the vocabulary of a WordPiece tokenizer.json in opennlp-dl Oct 1, 2026
@krickert
krickert requested review from mawiesne and rzo1 October 1, 2026 17:25
@rzo1
rzo1 requested a review from jzonthemtn October 1, 2026 19:36
@krickert krickert changed the title OPENNLP-1988 (3b/10): Read the vocabulary of a WordPiece tokenizer.json in opennlp-dl OPENNLP-1988: Read the vocabulary of a WordPiece tokenizer.json in opennlp-dl Oct 1, 2026
@krickert

krickert commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

This was a ticket for helping follow-ups stacked tix with remaining regex removal. It can hold off.

@rzo1 rzo1 added this to the 3.0.0 milestone Oct 2, 2026
Comment thread opennlp-core/opennlp-ml/opennlp-dl/src/main/java/opennlp/dl/AbstractDL.java Outdated
Comment thread opennlp-core/opennlp-ml/opennlp-dl/src/main/java/opennlp/dl/AbstractDL.java Outdated
Comment thread opennlp-core/opennlp-ml/opennlp-dl/src/main/java/opennlp/dl/AbstractDL.java Outdated
Comment thread opennlp-core/opennlp-ml/opennlp-dl/src/main/java/opennlp/dl/AbstractDL.java Outdated
Comment thread opennlp-core/opennlp-ml/opennlp-dl/src/main/java/opennlp/dl/AbstractDL.java Outdated
Comment thread opennlp-core/opennlp-ml/opennlp-dl/src/main/java/opennlp/dl/AbstractDL.java Outdated
Comment thread opennlp-core/opennlp-ml/opennlp-dl/src/main/java/opennlp/dl/AbstractDL.java Outdated
Comment thread opennlp-core/opennlp-ml/opennlp-dl/src/main/java/opennlp/dl/AbstractDL.java Outdated
Comment thread opennlp-core/opennlp-ml/opennlp-dl/src/main/java/opennlp/dl/AbstractDL.java Outdated
@rzo1 rzo1 added new feature New functionality (Jira: New Feature) component: dl Deep learning / ONNX components (opennlp-dl) component: docs Manual and documentation labels Oct 4, 2026
@krickert
krickert force-pushed the OPENNLP-1988-tokenizer-json branch from 83ea203 to 0591a40 Compare October 4, 2026 18:08
@krickert

krickert commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review -

Dropped the message constants and the static on the vocabulary readers. They are package-private now, since the constructor calls them and their return type is package-private. Exceptions are plain strings and JsonScan errors are no longer rewrapped; JsonScan names the offset of a bad value instead. The other static methods predate this PR, I can do those in a follow-up.

I'm applying the same logic to the other open PRs.

@rzo1 rzo1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx, the review comments are addressed. Please rebase onto main before merging (small conflict in JsonScan).

@krickert
krickert force-pushed the OPENNLP-1988-tokenizer-json branch from 0591a40 to d8f7303 Compare October 5, 2026 20:53
@krickert

krickert commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Rebased and g2g

@rzo1

rzo1 commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

@krickert Could you rebase this onto main? Main renamed ArgumentChecks to ParamChecks (#1409), and the only conflict is in JsonScan: keep your side of both hunks and switch the ArgumentChecks calls to ParamChecks. With that, opennlp-dl builds and JsonScanTest, LoadVocabTest and SentenceVectorsDLEmbedderTest pass locally.

I would have pushed the rebase myself, but GitHub rejects pushes from maintainers to the ai-pipestream fork (same problem as before). "Allow edits by maintainers" doesn't work for organization-owned forks. Could you open future PRs from a branch on apache/opennlp or from a personal fork instead? Then we can rebase them for you.

@krickert

krickert commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Sorry I thought I transferred all the branches from my fork - I'll rebase now

Accept Hugging Face tokenizer.json files as WordPiece vocabularies in
opennlp-dl. Read model.vocab and include added_tokens with their declared
IDs. Reject token or ID conflicts, malformed entries, unsupported model
types and subword prefixes other than ##.

Reject a normalizer.lowercase setting that differs from the constructor's
lowerCase argument. Other tokenizer settings are not imported.

Error messages name the member and offset of a value of the wrong type.

Add tests for vocabulary loading, invalid input and a leading byte order
mark, using fixtures created for the tests. Document the vocabulary rules
in the document categorizer chapter and link to them from the name finder
and embedder sections.

Assisted-by: Claude Code 2.1.281
Co-authored-by: Kristian Rickert <kristian@apache.org>
Co-authored-by: Claude <noreply@anthropic.com>
Reviewed-by: Kristian Rickert <kristian@apache.org>
Signed-off-by: Kristian Rickert <kristian@apache.org>
@krickert
krickert force-pushed the OPENNLP-1988-tokenizer-json branch from d8f7303 to 10654c9 Compare October 8, 2026 08:44
@rzo1
rzo1 merged commit bca31bb into apache:main Oct 8, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: dl Deep learning / ONNX components (opennlp-dl) component: docs Manual and documentation new feature New functionality (Jira: New Feature)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants