Add Context-Aware Tokenizer Selection Utility Based on Corpus Analysis#40515
Open
Aishwarya0811 wants to merge 6 commits intohuggingface:mainfrom
Open
Add Context-Aware Tokenizer Selection Utility Based on Corpus Analysis#40515Aishwarya0811 wants to merge 6 commits intohuggingface:mainfrom
Aishwarya0811 wants to merge 6 commits intohuggingface:mainfrom
Conversation
…ithub.com/Aishwarya0809/transformers into feature/context-aware-tokenizer-selection
Author
|
The test failures appeared after clicking "Update branch" and are in SmolVLM image processing, completely unrelated to the tokenizer selection utility I implemented. These appear to be pre-existing issues in the main branch. |
Member
|
Mentioned in #40512, but I don't think we want this in Transformers right now! A lot of our focus is on running and fine-tuning existing models, rather than tools for making these kind of baseline decisions about brand new model architectures. Maybe make your own repo for it? |
Collaborator
ArthurZucker
left a comment
There was a problem hiding this comment.
Yep as @Rocketknight1 said, but we are happy to help you get visibiity: you should make it into a hf community post!
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This PR introduces a new utility module that automates tokenizer selection and configuration based on corpus characteristics, addressing the need to reduce manual trial-and-error in tokenizer selection and improve model performance with minimal user effort.
Key Features:
CorpusAnalyzer: Extracts statistical features from text corpora (vocabulary size, morphological complexity, character diversity, language patterns)
TokenizerRecommender: Maps corpus features to optimal tokenizer types (BPE, WordPiece, SentencePiece) using rule-based heuristics
TokenizerSelector: End-to-end utility that analyzes corpus, recommends tokenizer type, and optionally trains it using existing infrastructure
Language-aware recommendations: Handles different script types (Latin, CJK, mixed) appropriately
Implementation Details:
Minimal changes: Single new file src/transformers/utils/tokenizer_selection.py
Zero modifications to existing tokenizer classes
Uses lazy imports to avoid circular dependencies
Integrates with existing train_new_from_iterator method
Comprehensive test coverage (16 tests)
-->
Fixes #40512
Fixes # (issue) Context-Aware Tokenizer Selection Utility Based on Corpus Analysis
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
-->