Sub topic 13
BERTScore options: IDF weighting and baseline rescaling
Prerequisites and the two options
This chapter assumes that you know basic Python, precision, recall, and F1 score. You should also understand that a transformer model produces a contextual embedding for each token. A contextual embedding is a numeric representation whose value depends on the token and its surrounding words.
BERTScore compares candidate and reference tokens by cosine similarity between their contextual embeddings. Two options change how those similarities become final scores:
- IDF weighting gives more influence to tokens that are rare in the reference collection.
- Baseline rescaling converts raw similarity scores to a more readable scale using a language- and model-specific baseline.
These options solve different problems. IDF changes which tokens matter most. Baseline rescaling changes how the final number is displayed and interpreted.
IDF weighting
Inverse document frequency, or IDF, measures how unusual a token is in a collection of documents. A common form is:
\operatorname{IDF}(t)=\log\left(\frac{N}{1+\operatorname{DF}(t)}\right)Here, \(N\) is the number of documents and \(\operatorname{DF}(t)\) is the number of documents containing token \(t\). The added one prevents division by zero.
Words such as “the” occur in many documents, so they receive low weight. A rare technical term receives a higher weight. During BERTScore aggregation, the score contribution from a token is multiplied by its IDF weight. The result gives important, distinctive words more influence than routine words.
The IDF collection matters. If it is too small or unlike the evaluation data, the weights can be unstable. Use the same IDF procedure for every system being compared. Otherwise, the scores do not measure the same thing.
Baseline rescaling
Raw BERTScore values are cosine-similarity aggregates. They often appear close to 1, even when the text is only moderately similar. A raw score of 0.86 has no universal meaning because it depends on the model, language, and data.
Baseline rescaling uses scores expected from unrelated or ordinary sentence pairs for a particular model and language. It shifts and scales the raw result so that scores are easier to interpret. The transformation is approximately:
s'=\frac{s-b}{1-b}where \(s\) is the raw score and \(b\) is the stored baseline. The exact baseline file and implementation determine the reported value.
Rescaling does not make a score factual or human-validated. It also does not make scores from different models directly comparable. Report the model, language, IDF setting, and rescaling setting with every result.
Using the options in Python
The bert_score package exposes both options directly:
from bert_score import score
candidates = [
"The cat sat on the mat."
]
references = [
"A cat was sitting on the rug."
]
raw_p, raw_r, raw_f1 = score(
candidates,
references,
lang="en",
idf=False,
rescale_with_baseline=False,
)
weighted_p, weighted_r, weighted_f1 = score(
candidates,
references,
lang="en",
idf=True,
rescale_with_baseline=True,
)
print("raw F1:", raw_f1.mean().item())
print("IDF-weighted, rescaled F1:", weighted_f1.mean().item())The two F1 values answer different reporting questions. The first uses unweighted raw matching. The second emphasizes tokens according to IDF and then applies baseline rescaling. Do not describe the second value as simply a “better” score.
Reporting checklist
| Item | What to report |
|---|---|
| Model | Model name and language |
| Aggregation | Precision, recall, and F1 |
| IDF | Whether it was enabled and how weights were built |
| Rescaling | Whether baseline rescaling was enabled |
Exercise
Why can IDF weighting change the ranking of two systems, while baseline rescaling usually cannot change their ranking under the same configuration?
Show answer
IDF weighting changes the relative contribution of tokens, so systems can be rewarded differently for rare words. Baseline rescaling applies the same monotonic scale transformation to both scores, so their order normally stays the same.