Skip to content

Fix MedLink BM25 hard-negative mining - #1195

Open
fbonc wants to merge 2 commits into
sunlabuiuc:masterfrom
fbonc:medlink-fix
Open

Fix MedLink BM25 hard-negative mining#1195
fbonc wants to merge 2 commits into
sunlabuiuc:masterfrom
fbonc:medlink-fix

Conversation

@fbonc

@fbonc fbonc commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Problem
get_bm25_hard_negatives scored the corpus against the positive document (bm25_model.get_scores(d)) instead of the query (q), which is bad. Hard negatives are supposed to be documents the query ranks highly but that aren't the answer.

A second bug too. the negative selection excluded only the current positive (ned_d_id != d_id). Once scoring is fixed to the query, all of a query's positives rank at the top, so excluding just one lets another true positive be chosen as a negative (a false negative) whenever a query has more than one match which record linkage allows.

Fix
Score against the query, and exclude all of the query's positives (neg_d_id not in d_ids), not just the current one.

Tests
Added two regression tests (controlled fake BM25): one asserting the negative comes from scoring the query (not the positive doc), one asserting no positive is ever selected as a negative when a query has multiple positives.

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