Skip to content

Fix explicit negatives dropped when ner_labels is set - #407

Open
GPT-AGI wants to merge 1 commit into
urchade:mainfrom
GPT-AGI:fix-explicit-label-negatives
Open

GPT-AGI wants to merge 1 commit into
urchade:mainfrom
GPT-AGI:fix-explicit-label-negatives

Conversation

@GPT-AGI

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

Copy link
Copy Markdown
Contributor

What was wrong

The training guide explicitly says:

Negative labels (ner_negatives): Entity types to use as negative examples

Its example sets both ner_labels and ner_negatives. batch_generate_class_mappings kept only ner_labels, so the documented negatives never became candidates.

On the docs example (organization / person / date / location plus negatives product, event, money), a uni-encoder mapping was:

['date', 'location', 'organization', 'person']

Bi-encoders looked up ner_label (singular). The documented key ner_labels was ignored, so an example whose gold span was only organization and whose ner_labels were ["organization", "person", "location"] trained as:

['organization']

Relation labels had the same split: rel_labels was kept and rel_negatives was dropped (['works_at'] instead of works_at + founded).

What changed

Predefined label lists still replace randomly sampled in-batch negatives. Explicit ner_negatives / rel_negatives are appended, and duplicates keep the first occurrence so class ids stay contiguous. Bi-encoders read ner_labels, and still accept the old ner_label key.

For per-example uni-encoder and relation mappings, class ids of an existing label list stay 1..n; explicit negatives get the following ids. Bi-encoder candidate ordering keeps its existing shuffled shared-batch behavior, but the candidates now come from the documented ner_labels set. Saved checkpoints are unchanged. Examples that set only ner_labels keep the same candidates.

How verified

Python 3.12, from the clone:

.\.venv\Scripts\python.exe -m pytest -q --tb=line tests\test_explicit_labels.py tests\test_empty_ner.py
.\.venv\Scripts\python.exe -m ruff check gliner\data_processing\processor.py

34 passed. Ruff reported no issues. tests/test_empty_ner.py still covers empty ner_labels and ner_negatives without ner_labels.

Training examples that follow the documented format pass both ner_labels and ner_negatives. The predefined list replaced the negatives, and bi-encoders read the unused key ner_label, so the published label set never reached the model.

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

This branch has not been deployed

No deployments
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.

1 participant