Translation Evaluation Beyond BLEU › Building a Toy Learned Metric
Language AI HandbookAll chapters 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, is the standardized feature matrix, contains centered toy scores, contains the fitted weights, and controls the penalty. The intercept is unpenalized.
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]Expand
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]Expand
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]Expand

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!