Repository navigation
Fix swapped prediction/reference order in KPI-EDGAR metric - #4350
Open
azrabano23 wants to merge 1 commit into
Open
azrabano23 wants to merge 1 commit into
azrabano23 wants to merge 1 commit into
Conversation
`_request_states_to_pred_gold_pairs` appended `(reference, completion)` while `_compute_stats` unpacks each pair as `(pred_text, gold_text)`, so the model completion was treated as the gold reference and vice versa. `word_macro_f1_score` is symmetric in pred/gold (with adjust=False, F1 = 2*overlap / (num_pred + num_gold)), which hid the swap. `adjusted_macro_f1_score` normalizes tp/fn by num_gold and fp by num_pred, so it changes value under the swap; for the pair gold="revenue increased[kpi], 100[cy], 90[py]", pred="revenue[kpi], 100[cy]" the metric reported 0.45 instead of 0.416667. Build the tuple in the order the consumer and the keyword arguments (`pred_entities=`, `gold_entities=`) expect, and add a regression test on an asymmetric pair that pins the orientation. Fixes stanford-crfm#4348 Signed-off-by: Azra Bano <azrabano.work@gmail.com> Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This branch has not been deployed
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.
What was wrong
KPIEdgarMetricscored the gold reference as if it were the model's prediction, and the prediction as if it were the reference._request_states_to_pred_gold_pairsappended(references[0].output.text, completions[0].text), while_compute_statsunpacks each pair asfor pred_text, gold_text in pred_gold_pairsand passes them on aspred_entities=/gold_entities=.Concrete effect, running
_compute_statson one instance with the realTAG_DICT:Root cause
word_macro_f1_scoreis symmetric in pred/gold: withadjust=False,F1 = 2*overlap / (num_pred + num_gold), which is unchanged under exchange, so that metric masked the swap.adjusted_macro_f1_scorenormalizestp/fnbynum_goldandfpbynum_pred, so swappingnum_predandnum_goldchanges its value. The direction of the error depends on whether the model over- or under-predicts per tag, so it does not average out across instances.The fix
Build the tuple as
(completion, reference), the order the consumer and its keyword arguments already assume. One-line change insrc/helm/benchmark/metrics/kpi_edgar_metrics.py.Adds
src/helm/benchmark/metrics/test_kpi_edgar_metrics.pywith two tests on the asymmetric pair above: one pins the tuple order from_request_states_to_pred_gold_pairs, the other assertsadjusted_macro_f1_score == 5/12throughKPIEdgarMetric.evaluate_instances. Both fail onmain(0.45 != 0.416667) and pass with the fix.Verification
Python 3.12, CPU only. Published KPI-EDGAR
adjusted_macro_f1_scorenumbers computed before this change were computed with the orientation swapped.Fixes #4348
🤖 Generated with Claude Code