Skip to content

10.5 Sequence metrics: exact match, BLEU, chrF

The seq2seq models of this chapter now write dates, and soon translations and stories. The training loss says how surprised a model is by the reference, not whether what it generates is right: beam search can produce a fluent output the loss never saw. So the system needs metrics over generated text. The simplest, exact match, is the bar for the dates task, because a date is right or wrong. For free text, the field reports BLEU and chrF, and reports them in one exact configuration: sacreBLEU’s. Two “BLEU” implementations that differ in tokenization or smoothing disagree by several points on the same output, which is larger than most of the improvements papers claim.

Concepts from other sections (2)

This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.

This section builds all three metrics from their sufficient statistics, matches sacreBLEU to twelve digits, and attaches a bootstrap interval, so every number that the LM evaluation harness prints later is both comparable and honest about its noise. The one prerequisite is bootstrap_ci from LLN, CLT, confidence intervals, bootstrap in Mathematics, which supplies the interval every score carries; the companion problem set on LLN, CLT, and confidence intervals is good practice.

The solution is python/tinyllm/eval/seqmetrics.py, with exact_match, tokenize_13a, bleu_stats, bleu_from_stats, corpus_bleu, chrf_stats, chrf_from_stats, chrf, sentence_stats, score_from_stats, and metric_ci. It implements the contract course/contracts/py/tinyllm/eval/seqmetrics.pyi, and the oracle tests are in test_seqmetrics.py. The translate verb of the {tinyllm} CLI reports these metrics.

Learning objectives

  • Compute BLEU by hand: clipped n-gram precisions, exp smoothing, the geometric mean, and the brevity penalty against the closest reference.
  • Compute chrF by hand from character n-gram counts, and explain why it forgives inflection.
  • Explain why a corpus score pools sufficient statistics rather than averaging sentence scores.
  • Attach a bootstrap interval that resamples whole sentences and rescores the pooled statistics.
  • Name the settings (tokenizer, smoothing, case, reference layout) that make a BLEU number comparable.
SymbolMeaningType
hh, {r1,…,rK}\{r_1, \dots, r_K\}one hypothesis and its referencesstrings
cnth(g)\mathrm{cnt}_h(g), cntr(g)\mathrm{cnt}_{r}(g)how many times n-gram gg occurs in hh or rrint
mn=∑gmin⁡(cnth(g),max⁡kcntrk(g))m_n = \sum_{g} \min(\mathrm{cnt}_h(g), \max_k \mathrm{cnt}_{r_k}(g))clipped matches of order nn (sum over the nn-grams gg of hh)int
tnt_nnumber of nn-grams in hhint
cc, rrhypothesis length in tokens; length of the reference closest to cc (ties to the shorter)int
pn=mn/tnp_n = m_n / t_nmodified precision of order nnfloat
BP\mathrm{BP}brevity penalty, 11 if c≥rc \ge r, else e1−r/ce^{1 - r/c}float
PkP_k, RkR_kchrF character precision and recall of order kkfloat
β\betarecall weight of chrF (2: recall counts β2=4\beta^2 = 4 times)float
NNnumber of sentences in the corpusint

Start with the easy one. Exact match is the fraction of hypotheses equal to their reference after removing white space at both ends; a decoder’s trailing newline is a formatting artifact, not an error. Case and inner white space count, because they change the meaning of a date. Normalized variants (SQuAD lowercases and drops articles) are different metrics with different names.

BLEU counts words, so it needs a tokenizer, and the tokenizer is part of the metric. sacreBLEU’s default, 13a, reproduces the WMT mteval-v13a script. It removes <skipped>, joins a word broken by - at a line end, unescapes &quot; &amp; &lt; &gt;, puts spaces around punctuation and symbols, splits a period or comma except between two digits (so 3.14 and 1,000 stay whole), and splits a dash only after a digit (10-12 becomes 10 - 12, e-mail stays). The line is right-stripped first. tokenize="none" splits on white space only. To be comparable with published BLEU, 13a must be reproduced regex for regex, including its digit exceptions.

BLEU’s definition (Papineni et al.) is a corpus-level ratio of counts, not an average of sentence scores, so the unit of computation is a fixed-length vector of counts per sentence. For one hypothesis, keep ten numbers: [c,r,m1..m4,t1..t4][c, r, m_1..m_4, t_1..t_4].

Clipping is the heart of BLEU. Without the min⁡\min in mnm_n, “the the the the” would score a perfect unigram precision against “the cat”. With several references, a hypothesis nn-gram may match up to the largest count of that nn-gram in any one reference: the references are merged by taking the per-gram maximum, not the sum. Then

BLEU=100⋅BP⋅exp⁡(14∑n=14log⁡pn).\mathrm{BLEU} = 100 \cdot \mathrm{BP} \cdot \exp\Big(\tfrac{1}{4}\sum_{n=1}^{4} \log p_n\Big).

The geometric mean means one zero precision zeroes the score, so zeros must be smoothed, and smoothed in one specific way to be comparable. sacreBLEU’s default “exp” smoothing replaces the jj-th zero precision by 1/(2jtn)1 / (2^j t_n), halving the stand-in each time another zero order appears. Two exceptions remain: if nothing matches at all the score is 00, and an order with tn=0t_n = 0 (every hypothesis shorter than nn tokens) ends the loop and counts as log⁡0\log 0, so such a corpus scores 00.

The brevity penalty exists because precision alone rewards short output: a one-word hypothesis that is correct has p1=1p_1 = 1. The penalty needs one reference length, and it compares cc with the reference length closest to cc, ties to the shorter, as sacreBLEU does. It applies only when the hypothesis is shorter.

chrF is the same pattern on characters. It removes white space and counts character nn-grams of orders k=1..6k = 1..6. Per order it keeps three numbers, [hypothesis count, reference count, matches], where matches are clipped as in BLEU, and the hypothesis count is 00 for an order the reference has no nn-gram of (sacreBLEU’s rule). Averaging over the orders where both counts are positive gives Pˉ\bar P and Rˉ\bar R, and a single FβF_\beta is taken from the averages, not an average of per-order Fs:

chrF=100⋅(1+β2) PˉRˉβ2Pˉ+Rˉ.\mathrm{chrF} = 100 \cdot \frac{(1 + \beta^2)\, \bar P \bar R}{\beta^2 \bar P + \bar R}.

With several references, a sentence keeps the statistics of the reference with the best sentence chrF, the first one on a tie. Characters make chrF kinder to morphology: “cats” shares “c”, “a”, “t”, “ca”, “at”, “cat” with “cat”, where BLEU sees a miss.

Both metrics are functions of sums of per-sentence statistics, so a corpus score is computed once from the column sums. The mean of sentence BLEUs is a different, worse-behaved number: on a two-sentence corpus, 31.26 pooled against 36.96 averaged.

Pooling also makes the bootstrap cheap. sentence_stats gives an N×SN \times S matrix, and metric_ci calls bootstrap_ci on the indices 0..N−10..N-1 with the statistic “sum the resampled rows, then score”. Each resample keeps a hypothesis with its own references, so the bootstrap distribution is of the same metric that is reported. A score without an interval is a guess.

One surprise the tests pin down: smoothing is not scale-invariant, so a sentence counted twice in a resample can score differently from the sentence alone, because its zero-order precision becomes 1/(2⋅2tn)1/(2 \cdot 2t_n).

Each metric gets one hand-worked example, and a correct solution reproduces all three numbers exactly.

Let hh = “the cat sat on the mat” and rr = “the cat is on the mat”. Both have 6 tokens, so c=r=6c = r = 6 and BP=1\mathrm{BP} = 1. The n-gram counts:

nnhypothesis nn-gramsmatched (clipped)pnp_n
1the ×2, cat, sat, on, matthe ×2, cat, on, mat5/65/6
2the cat, cat sat, sat on, on the, the matthe cat, on the, the mat3/53/5
3the cat sat, cat sat on, sat on the, on the maton the mat1/41/4
4the cat sat on, cat sat on the, sat on the matnone: smoothed to 1/(2⋅3)1/(2 \cdot 3)1/61/6

So the statistics are [6,6,5,3,1,0,6,5,4,3][6, 6, 5, 3, 1, 0, 6, 5, 4, 3] and BLEU=100⋅(56⋅35⋅14⋅16)1/4=100⋅(1/48)1/4=37.991784\mathrm{BLEU} = 100 \cdot (\tfrac{5}{6} \cdot \tfrac{3}{5} \cdot \tfrac{1}{4} \cdot \tfrac{1}{6})^{1/4} = 100 \cdot (1/48)^{1/4} = 37.991784.

Let hh = “cat” and rr = “cats”. Per order:

kkhyp, ref, matchPkP_kRkR_k
13, 4, 313/4
22, 3, 212/3
31, 2, 111/2
40, 1, 0 (no hypothesis 4-gram)skippedskipped
5, 60, 0, 0skippedskipped

Pˉ=1\bar P = 1, Rˉ=(3/4+2/3+1/2)/3=23/36\bar R = (3/4 + 2/3 + 1/2)/3 = 23/36, and chrF=100⋅5PˉRˉ/(4Pˉ+Rˉ)=100⋅115/167=68.862275\mathrm{chrF} = 100 \cdot 5 \bar P \bar R / (4 \bar P + \bar R) = 100 \cdot 115/167 = 68.862275.

Hypotheses “2021-05-03”, ” 2021-05-04\n”, “2021-5-3” against “2021-05-03”, “2021-05-04”, “2021-05-03”: the first matches, the second matches after stripping, the third does not (5 is not 05). EM =2/3= 2/3.

TOKENIZERS = ("13a", "none")
def tokenize_13a(line: str) -> str
def exact_match(hyps: Sequence[str], refs: Sequence[str]) -> float # 0..1
def bleu_stats(hyp: str, refs: Sequence[str], tokenize: str = "13a") -> list[int] # 10 numbers
def bleu_from_stats(stats: Sequence[float]) -> float # 0..100
def corpus_bleu(hyps: Sequence[str], refs: Sequence[Sequence[str]], tokenize: str = "13a") -> float
def chrf_stats(hyp: str, refs: Sequence[str], n: int = 6, beta: float = 2.0) -> list[int] # 3 n numbers
def chrf_from_stats(stats: Sequence[float], n: int = 6, beta: float = 2.0) -> float # 0..100
def chrf(hyps: Sequence[str], refs: Sequence[Sequence[str]], n: int = 6, beta: float = 2.0) -> float
def sentence_stats(metric: str, hyps, refs) -> NDArray # [N, S] float64
def score_from_stats(metric: str, summed: NDArray, n_sentences: int) -> float
def metric_ci(metric, hyps, refs, n_boot=1000, alpha=0.05, rng=None) -> tuple[float, float, float]

Every metric is split into a statistics function and a scoring function, so the same rows serve the corpus score, any sub-corpus, and every bootstrap resample. refs[i] is the list of references of hyps[i]; sacreBLEU’s own API takes reference streams, the transpose. A bare string there is a TypeError, because otherwise each character would silently become a reference.

The tokenizer is four regexes over a padded line, then a white-space split and rejoin:

_13A = [
# symbols and punctuation: { | } ~ [ \ ] ^ _ ` space ! " # $ % & ( ) * + : ; < = > ? @ /
(re.compile(r"([\{-\~\[-\` -\&\(-\+\:-\@\/])"), r" \1 "),
# period and comma unless preceded by a digit
(re.compile(r"([^0-9])([\.,])"), r"\1 \2 "),
# period and comma unless followed by a digit
(re.compile(r"([\.,])([^0-9])"), r" \1 \2"),
# dash when preceded by a digit
(re.compile(r"([0-9])(-)"), r"\1 \2 "),
]
def tokenize_13a(line):
line = line.replace("<skipped>", "").replace("-\n", "").replace("\n", " ")
if "&" in line:
line = line.replace("&quot;", '"').replace("&amp;", "&")
line = line.replace("&lt;", "<").replace("&gt;", ">")
line = f" {line} " # so the "not a digit" rules see a neighbour at the ends
for pattern, repl in _13A:
line = pattern.sub(repl, line)
return " ".join(line.split())

3.14 survives because both period rules need a non-digit on one side; 10-12 splits because the dash follows a digit.

def bleu_stats(hyp, refs, tokenize="13a"):
refs = _ref_list(refs) # a bare str raises TypeError
max_ref = Counter()
ref_lens = []
for r in refs:
toks = _tokens(r, tokenize) # rstrip, then 13a or plain split
ref_lens.append(len(toks))
for g, c in _word_ngrams(toks).items():
if c > max_ref[g]:
max_ref[g] = c # per-gram MAX over references
htoks = _tokens(hyp, tokenize)
correct = [0] * MAX_ORDER
total = [0] * MAX_ORDER
for g, c in _word_ngrams(htoks).items():
total[len(g) - 1] += c
correct[len(g) - 1] += min(c, max_ref[g]) # clipping
return [len(htoks), _closest_ref_len(len(htoks), ref_lens)] + correct + total

For “the cat sat on the mat” against “the cat is on the mat” this returns [6,6,5,3,1,0,6,5,4,3][6, 6, 5, 3, 1, 0, 6, 5, 4, 3], the row worked by hand. _closest_ref_len scans references keeping the smallest ∣c−r∣|c - r| and, on equal distance, the shorter rr.

Scoring the statistics uses sacreBLEU’s arithmetic, logs of percentages, so the result is already in 0..100:

def bleu_from_stats(stats):
# ... (exactly 10 numbers)
sys_len, ref_len = stats[0], stats[1]
correct, total = stats[2 : 2 + MAX_ORDER], stats[2 + MAX_ORDER :]
if not any(correct):
return 0.0 # nothing matched at all
bp = 1.0
if sys_len < ref_len: # only short output is penalized
bp = math.exp(1.0 - ref_len / sys_len) if sys_len > 0 else 0.0
logs = [LOG_ZERO] * MAX_ORDER # sacreBLEU's log(0)
smooth = 1.0
for n in range(MAX_ORDER):
if total[n] == 0:
break # no n-grams of this order: stays log 0
if correct[n] == 0:
smooth *= 2.0 # j-th zero order -> 1 / (2^j t_n)
logs[n] = math.log(100.0 / (smooth * total[n]))
else:
logs[n] = math.log(100.0 * correct[n] / total[n])
return bp * math.exp(sum(logs) / MAX_ORDER) # geometric mean, times BP

In the hand example the single zero 4-gram order makes smooth 2, so the stand-in is 1/(2⋅3)1/(2 \cdot 3) and the score is 100⋅(1/48)1/4=37.991784100 \cdot (1/48)^{1/4} = 37.991784. corpus_bleu sums bleu_stats over sentences element by element and calls bleu_from_stats once.

def _char_ngrams(line, n):
"""Character n-gram counts of orders 1..n, white space removed."""
s = "".join(line.split())
return [Counter(s[i : i + k] for i in range(len(s) - k + 1)) for k in range(1, n + 1)]
def chrf_stats(hyp, refs, n=CHRF_N, beta=CHRF_BETA):
# ... (n, beta checks; refs as a list)
hyp_grams = _char_ngrams(hyp, n)
best, best_f = None, -1.0
for r in refs:
stats = []
for h, g in zip(hyp_grams, _char_ngrams(r, n)):
match = sum(min(c, g[x]) for x, c in h.items() if x in g) # clipped matches
# sacreBLEU's rule: the hypothesis count is 0 when the reference has no k-gram.
stats += [sum(h.values()) if g else 0, sum(g.values()), match]
f = chrf_from_stats(stats, n, beta)
if f > best_f: # strict: the first reference wins a tie
best, best_f = stats, f
return best
def chrf_from_stats(stats, n=CHRF_N, beta=CHRF_BETA):
# ... (checks)
factor = beta**2
prec = rec = 0.0
orders = 0
for k in range(n):
n_hyp, n_ref, n_match = stats[3 * k : 3 * k + 3]
if n_hyp > 0 and n_ref > 0: # only orders both sides have
prec += n_match / n_hyp
rec += n_match / n_ref
orders += 1
if orders == 0:
return 0.0
prec, rec = prec / orders, rec / orders # average P and R first ...
if prec + rec == 0:
return 0.0
return 100.0 * (1 + factor) * prec * rec / (factor * prec + rec) # ... then one F_beta

For “cat” against “cats”, orders 1 to 3 contribute and Rˉ=23/36\bar R = 23/36, so the score is 100⋅5⋅23/36/(4+23/36)=100⋅115/167100 \cdot 5 \cdot 23/36 / (4 + 23/36) = 100 \cdot 115/167.

Exact match is h.strip() == r.strip() averaged. The interval wraps all three metrics in one shape:

def metric_ci(metric, hyps, refs, n_boot=1000, alpha=0.05, rng=None):
if rng is None:
raise ValueError("metric_ci needs an rng (a PCG32): the interval must be reproducible")
rows = sentence_stats(metric, hyps, refs) # [N, S]: 1, 10 or 18 columns
def stat(idx):
picked = rows[np.asarray(idx, dtype=np.int64)] # a resample of whole sentences
return score_from_stats(metric, picked.sum(axis=0), len(picked))
# bootstrap_ci resamples the indices 0..N-1; the statistic re-pools and rescores.
point, lo, hi = bootstrap_ci(np.arange(len(rows), dtype=np.float64), stat, n_boot, alpha, rng)
return float(point), float(lo), float(hi)

metric_ci reproduces an independent sacreBLEU bootstrap run seed for seed. The full solution is seqmetrics.py.

BLEU statistics cost O(L)O(L) per sentence for LL tokens (four orders), and chrF O(nC)O(n C) for CC characters. The bootstrap costs O(B⋅NS)O(B \cdot N S) for BB resamples, because each resample only sums precomputed rows; recomputing n-grams per resample would cost O(B⋅corpus size)O(B \cdot \text{corpus size}).

Why match sacreBLEU instead of writing a “cleaner” BLEU? Any change in tokenization, smoothing, or case moves scores by more than typical improvements (Post 2018). Matching the de facto standard makes every number comparable; the cost is reproducing quirks such as LOG_ZERO and the break on empty orders.

Why sufficient statistics rather than a direct corpus function? The same rows give the corpus score, any sub-corpus score, and every bootstrap resample, where a direct function would have to be rerun on raw text each time.

Why does exact match strip only the ends? It is a strict metric by design. A trailing newline from a decoder is a formatting artifact, while case and inner spacing change the meaning of a date.

The tradeoff accepted is that smoothing is not scale-invariant, so a resample that duplicates a sentence can score differently from the sentence alone. The solution accepts this to stay identical to sacreBLEU’s bootstrap.

The suite test_seqmetrics.py uses oracle values: numbers computed by hand from the definitions, never numbers the code printed. It covers the three hand examples; a clipping case; a closest-reference case where the closest is the longer reference; the brevity penalty both ways; a smoothed zero order; pooled statistics against a mean; the per-hypothesis layout; 13a keeping 3.14 whole; case; a chrF order that needs n=6n = 6; white space in chrF; the best reference; exact match with a strip and with case; and an interval on a two-sentence corpus where every resample can be listed by hand. Each pitfall in the next section makes at least one of these tests fail.

The full set of behaviors a correct solution must have:

CaseKind of checkChecksWhy it matters downstream
hand example: BLEUunitthe hand-worked BLEU statistics and 37.991784pins down the definition
hand example: chrFunitthe hand-worked chrF statistics and 100⋅115/167100 \cdot 115/167the same for chrF
hand example exact matchunit2/3, with the stripthe dates-task bar
clippingboundary“the the the the” matches one unigramrepetition never pays
closest reference lengthboundaryclosest, ties to the shorter, longer when closerthe brevity penalty with several references
brevity penaltyunite1−r/ce^{1 - r/c} when short, nothing when longdropping hard words is not rewarded
smoothing and zero ordersboundary“exp” smoothing values; no match and no 4-gram give 0short outputs of the dates task
corpus pools statisticspropertypooled sums, not the mean of sentence scoresthe corpus number the harness reports
references are per hypothesisboundaryper-hypothesis layout; variable counts; a bare string failsthe zoo passes one reference per row
13a tokenizer matches sacreBLEUgolden15 lines through 13acomparable token counts
BLEU matches sacreBLEUgoldenstatistics and score on 26 corpora, both tokenizerscomparable with published BLEU
case countsunitcase-sensitive by defaultno silent inflation
chrF matches sacreBLEUgoldenstatistics and score on 16 corporacomparable with published chrF
chrF ignores white space and forgives inflectionunitwhite space removed; “cats” vs “cat”why chrF sits beside BLEU
chrF β\beta weights recallunitβ2\beta^2, and β\beta is a parameterrecall-weighted F
chrF uses the best referenceunitthe best reference, not an average or the lastseveral references per sentence
exact match is strict insideboundarycase and inner spaces counta date is right or wrong
metric_ci matches an independent bootstrapgolden6 intervals equal an independent sacreBLEU bootstrapevery harness number carries this CI
metric_ci brackets the scorepropertyreproducible, in range, degenerate when every pair matchesresampling keeps pairs together
validationboundarymismatched lengths, empty corpus, unknown names, missing rnga silent 0 hides a broken pipeline

The common mistakes all produce a plausible number that is simply not BLEU or chrF as anyone else computes it:

PitfallSymptomHow the solution avoids it
counting n-gram matches without clipping“the the the the” scores like “the cat”min(c, max_ref[g]) in bleu_stats
brevity penalty against the shortest reference, or applied to long hypotheses tooscores drop for outputs of the right length_closest_ref_len (ties to the shorter); BP only if sys_len < ref_len
corpus BLEU as the mean of sentence BLEUs36.96 instead of 31.26 on two sentencescorpus_bleu sums the ten statistics, then scores once
the wrong reference layout: a bare string, or sacreBLEU’s streamseach character becomes a reference; pairs scored against the wrong sentence_ref_list rejects a bare str; refs[i] is the list for hyps[i]
arithmetic mean of precisions, or no smoothingscores far too high, or 0 for any output missing one 4-grammean of logs (geometric mean); smooth *= 2.0 for each zero order
a different tokenizer or case rule3.14 split in three; “The” matches “the”the four _13A regexes exactly as sacreBLEU; no lowercasing
chrF with white space kept, β\beta not squared, per-order F averaged, or orders 1 to n−1n-1chrF off by several points"".join(line.split()); factor = beta**2; average PP and RR first, then one F; range(1, n + 1)
chrF keeping the last reference instead of the besta bad extra reference lowers the scorechrf_stats keeps the stats with the highest sentence chrF, > so the first wins ties
exact match that ignores case, or does not strip“Paris” equals “paris”; a trailing newline is an errorh.strip() == r.strip(), nothing more
a bootstrap that averages sentence scoresan interval for a different metric than the one reportedstat sums resampled rows and calls score_from_stats

Warning: The tokenizer, the smoothing, the case rule, and the reference layout are part of the metric. Change one and the number is no longer comparable with anything published, even though it is still called BLEU.

The LM evaluation harness and the model zoo scores the zoo’s seq2seq and transformer rows with these functions, reporting EM and chrF columns each with its interval. Multimodal eval metrics computes caption BLEU-4 and chrF through corpus_bleu and chrf. Outside this book, Agent evaluation scorers in AI Engineering re-implements exact match in Go, and Mutation testing in depth in Software Engineering uses this section’s test suite as its example of surviving faults, both equivalent ones and missed ones.

Production tooling goes further:

This pieceProduction equivalentWhat it addsWhere to look
corpus_bleu, chrfsacreBLEUsignatures that name every setting, other tokenizers (intl, zh, ja-mecab), chrF++ word n-grams, TERsacrebleu/metrics/bleu.py, chrf.py
metric_cisacreBLEU paired bootstrap and approximate randomizationsignificance of the DIFFERENCE between two systems on the same sentencessacrebleu/significance.py
exact matchSQuAD and HF evaluatenormalized EM and token F1 for extractive QAevaluate/metrics/squad
string metricsCOMET, BLEURTlearned metrics that correlate better with human judgmentRei et al. (2020), Sellam et al. (2020)
  • Papineni et al., “BLEU: a Method for Automatic Evaluation of Machine Translation” (ACL 2002).
  • Popovic, “chrF: character n-gram F-score for automatic MT evaluation” (WMT 2015).
  • Post, “A Call for Clarity in Reporting BLEU Scores” (WMT 2018).
  • Koehn, “Statistical Significance Tests for Machine Translation Evaluation” (EMNLP 2004).
  • exact match: the fraction of hypotheses equal to their reference after stripping white space at both ends.
  • clipping: crediting a hypothesis n-gram at most as many times as it occurs in any one reference.
  • modified precision: pn=mn/tnp_n = m_n / t_n, clipped matches over hypothesis n-grams of order nn.
  • brevity penalty: e1−r/ce^{1 - r/c} when the hypothesis is shorter than the closest reference, else 1.
  • exp smoothing: sacreBLEU’s replacement of the jj-th zero precision by 1/(2jtn)1/(2^j t_n).
  • chrF: a recall-weighted F score over character n-grams of orders 1 to 6, white space removed.
  • sufficient statistics: the per-sentence count vectors whose column sums determine the corpus score.
  • BLEU counts word n-grams of orders 1 to 4 that the hypothesis shares with a reference, clipped by the reference counts, takes the geometric mean of the four precisions, and multiplies by a brevity penalty measured against the reference closest in length.
  • A corpus score pools sufficient statistics over sentences; it is not the mean of sentence scores. Pooling is also what makes a bootstrap over sentences cheap.
  • chrF counts character n-grams with white space removed, averages precision and recall over orders 1 to 6, and weights recall by β2=4\beta^2 = 4; it forgives “cats” for “cat” where BLEU sees a miss.
  • The tokenizer, the smoothing, the case rule, and the reference layout are part of the metric: matching sacreBLEU’s defaults exactly makes the numbers comparable with published scores.
  • A score without an interval is a guess: metric_ci resamples sentences with a bootstrap and reproduces an independent sacreBLEU run seed for seed.
  1. Why is the corpus BLEU of two sentences not the mean of their sentence BLEUs?
    AnswerBLEU is a geometric mean of pooled precisions times a pooled brevity penalty, a nonlinear function of summed counts. Averaging sentence scores applies the nonlinearity per sentence, which weights short sentences and smoothed zeros very differently (31.26 pooled against 36.96 averaged on the example corpus).
  2. With two references, why is the clip the maximum count in one reference and not the sum over references?
    AnswerEach reference is a complete valid output. A word that appears once in each of two references is still correct only once in a single sentence; summing would let a hypothesis repeat it and be credited twice.
  3. In the worked example, where does the 1/61/6 for the 4-gram precision come from?
    AnswerNo 4-gram matched, so exp smoothing applies: it is the first zero order, so `smooth` becomes 2 and the stand-in precision is $1/(2 \cdot t_4) = 1/(2 \cdot 3)$.
  4. Why does chrF average PP and RR over orders before forming FβF_\beta?
    AnswerThat is chrF's definition in sacreBLEU. Averaging per-order F scores is a different metric and gives different numbers, so it would not be comparable with published chrF.
  5. Why does metric_ci resample row indices rather than resampling hypotheses and references separately?
    AnswerA hypothesis is only meaningful against its own references. Resampling rows keeps each pair together, and summing the picked rows before scoring makes the interval describe the same pooled metric that is reported.