svgtext-metric-ci
Corpus scores with intervals
Which system scores higher on each metric, and is the gap larger than the resampling noise?
How to read it
- Read each row as one metric: the dot is the corpus score and the bar its bootstrap interval.
- Compare dots of different colours within a metric to see which system scores higher.
- Use the method's paired p-value to judge the gap; intervals that overlap can still differ significantly.
- Callout 1: A corpus score with its interval.
- Callout 2: A second system on the same metric.
- Callout 3: A wide interval: few rows or very uneven outputs.
Watch out
- The interval reflects which rows happened to be tested, not how well the references capture good answers.
- A higher BLEU is not a better system unless people or a judge agree.
Defaults
No settings: the chart draws one way.
Pinned in the code
- Draws what the Python or R engine computed; the chart computes nothing statistical.
- Intervals are paired bootstrap percentile intervals over rows (Koehn 2004) on the shared Wichmann–Hill stream: every replicate resamples the same rows for every system.
- Corpus BLEU and chrF pool n-gram counts over rows before forming the score; ROUGE is the mean of row F1 values. None is a mean of the row-level dots.
- Overlapping intervals do not by themselves mean no difference; the method's paired p-value against the first system answers that.
# Corpus scores with intervals — Codesplash Chart Lab (recipe "text-metric-ci")
# controls: defaults
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
try:
import codesplash as cs # optional: the app's chart theme
except ImportError:
cs = None
if cs:
cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]
df = pd.read_csv("text-metric-ci-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["metric"] = pd.Categorical(df["metric"].astype("string"), categories=["BLEU", "chrF", "ROUGE-1", "ROUGE-2", "ROUGE-L"])
df["system"] = pd.Categorical(df["system"].astype("string"), categories=["baseline", "fine-tuned"])
_tokens = cs.palette(dark=False) if cs else {}
SEQ = _tokens.get("sequential", ["#eff6fd", "#1a469d"]) # sequential ramp (low → high)
DIV = _tokens.get("diverging", ["#c13e2e", "#f3f5f8", "#0859ac"]) # negative, midpoint, positive
REF = _tokens.get("reference", "#4e5661")
GREY = _tokens.get("dim", "#ced1d6")
def levels_of(s):
"""Declared level order (categoricals), else order of first appearance."""
if isinstance(s.dtype, pd.CategoricalDtype):
return [v for v in s.cat.categories if (s == v).any()]
return list(dict.fromkeys(s.dropna().astype(str)))
M = "metric"
EST = "score"
LO = "lower"
HI = "upper"
SYS = "system"
d = df.dropna(subset=[M, EST])
metrics = levels_of(d[M])
systems = levels_of(d[SYS]) if SYS else [None]
fig, ax = plt.subplots(figsize=(7, 0.6 * len(metrics) * max(1, len(systems)) + 1.2))
for j, s in enumerate(systems):
for i, m in enumerate(metrics):
r = d[(d[M].astype(str) == m) & ((d[SYS].astype(str) == str(s)) if SYS else True)]
if r.empty:
continue
y = len(metrics) - 1 - i + 0.8 * ((j + 0.5) / len(systems) - 0.5)
r = r.iloc[0]
ax.errorbar(r[EST], y, xerr=[[r[EST] - r[LO]], [r[HI] - r[EST]]], fmt="o", color=PALETTE[j % len(PALETTE)], capsize=3, label=s if i == 0 else None)
ax.set_yticks(range(len(metrics)), metrics[::-1])
ax.set_xlabel("score (0–100)")
if SYS:
ax.legend(title=SYS, fontsize=8)
ax.set_title("Corpus scores with bootstrap intervals")
plt.show()Needs pandas, numpy, matplotlib · reads text-metric-ci-demo.csv · app theme from the optional codesplash helper
# Corpus scores with intervals — Codesplash Chart Lab (recipe "text-metric-ci")
# controls: defaults
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
try:
import codesplash as cs # optional: the app's chart theme
except ImportError:
cs = None
if cs:
cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else px.colors.qualitative.Plotly
df = pd.read_csv("text-metric-ci-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["metric"] = pd.Categorical(df["metric"].astype("string"), categories=["BLEU", "chrF", "ROUGE-1", "ROUGE-2", "ROUGE-L"])
df["system"] = pd.Categorical(df["system"].astype("string"), categories=["baseline", "fine-tuned"])
_tokens = cs.palette(dark=False) if cs else {}
SEQ = _tokens.get("sequential", ["#eff6fd", "#1a469d"]) # sequential ramp (low → high)
DIV = _tokens.get("diverging", ["#c13e2e", "#f3f5f8", "#0859ac"]) # negative, midpoint, positive
REF = _tokens.get("reference", "#4e5661")
GREY = _tokens.get("dim", "#ced1d6")
def levels_of(s):
"""Declared level order (categoricals), else order of first appearance."""
if isinstance(s.dtype, pd.CategoricalDtype):
return [v for v in s.cat.categories if (s == v).any()]
return list(dict.fromkeys(s.dropna().astype(str)))
M = "metric"
EST = "score"
LO = "lower"
HI = "upper"
SYS = "system"
d = df.dropna(subset=[M, EST])
systems = levels_of(d[SYS]) if SYS else [None]
fig = go.Figure()
for j, s in enumerate(systems):
r = d[(d[SYS].astype(str) == str(s))] if SYS else d
fig.add_scatter(x=r[EST], y=r[M], mode="markers", name=str(s) if s is not None else "score",
error_x=dict(type="data", symmetric=False, array=r[HI] - r[EST], arrayminus=r[EST] - r[LO]),
marker=dict(size=9, color=PALETTE[j % len(PALETTE)]))
fig.update_yaxes(categoryorder="array", categoryarray=levels_of(d[M])[::-1])
fig.update_layout(scattermode="group", xaxis_title="score (0–100)", title="Corpus scores with bootstrap intervals")
fig.show()Needs pandas, numpy, plotly · reads text-metric-ci-demo.csv · app theme from the optional codesplash helper
# Corpus scores with intervals — Codesplash Chart Lab (recipe "text-metric-ci")
# controls: defaults
library(ggplot2)
has_cs <- isTRUE(requireNamespace("codesplashr", quietly = TRUE)) # optional: the app's chart theme
theme_cs <- if (has_cs) codesplashr::theme_codesplash(dark = FALSE) else theme_minimal()
cs_cat <- if (has_cs) codesplashr::cs_palette(dark = FALSE)$categorical else grDevices::palette.colors(8, "Okabe-Ito")
if (has_cs) update_geom_defaults("text", list(colour = codesplashr::cs_palette(dark = FALSE)$foreground))
df <- read.csv("text-metric-ci-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
df[["metric"]] <- factor(df[["metric"]], levels = c("BLEU", "chrF", "ROUGE-1", "ROUGE-2", "ROUGE-L"))
df[["system"]] <- factor(df[["system"]], levels = c("baseline", "fine-tuned"))
tok <- if (has_cs) codesplashr::cs_palette(dark = FALSE) else list()
seq_ramp <- if (is.null(tok$sequential)) c("#eff6fd", "#1a469d") else tok$sequential # low → high
div_ramp <- if (is.null(tok$diverging)) c("#c13e2e", "#f3f5f8", "#0859ac") else tok$diverging # −, 0, +
ref_col <- if (is.null(tok$reference)) "#4e5661" else tok$reference
grey_col <- if (is.null(tok$dim)) "#ced1d6" else tok$dim
levels_of <- function(v) if (is.factor(v)) levels(droplevels(v)) else unique(as.character(v[!is.na(v)]))
m_col <- "metric"
est_col <- "score"
lo_col <- "lower"
hi_col <- "upper"
sys_col <- "system"
d <- df[!is.na(df[[m_col]]) & !is.na(df[[est_col]]), ]
d$metric <- factor(as.character(d[[m_col]]), levels = rev(levels_of(d[[m_col]])))
ks <- if (is.null(sys_col)) "score" else levels_of(d[[sys_col]])
d$sys <- factor(if (is.null(sys_col)) "score" else as.character(d[[sys_col]]), levels = ks)
pd <- position_dodge(width = 0.6)
p <- ggplot(d, aes(x = .data[[est_col]], y = metric, colour = sys)) +
geom_errorbarh(aes(xmin = .data[[lo_col]], xmax = .data[[hi_col]]), height = 0.2, position = pd) +
geom_point(size = 2.6, position = pd) +
scale_colour_manual(values = setNames(rep_len(cs_cat, length(ks)), ks)) +
labs(x = "score (0–100)", y = NULL, colour = sys_col, title = "Corpus scores with bootstrap intervals") + theme_cs
print(p)Needs ggplot2 · reads text-metric-ci-demo.csv · app theme from the optional codesplashr helper
- Intervals are the engine's paired bootstrap percentiles; the emitted code draws them as given.