Skip to content

fix: handle multiple GLiNER labels share the same span - #238

Open
asteier2026 wants to merge 2 commits into
mainfrom
asteier2026/bugfix/gliner-duplicate-span-score-tiebreak
Open

fix: handle multiple GLiNER labels share the same span#238
asteier2026 wants to merge 2 commits into
mainfrom
asteier2026/bugfix/gliner-duplicate-span-score-tiebreak

Conversation

@asteier2026

Copy link
Copy Markdown
Contributor

Summary

  • resolve_overlaps previously used alphabetical label order as the final tiebreaker when two GLiNER detections shared the exact same character span, causing higher-confidence labels to be silently dropped in favour of lower-confidence ones.
  • Added -item.score to the sort key (before item.label) so the highest-scoring label wins on exact-span ties.

Example: "Mum" was tagged as both relationship (score 0.941) and last_name (score 0.719). Before this fix, last_name won because l < r alphabetically. After, relationship correctly wins.

Test plan

  • Existing test_detection_postprocess.py parametrized test covers the new behaviour — verify it passes with make test
  • Spot-check a rewrite run on a text with relationship/family terms to confirm relationship entities surface correctly

🤖 Generated with Claude Code

@asteier2026
asteier2026 requested a review from a team as a code owner August 6, 2026 15:24
@greptile-apps

greptile-apps Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR changes exact-span overlap resolution to prefer the highest-scoring GLiNER label and adds a regression test for that behavior. It also extends sealed W&B imports with benchmark identity metadata and updates credential handling.

  • Adds score precedence for equal-length, equal-position entity spans.
  • Adds typed benchmark identity fields and CLI options for W&B imports.
  • Preserves launcher-provided WANDB_API_KEY inside the guarded W&B environment.
  • Expands tests and documentation for the new measurement behavior.

Confidence Score: 4/5

The PR is not yet safe to merge because occurrence expansion still replaces original detector provenance with synthetic propagation metadata.

The score-based overlap ordering applies to both detector results and score-1.0 propagation copies; when expansion recreates an original occurrence, the synthetic copy wins and its source and score are emitted in final_entities.

Files Needing Attention: src/anonymizer/engine/detection/postprocess.py and tests/engine/test_detection_postprocess.py

Important Files Changed

Filename Overview
src/anonymizer/engine/detection/postprocess.py Adds confidence-based exact-span selection, but the same precedence still lets synthetic propagation copies replace detector provenance.
tests/engine/test_detection_postprocess.py Covers the intended detector-label confidence tiebreak but does not verify preservation of detector score and source during occurrence expansion.
tools/measurement/import_wandb_run.py Adds validated benchmark identity CLI fields and carries them into sealed-import publication payloads.
tools/measurement/measurement_tools/wandb_models.py Defines benchmark identity validation, comparer projections, and outbound field policies.
tools/measurement/measurement_tools/wandb_setup.py Updates guarded W&B publication behavior to retain launcher-provided API credentials.
tools/measurement/README.md Documents benchmark identity options and environment-based W&B authentication.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  D[Detector entity<br/>real score and detector source] --> E[Expand occurrences]
  E --> P[Propagation copy<br/>score 1.0 and propagation source]
  D --> R[Resolve overlaps]
  P --> R
  R -->|score tiebreak| F[Final entity uses propagation provenance]
Loading

Reviews (3): Last reviewed commit: "fix: prefer highest-scoring label when m..." | Re-trigger Greptile

Comment thread src/anonymizer/engine/detection/postprocess.py
@asteier2026 asteier2026 changed the title fix: prefer highest-scoring label when multiple GLiNER labels share the same span fix: handle multiple GLiNER labels share the same span Aug 10, 2026
lipikaramaswamy and others added 2 commits August 10, 2026 11:27
Signed-off-by: asteier2026 <asteier@nvidia.com>
…he same span

resolve_overlaps previously used alphabetical label order as a tiebreaker for
exact-span matches, causing higher-scoring labels like relationship (0.941) to
be dropped in favour of lower-scoring ones like last_name (0.719). Adding
-score before label in the sort key ensures the highest-confidence label wins.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: asteier2026 <asteier@nvidia.com>
@asteier2026
asteier2026 force-pushed the asteier2026/bugfix/gliner-duplicate-span-score-tiebreak branch from 5bb4fd6 to 06e5aaa Compare August 10, 2026 18:28
@asteier2026
asteier2026 requested a review from a team as a code owner August 10, 2026 18:28
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