Skip to content

Fix distillation spans dropped beside punctuation - #406

Merged
Ingvarstep merged 1 commit into
urchade:mainfrom
GPT-AGI:fix-distill-punctuation-spans
Nov 11, 2026
Merged

Ingvarstep merged 1 commit into
urchade:mainfrom
GPT-AGI:fix-distill-punctuation-spans

Conversation

@GPT-AGI

@GPT-AGI GPT-AGI commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

What was wrong

compress_prompt_embeddings(..., distill=True) turns character spans from inference into word indexes with str.split(). That keeps punctuation on the word (Honolulu,, Hawaii.). Inference tokenizes with the model word splitter, which separates the comma and the period, so the predicted spans match neither split word and are omitted from the fine-tune set.

text = "Born in Honolulu, Hawaii."
preds = spans for "Honolulu" and "Hawaii" (the tokens WhitespaceTokenSplitter emits)
_predictions_to_word_level ->
{'tokenized_text': ['Born', 'in', 'Honolulu,', 'Hawaii.'], 'ner': []}

The usage docs generate those pseudo-labels from sentences such as "Barack Obama was born in Honolulu, Hawaii."

What changed

Word boundaries now come from data_processor.words_splitter, the same splitter inference uses. A span is kept when its stripped character range lands on those token bounds. predict_entities output is unchanged. Only the training examples built for distill=True change, and only their word tokenization.

How verified

Python 3.12, from the clone:

.\.venv\Scripts\python.exe -m pytest -q --tb=line tests\test_distill_word_level.py
.\.venv\Scripts\python.exe -m ruff check gliner\model.py

2 passed. Ruff reported no issues. The same sentence now yields ner == [(2, 2, "location"), (4, 4, "location")] on tokens ["Born", "in", "Honolulu", ",", "Hawaii", "."].

Pseudo-label alignment used str.split, which keeps commas and periods on the word. Spans predicted on the model's own tokens then matched no word and were left out of the fine-tune set.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Ingvarstep

Copy link
Copy Markdown
Collaborator

Hi @GPT-AGI , thanks for fixing it.

@Ingvarstep
Ingvarstep merged commit beb41b3 into urchade:main Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants