Skip to content

Speed up SQuAD v2 scoring by reusing normalized answers - #893

Open
snygginghani wants to merge 1 commit into
huggingface:mainfrom
snygginghani:perf/squad-v2-scoring
Open

snygginghani wants to merge 1 commit into
huggingface:mainfrom
snygginghani:perf/squad-v2-scoring

Conversation

@snygginghani

Copy link
Copy Markdown

Summary

SQuAD v2 scoring normalizes each reference while filtering it and again for exact match and F1. It also normalizes and counts prediction tokens for every reference. This change normalizes each answer once and reuses the prediction token counts across references.

Validation

  • The public evaluate.load(...).compute(...) path returned identical values for all 13 result fields on 11,873 questions from the official SQuAD v2 development set.
  • Median public API latency on Windows and Python 3.13.3 fell from 845.8 ms to 396.3 ms (2.13× faster). I alternated baseline and patched order across eight calls to each local metric, used in-memory computation, and excluded import and dataset loading time.
  • To reproduce the input, take each question's first annotated answer or an empty string, append Bogotá! to every other prediction starting with the first, and set each no-answer probability to the zero-based question index modulo 11 divided by 10. Use a no-answer threshold of 0.6.
  • Added four local regression cases covering repeated tokens, multiple references, punctuation, and empty or article-only answers. The focused metric and local loader tests returned 30 passed and 1 skipped.

The implementation and benchmark were prepared with AI assistance.

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