Translation Evaluation Beyond BLEU › Building a Toy Learned Metric

Michael BrenndoerferNovember 25, 20264 min read
Language AI HandbookAll chapters
Part 27 of 67Machine Translation and Speech Translation
Chapter 194Translation Evaluation Beyond BLEU › Building a Toy Learned Metric
Reading section 11 of 16 · Building a Toy Learned Metric · 4 minSection 11 of 16 · 4 min

Section 11 of 16 · 4 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

The toy learned metric fits a regression to explicit features, making feature sets easy to compare, whereas published learned metrics can instead use representations from a pretrained encoder.

The four baseline features are BLEU, chrF++, TER, and length ratio. The full model adds number consistency and term adherence. In each training fold, XX is the standardized feature matrix, yy contains centered toy scores, β\beta contains the fitted weights, and α=1\alpha=1 controls the penalty. The intercept is unpenalized.

min⁡β  ∥y−Xβ∥22+α∥β∥22\min_{\beta} \; \|y - X\beta\|_2^2 + \alpha\|\beta\|_2^2

The split that matters

The 58 rows come from eight source segments. Seven or eight variants of the same segment share wording and reference length, so a random row split can put one variant in training and another in evaluation, and the estimate can be optimistic for new source segments. We keep every variant of a segment in one fold.

PythonIn [26]
CollapseExpand
FEATURE_SETS = {
    "learned_lexical": ["bleu", "chrf", "ter", "len_ratio"],
    "learned_full": [
        "bleu",
        "chrf",
        "ter",
        "len_ratio",
        "num_consistency",
        "term_adherence",
    ],
}

gkf = GroupKFold(n_splits=4)

for name, feats in FEATURE_SETS.items():
    oof = np.zeros(len(df))
    for train_idx, test_idx in gkf.split(df, df["mqm"], groups=df["seg_id"]):
        model = make_pipeline(StandardScaler(), Ridge(alpha=1.0))
        model.fit(df.iloc[train_idx][feats], df.iloc[train_idx]["mqm"])
        oof[test_idx] = model.predict(df.iloc[test_idx][feats])
    df[name] = np.clip(oof, 0, 100)

The scaler and model are fitted inside each fold, without using the labels of its held-out groups. The feature definitions were chosen with knowledge of which errors this simulated dataset contains. That choice still limits generalization.

Rank correlation with confidence intervals

We use Spearman correlation for the held-out predictions, and resample entire source groups to show how the estimates vary when a different mix of groups is counted. The intervals keep the fitted predictions fixed and use only eight source groups, so they illustrate sensitivity. They omit uncertainty from retraining and from feature selection.

PythonIn [27]
CollapseExpand
def rank_corr(y_true, y_pred):
    return spearmanr(np.asarray(y_true), np.asarray(y_pred))[0]


def bootstrap_corr_ci(y_true, y_pred, groups, n_boot=1000, seed=0):
    rng = np.random.default_rng(seed)
    y_true = np.asarray(y_true)
    y_pred = np.asarray(y_pred)
    groups = np.asarray(groups)
    group_rows = [
        np.flatnonzero(groups == group) for group in np.unique(groups)
    ]
    vals = []
    for _ in range(n_boot):
        sampled_groups = rng.integers(0, len(group_rows), len(group_rows))
        idx = np.concatenate([group_rows[group] for group in sampled_groups])
        if np.ptp(y_true[idx]) == 0 or np.ptp(y_pred[idx]) == 0:
            continue
        vals.append(rank_corr(y_true[idx], y_pred[idx]))
    return np.percentile(vals, [2.5, 97.5])


CANDIDATES = [
    ("Sentence BLEU", "bleu"),
    ("chrF++", "chrf"),
    ("Learned (lexical only)", "learned_lexical"),
    ("Learned (+ compliance)", "learned_full"),
]

results = []
for label, col in CANDIDATES:
    rho = rank_corr(df["mqm"], df[col])
    lo, hi = bootstrap_corr_ci(df["mqm"], df[col], df["seg_id"])
    results.append({"scorer": label, "rho": rho, "lo": lo, "hi": hi})

results_df = pd.DataFrame(results)
print(results_df.round(3).to_string(index=False))
VisualizationOut [28]
CollapseExpand
Four correlations with source-group bootstrap intervals. The compliance-feature ridge model has the highest point estimate, while the lexical-only ridge model is just below sentence BLEU.
Spearman correlation with the constructed MQM-style scores, with percentile intervals from resampling source groups. The ridge model with compliance features ranks first on this small designed dataset.

The compliance-feature model gives the highest point estimate on this sample. The lexical-only model ranks below sentence BLEU and above chrF++. Before clipping, each fitted ridge model is an affine function of the input features. The glossary and number checks add information about errors the construction deliberately introduced.

Keeping variants of a source in one fold prevents that source from appearing on both sides of a split. It does not correct a feature set chosen with knowledge of the evaluation's error types. A production evaluation should freeze feature choices before checking on a separate human-annotated holdout.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy