Skip to content

Refresh BERTScore IDF when the reference corpus changes - #899

Open
snygginghani wants to merge 1 commit into
huggingface:mainfrom
snygginghani:fix/refresh-bertscore-reference-idf
Open

snygginghani wants to merge 1 commit into
huggingface:mainfrom
snygginghani:fix/refresh-bertscore-reference-idf

Conversation

@snygginghani

Copy link
Copy Markdown

Summary

With idf=True, BERTScore fits importance weights on the reference text. Evaluate caches the scorer by model settings, so a second call with different references can silently use the first call's weights.

Fingerprint the flattened reference corpus and refresh the existing scorer's IDF weights when that corpus changes. This reuses the loaded model and tokenizer. The regression checks a second call with multiple references against a fresh scorer and verifies the original scorer is reused.

Validation

I reproduced the discrepancy with bert-score==0.3.13 and a local all-MiniLM-L6-v2 checkpoint. The offline reproducer in tests/test_bertscore_idf.py builds a local one-layer BERT and checks the public metric API without downloading weights.

  • python -m pytest tests/test_bertscore_idf.py -q passed.
  • Black, isort, flake8 and git diff --check passed on the changed files.

AI assistance was used to investigate and prepare the patch and regression test.

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