Vocabulary Pruning Engine for Multilingual GLiNER Models#366
Open
ALI-AL-MARJANI wants to merge 12 commits into
Open
Vocabulary Pruning Engine for Multilingual GLiNER Models#366ALI-AL-MARJANI wants to merge 12 commits into
ALI-AL-MARJANI wants to merge 12 commits into
Conversation
added 11 commits
May 18, 2026 15:47
- scripts/prune_gliner_vocab.py: prune multilingual GLiNER vocab to target language
- scripts/validate_pruned_model.py: 3-tier validator (PASS/SCORE_DRIFT/ENTITY_FAIL),
--score_tol flag
- docs/vocab_pruning.md: full documentation page with benchmark results
- docs/index.md: add vocab_pruning to toctree
- gliner/modeling/encoder.py: fix token_lengths kwarg leak in BiEncoder.encode_labels
- gliner/model.py: wrap onnxruntime import in try/except for ARM compatibility
Benchmarked on urchade/gliner_multi-v2.1 (mDeBERTa-v3, 250k vocab):
English Wikipedia corpus -> 250,105 -> 90,840 tokens (63.7% reduction)
Model size: 1155.8 -> 666.5 MB (42.3% smaller), ALL PASS entity correctness
Collaborator
|
@ALI-AL-MARJANI , thanks for your contributions. Please, fix ruff errors first so we can move forward. |
Fix 25 ruff errors blocking the lint job requested by maintainer: - Sort import blocks (I001) and __all__ (RUF022) across 9 files - Merge duplicate get_train_dataloader (F811) — curriculum path integrated into the single authoritative implementation - Add missing docstring args (D417) in config.py, long_doc.py, model.py - Remove unused imports (F401): math, torch, Dict, numpy - Fix for-loop variable overwrite (PLW2901) in descriptions.py - Remove unused neg_mask variable (F841) in loss_functions.py - Fix EN dash in string literal (RUF001) in trainer.py - Fix docstring summary blank line (D205) in hard_negatives.py - Break line > 120 chars (E501) in model.py Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Author
|
CI should pass now i guess |
Collaborator
|
@ALI-AL-MARJANI , please merge from main as there are some conflicts right now that need to be resolved |
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.
Problem
Multilingual GLiNER models (mDeBERTa-v3) carry a 250k-token embedding matrix.
For single-language deployments, >60% of these embeddings are never accessed.
This creates an unnecessary memory and cold-start bottleneck for edge/CPU deployments.
Solution
scripts/prune_gliner_vocab.pytokenises a target-language corpus, identifies theactive token intersection, slices
word_embeddings.weight, rebuildstokenizer.json,and saves a fully self-contained pruned model loadable via
GLiNER.from_pretrained().Benchmark —
urchade/gliner_multi-v2.1(English Wikipedia, 100k articles)Files changed
scripts/prune_gliner_vocab.py— pruning engine (new)scripts/validate_pruned_model.py— 3-tier correctness validator (new)docs/vocab_pruning.md— documentation with benchmarks (new)docs/index.md— added to toctreegliner/modeling/encoder.py— bugfix:token_lengthskwarg leaked into BiEncoderlabels encoder forward pass
gliner/model.py— bugfix: bareimport onnxruntimereplaced with try/exceptUsage
python scripts/prune_gliner_vocab.py \ --model_id urchade/gliner_multi-v2.1 \ --dataset_for_vocab wikipedia \ --output_dir ./pruned_en \ --lang en