Skip to content

Evaluation, diagnostics, benchmarks, and additional tests · Evaluation, diagnostics, benchmarks, and additional hypothesis tests · EVA030 · Metric

BLEU

Scores corpus-level clipped n-gram precision with a brevity penalty against one or more references.

Runs in CodeSplash Complete calculation CodeSplash's run and the reference's record

In CodeSplash

A CodeSplash method runs this entry in Python and R. Set it up from the method's page.

Do it in CodeSplash Run it on your own data, in Python or R.

Availability
Runs in CodeSplash
Code example
Complete calculation
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
Verified in Python and R through evaluate.text. The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Scores corpus-level clipped n-gram precision with a brevity penalty against one or more references.

Question / hypotheses

How much reference n-gram material is reproduced without merely outputting very short candidates?

Architecture / computational structure

A fixed scoring/calibration pipeline applied to model outputs or supplied observations; the formula and usage sections identify its operations.

Assumptions

Tokenization, case, reference selection, maximum n-gram order, effective-order behavior, and smoothing must be fixed. The reference corpus must support the intended comparison.

Formula / computational definition

BLEU=BPexp⁡(∑n=1Nwnlog⁡pn),BP=min⁡(1,e1−r/c).BLEU=BP\exp\left(\sum_{n=1}^{N}w_n\log p_n\right),\quad BP=\min(1,e^{1-r/c}).

Parameters and notation

p_n is corpus clipped precision; c and r are candidate and effective reference lengths. Weights, tokenizer, smoothing, and implementation signature are hyperparameters.

Fitting, fine-tuning, and adaptation

There is no model fine-tuning step for this evaluation procedure. Freeze the evaluated systems and evaluator before the final test. Select evaluation settings on development data; if a learned evaluator or calibration model is adapted, use separate fitting data, version it, and reassess its validity.

How to use and calibrate

Use a standard implementation with its full signature, aggregate corpus counts, and perform paired document-level resampling for system comparisons.

Example application

Compare machine translation outputs on the same test set.

Interpretation / pitfalls

Watch out

Lexical overlap cannot certify factual accuracy or valid paraphrases. Sentence BLEU and averaged sentence BLEU differ from corpus BLEU. A zero high-order count needs an explicitly stated policy.

Python and R code examples

Scope: Mathematical calculation on synthetic inputs; not a complete benchmark pipeline.

Validation: Python — Executed successfully on synthetic inputs. R — reviewed but not executed in this environment. Python dependencies are explicit imports; R uses base R unless a package/bridge is explicitly named.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Complete calculation — Mathematical calculation on synthetic inputs; not a complete benchmark pipeline. · needs numpy

import numpy as np
p=np.array([.8,.6,.4,.2]); c=90; r=100; bp=min(1.,np.exp(1-r/c))
print(100*bp*np.exp(np.log(p).mean()))  # supplied corpus n-gram precisions
R

Complete calculation — Mathematical calculation on synthetic inputs; not a complete benchmark pipeline.

p <- c(.8,.6,.4,.2); candidate.length <- 90; reference.length <- 100
bp <- min(1,exp(1-reference.length/candidate.length)); print(100*bp*exp(mean(log(p))))

Sources

From the CodeSplash reference, entry EVA030.