Skip to content

Scores for generated text, images, audio and video

Perplexity, CLIPScore, rate–distortion curves and warping error each measure one thing under one protocol. Know the protocol, know what the score rewards that you don't want, and pair it with the checks it can't do.

Advanced ~15 min9 steps

What runs in CodeSplash

You will be able to

  • Compute perplexity and bits per token and say when two values are comparable
  • Read CLIPScore as content overlap, not correctness
  • Compare codecs by rate–distortion curves at real bitrates
  • Explain why a frozen video gets a perfect warping error

Read first

01

One score, one protocol

Read

Every score for generated output is defined by a protocol: a tokenizer, a feature network, a bitrate rule, a flow estimator. Change the protocol and the number changes, so scores from different protocols can't be compared. And every score rewards something you may not want: fluent text, generic captions, plausible but invented detail, frozen motion.

The other chapters' lessons cover image-generator scores, text-overlap metrics, judges and listening tests:

Reference · EVA021 · Needs a data type CodeSplash doesn't load yetFréchet Inception DistanceCompares Gaussian approximations to real and generated image-feature distributions. Reference · EVA038 · Runs in CodeSplashLLM-as-judge and pairwise human preference protocolsUses a rubric to judge open-ended outputs and aggregates paired preferences, ideally validated against independent human ratings.

This lesson covers four more, and what they have in common.

DExplorable · Scoring generators: FID, precision and recall

Can one number say how good generated samples are?

How will this generator's precision and recall come out?

How sure?

Generator

The real data is a ring of 8 clusters. Each generator gets something different wrong.

Feature extractor

FID and the k-NN scores compare features, not raw samples. Real FID uses a vision network; here, four simple maps.

200

How many real and how many generated samples are compared.

3

Each sample's ball reaches its k-th nearest neighbor in its own set.

Simulating…

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

02

Perplexity and bits per token

Read

On held-out text, with causal conditioning and NN scored tokens:

PPL=exp⁡(−1N∑tlog⁡p(xt∣x<t)),BPT=NLLlog⁡2.\mathrm{PPL} = \exp\left(-\frac{1}{N}\sum_t \log p(x_t \mid x_{<t})\right), \qquad \mathrm{BPT} = \frac{\mathrm{NLL}}{\log 2}.

In the reference's four-token example, perplexity is 2.364 and bits per tokenBits per tokenAverage bits to encode each held-out token: log base 2 of per-token perplexity. Comparable only under one tokenizer and one scoring rule. 1.241. Sum token losses over the corpus before averaging; don't average per-document perplexities. Declare the tokenizer, the context window and stride, and how padding, document boundaries and special tokens count.

Reference · EVA029 · Runs in CodeSplashPerplexity and bits per tokenMeasures held-out autoregressive prediction quality on a specified tokenization.
03

Per token is not per word

Explore
N-gram language model perplexityRecorded · Python and R agreeRecorded 2026-11-25 · 20 values compared
R

GPT-2 small: perplexity 76.7 per token on 15 rows (6.26 bits per token); mean Min-20% log-probability -8.33.

Perplexity per token
76.702
Bits per token
6.261
Perplexity per word
95.290
Mean Min-20% log-probability
−8.332

Plots

Min-20% log-probability per textHow is one numeric variable distributed?

Higher (closer to 0) means GPT-2 finds even the text's least likely tokens predictable, as with text it saw in training.

View data
Min-20% log-probability
−9.521
−9.969
−9.791
−7.793
−9.920
−5.870
−7.779
−6.199
−7.136
−9.309
−6.581
−8.574
−8.269
−9.115
−9.149

Assumptions

  • Scored on held-out rows — GPT-2 small was not fitted to these rows: it was trained on WebText (English web pages, up to 2019). Rows marked "test" in split are summarized; the others are shown as training rows. A text that was in WebText looks more predictable than new text; Min-K% helps spot it.
  • Same words and vocabulary — Perplexity here is per GPT-2 token, so compare it only with other GPT-2 perplexities. Word perplexity (per word, as the Words setting splits text) is closer to an n-gram model's, but not equal.
  • Rows are independent — The interval resamples whole rows; repeated or threaded rows make it too narrow.

Least predictable rows

RowTokensBits per tokenMin-20% log-probability
56107.858−9.115
20117.725−9.920
6097.463−9.149
4127.338−9.521
40116.847−9.309
8106.501−9.969
52106.351−8.269
12136.292−9.791
28126.175−7.779
44106.060−6.581

Most familiar rows (highest Min-K%)

RowTokensMin-20% log-probabilityBits per token
2415−5.8704.697
3212−6.1994.584
4410−6.5816.060
3612−7.1365.510
2812−7.7796.175
1611−7.7935.557
5210−8.2696.351
4810−8.5746.006
5610−9.1157.858
609−9.1497.463
  • 1 rows have no text or no training/test label (or no words) and are left out.
The exact R script · R R version 4.5.1 (2025-06-13)
# N-gram language model perplexity
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method evaluate.perplexity 1.1.1 · spec 7221e90eafd4cb1c
# Dataset: txt1_lm (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
library(codesplashr)

# %% Rows: text present (and a training/test label when that column is used), at least one word
TEXT <- "text"
SPLIT <- "split"
TOKENS <- "words"
LOWER <- TRUE
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/txt1_lm.parquet", col_select = c(TEXT, SPLIT)))
warnings <- list()
ok <- !is.na(df[[TEXT]])
if (!is.null(SPLIT)) ok <- ok & !is.na(df[[SPLIT]])
words_all <- vapply(seq_len(nrow(df)), function(i) if (ok[i]) length(cs_lm_tokenize(as.character(df[[TEXT]][i]), TOKENS, LOWER)) else 0L, integer(1))
rows <- which(ok & words_all > 0)
n_dropped <- nrow(df) - length(rows)
if (n_dropped) warnings <- c(warnings, sprintf("%d rows have no text%s (or no words) and are left out.", n_dropped, if (!is.null(SPLIT)) " or no training/test label" else ""))
if (!length(rows)) cs_error("CS_E_NO_ROWS")  # no row has any words

# %% Rows summarized: those marked with the test label; without a training/test column, every row (nothing is fitted)
SEED <- 42
if (!is.null(SPLIT)) {
  TEST_LEVEL <- "test"
  is_test <- as.character(df[[SPLIT]][rows]) == TEST_LEVEL
  if (all(is_test) || !any(is_test)) cs_error("CS_E_TOO_FEW_GROUPS", column = SPLIT, min = 2, k = 1)  # needs rows on both sides
} else {
  is_test <- rep(TRUE, length(rows))
}

# %% GPT-2 small (cs_gpt2_* ↔ codesplash.text.gpt2): log-probability of every token after <|endoftext|>
MODEL <- cs_gpt2_load()  # stops with CS_WEIGHTS_MISSING when GPT-2 isn't downloaded
K <- 20
lp_row <- numeric(length(rows)); n_row <- numeric(length(rows)); mk_row <- numeric(length(rows)); cut_row <- logical(length(rows))
for (j in seq_along(rows)) {
  s <- cs_gpt2_token_logprobs(as.character(df[[TEXT]][rows[j]]), MODEL)
  lp_row[j] <- sum(s$lp)
  n_row[j] <- s$n
  mk_row[j] <- cs_gpt2_min_k(s$lp, K)
  cut_row[j] <- s$cut
}
words <- as.numeric(words_all[rows])
te <- is_test; tr <- !is_test
ppl <- cs_lm_perplexity(lp_row[te], n_row[te])
train_ppl <- if (any(tr)) cs_lm_perplexity(lp_row[tr], n_row[tr]) else NULL
n_cut <- sum(cut_row)

# %% Bootstrap over the summarized rows (shared Wichmann-Hill stream)
B <- 200
CONF <- 0.95
lo <- NULL; hi <- NULL
if (B > 0) {
  reps <- cs_lm_bootstrap(lp_row[te], n_row[te], B, SEED + 1)
  ci <- cs_tm_percentile_ci(reps, CONF)
  lo <- ci[1]; hi <- ci[2]
}

# %% Artifacts: one row per input row
out <- cs_ml_out_dir("target/academy-parity/run-8142/evaluate.perplexity/gpt2_split/out-r")
nanoparquet::write_parquet(data.frame(row = as.integer(rows - 1L), split = ifelse(is_test, "test", "train"), tokens = as.integer(n_row),
                                      words = as.integer(words), logprob = lp_row, perplexity = exp(-lp_row / n_row), min_k = mk_row),
                           file.path(out, "scores.parquet"))

# %% Result
values <- list(
  n_train = sum(tr), n_test = sum(te), n_dropped = n_dropped,
  train_tokens = sum(n_row[tr]), test_tokens = sum(n_row[te]),
  vocab_size = NULL, oov_rate = NULL, order = NULL, smoothing = NULL,  # n-gram settings: none for GPT-2
  perplexity = ppl, perplexity_ci_low = lo, perplexity_ci_high = hi, cross_entropy = log2(ppl),
  train_perplexity = train_ppl,
  lm_name = "GPT-2 small", lm_word_perplexity = exp(-sum(lp_row[te]) / sum(words[te])),
  lm_min_k = mean(mk_row[te]), lm_train_min_k = if (any(tr)) mean(mk_row[tr]) else NULL,
  lm_min_k_percent = K, lm_truncated = n_cut
)
for (k in c("vocab_size", "oov_rate", "order", "smoothing", "perplexity_ci_low", "perplexity_ci_high", "train_perplexity", "lm_train_min_k"))
  if (is.null(values[[k]])) values[k] <- list(NULL)
scored <- if (!is.null(SPLIT)) sprintf("Rows marked \"%s\" in %s are summarized; the others are shown as training rows.", TEST_LEVEL, SPLIT) else "Every row is summarized."
assumptions <- list(
  list(key = "held_out", label = "Scored on held-out rows", status = "info",
       detail = sprintf("GPT-2 small was not fitted to these rows: it was trained on WebText (English web pages, up to 2019). %s A text that was in WebText looks more predictable than new text; Min-K%% helps spot it.", scored)),
  list(key = "same_vocabulary", label = "Same words and vocabulary", status = "info",
       detail = "Perplexity here is per GPT-2 token, so compare it only with other GPT-2 perplexities. Word perplexity (per word, as the Words setting splits text) is closer to an n-gram model's, but not equal."),
  list(key = "rows_independent", label = "Rows are independent", status = "info",
       detail = "The interval resamples whole rows; repeated or threaded rows make it too narrow.")
)
if (n_cut) warnings <- c(warnings, sprintf("%d texts are longer than 1,023 GPT-2 tokens; only their first 1,023 tokens are scored.", n_cut))
bits <- (-lp_row / n_row) / log(2)
idx <- which(te)
top <- head(idx[order(-bits[idx], idx, method = "radix")], 10)
surprise_rows <- lapply(top, function(j) list(row = as.integer(rows[j]), tokens = as.integer(n_row[j]), bits = bits[j], min_k = mk_row[j]))
fam <- head(idx[order(-mk_row[idx], idx, method = "radix")], 10)
familiar_rows <- lapply(fam, function(j) list(row = as.integer(rows[j]), tokens = as.integer(n_row[j]), min_k = mk_row[j], bits = bits[j]))
mk_label <- sprintf("Min-%g%% log-probability", K)
cols <- list(list(key = "row", label = "Row", type = "number"), list(key = "tokens", label = "Tokens", type = "number"),
             list(key = "bits", label = "Bits per token", type = "number"), list(key = "min_k", label = mk_label, type = "number"))
fam_cols <- cols[c(1, 2, 4, 3)]
charts <- list(cs_chart("min_k", "histogram", sprintf("Min-%g%% log-probability per text", K), list(x = cs_col(mk_label, mk_row[te])),
                        note = "Higher (closer to 0) means GPT-2 finds even the text's least likely tokens predictable, as with text it saw in training."))
cs_publish(list(
  title = "N-gram language model perplexity",
  engine = cs_engine_info("codesplashr", "nanoparquet"),
  n = length(rows),
  summary = sprintf("GPT-2 small: perplexity %.1f per token on %d rows (%.2f bits per token); mean Min-%g%% log-probability %.2f.", ppl, sum(te), log2(ppl), K, values$lm_min_k),
  statistics = list(
    list(key = "perplexity", label = "Perplexity per token", value = ppl),
    list(key = "cross_entropy", label = "Bits per token", value = values$cross_entropy),
    list(key = "lm_word_perplexity", label = "Perplexity per word", value = values$lm_word_perplexity),
    list(key = "lm_min_k", label = sprintf("Mean Min-%g%% log-probability", K), value = values$lm_min_k)
  ),
  tables = list(
    list(key = "surprising", title = "Least predictable rows", columns = cols, rows = surprise_rows),
    list(key = "familiar", title = "Most familiar rows (highest Min-K%)", columns = fam_cols, rows = familiar_rows)
  ),
  assumptions = assumptions,
  charts = charts,
  values = values,
  warnings = warnings,
  artifacts = list(list(key = "scores", path = file.path(out, "scores.parquet"), format = "parquet"))
))
Python

GPT-2 small: perplexity 76.7 per token on 15 rows (6.26 bits per token); mean Min-20% log-probability -8.33.

Perplexity per token
76.702
Bits per token
6.261
Perplexity per word
95.290
Mean Min-20% log-probability
−8.332

To keep this page light, the plots are shown once, under the R tab.

Assumptions

  • Scored on held-out rows — GPT-2 small was not fitted to these rows: it was trained on WebText (English web pages, up to 2019). Rows marked "test" in split are summarized; the others are shown as training rows. A text that was in WebText looks more predictable than new text; Min-K% helps spot it.
  • Same words and vocabulary — Perplexity here is per GPT-2 token, so compare it only with other GPT-2 perplexities. Word perplexity (per word, as the Words setting splits text) is closer to an n-gram model's, but not equal.
  • Rows are independent — The interval resamples whole rows; repeated or threaded rows make it too narrow.

Least predictable rows

RowTokensBits per tokenMin-20% log-probability
56107.858−9.115
20117.725−9.920
6097.463−9.149
4127.338−9.521
40116.847−9.309
8106.501−9.969
52106.351−8.269
12136.292−9.791
28126.175−7.779
44106.060−6.581

Most familiar rows (highest Min-K%)

RowTokensMin-20% log-probabilityBits per token
2415−5.8704.697
3212−6.1994.584
4410−6.5816.060
3612−7.1365.510
2812−7.7796.175
1611−7.7935.557
5210−8.2696.351
4810−8.5746.006
5610−9.1157.858
609−9.1497.463
  • 1 rows have no text or no training/test label (or no words) and are left out.
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# N-gram language model perplexity
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method evaluate.perplexity 1.1.1 · spec 7221e90eafd4cb1c
# Dataset: txt1_lm (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
import math
import os

import numpy as np
import pandas as pd

import codesplash as cs
from codesplash import ml as csml
from codesplash.text import gpt2
from codesplash.text import metrics as tm
from codesplash.text import ngram_lm as lm

# %% Rows: text present (and a training/test label when that column is used), at least one word
TEXT = "text"
SPLIT = "split"
TOKENS = "words"
LOWER = True
df = pd.read_parquet("tests/parity/fixtures/txt1_lm.parquet", columns=[TEXT] + ([SPLIT] if SPLIT else []))
warnings = []
ok = df[TEXT].notna().to_numpy()
if SPLIT:
    ok = ok & df[SPLIT].notna().to_numpy()
words_all = [len(lm.tokenize(t, TOKENS, LOWER)) if o else 0 for t, o in zip(df[TEXT], ok)]
rows = np.array([i for i in range(len(df)) if ok[i] and words_all[i] > 0], dtype=int)
n_dropped = len(df) - len(rows)
if n_dropped:
    warnings.append(f"{n_dropped} rows have no text{' or no training/test label' if SPLIT else ''} (or no words) and are left out.")
if not len(rows):
    cs.cs_error("CS_E_NO_ROWS")  # no row has any words

# %% Rows summarized: those marked with the test label; without a training/test column, every row (nothing is fitted)
SEED = 42
if SPLIT:
    TEST_LEVEL = "test"
    is_test = np.array([str(v) == TEST_LEVEL for v in df[SPLIT].iloc[rows]])
    if is_test.all() or not is_test.any():
        cs.cs_error("CS_E_TOO_FEW_GROUPS", column=SPLIT, min=2, k=1)  # needs rows on both sides
else:
    is_test = np.ones(len(rows), dtype=bool)

# %% GPT-2 small (codesplash.text.gpt2 ↔ codesplashr cs_gpt2_*): log-probability of every token after <|endoftext|>
MODEL = gpt2.Model()  # stops with CS_WEIGHTS_MISSING when GPT-2 isn't downloaded
K = 20
lp_row, n_row, mk_row, cut_row = [], [], [], []
for i in rows:
    t_lp, t_n, t_cut = gpt2.token_logprobs(str(df[TEXT].iloc[i]), MODEL)
    lp_row.append(float(np.sum(t_lp)))
    n_row.append(t_n)
    mk_row.append(gpt2.min_k(t_lp, K))
    cut_row.append(t_cut)
lp_row, n_row, mk_row = np.array(lp_row), np.array(n_row, dtype=float), np.array(mk_row, dtype=float)
words = np.array([words_all[i] for i in rows], dtype=float)
te, tr = is_test, ~is_test
ppl = lm.perplexity(lp_row[te], n_row[te])
train_ppl = lm.perplexity(lp_row[tr], n_row[tr]) if tr.any() else None
n_cut = int(sum(cut_row))

# %% Bootstrap over the summarized rows (shared Wichmann–Hill stream)
B = 200
CONF = 0.95
lo = hi = None
if B > 0:
    reps = lm.bootstrap_ppl(lp_row[te], n_row[te], B, SEED + 1)
    lo, hi = tm.percentile_ci(reps, CONF)

# %% Artifacts: one row per input row
out = csml.out_dir("target/academy-parity/run-8142/evaluate.perplexity/gpt2_split/out-python")
pd.DataFrame({
    "row": rows.astype(int), "split": np.where(is_test, "test", "train"), "tokens": n_row.astype(int), "words": words.astype(int),
    "logprob": lp_row, "perplexity": np.exp(-lp_row / n_row), "min_k": mk_row,
}).to_parquet(os.path.join(out, "scores.parquet"), index=False)

# %% Result
values = {
    "n_train": int(tr.sum()), "n_test": int(te.sum()), "n_dropped": n_dropped,
    "train_tokens": int(n_row[tr].sum()), "test_tokens": int(n_row[te].sum()),
    "vocab_size": None, "oov_rate": None, "order": None, "smoothing": None,  # n-gram settings: none for GPT-2
    "perplexity": ppl, "perplexity_ci_low": lo, "perplexity_ci_high": hi, "cross_entropy": math.log2(ppl),
    "train_perplexity": train_ppl,
    "lm_name": "GPT-2 small", "lm_word_perplexity": math.exp(-float(np.sum(lp_row[te])) / float(np.sum(words[te]))),
    "lm_min_k": float(np.mean(mk_row[te])), "lm_train_min_k": float(np.mean(mk_row[tr])) if tr.any() else None,
    "lm_min_k_percent": K, "lm_truncated": n_cut,
}
scored = (f'Rows marked "{TEST_LEVEL}" in {SPLIT} are summarized; the others are shown as training rows.' if SPLIT else "Every row is summarized.")
assumptions = [
    {"key": "held_out", "label": "Scored on held-out rows", "status": "info",
     "detail": f"GPT-2 small was not fitted to these rows: it was trained on WebText (English web pages, up to 2019). {scored} A text that was in WebText looks more predictable than new text; Min-K% helps spot it."},
    {"key": "same_vocabulary", "label": "Same words and vocabulary", "status": "info",
     "detail": "Perplexity here is per GPT-2 token, so compare it only with other GPT-2 perplexities. Word perplexity (per word, as the Words setting splits text) is closer to an n-gram model's, but not equal."},
    {"key": "rows_independent", "label": "Rows are independent", "status": "info",
     "detail": "The interval resamples whole rows; repeated or threaded rows make it too narrow."},
]
if n_cut:
    warnings.append(f"{n_cut} texts are longer than 1,023 GPT-2 tokens; only their first 1,023 tokens are scored.")
bits = (-lp_row / n_row) / math.log(2)
idx = [int(j) for j in np.flatnonzero(te)]
top = sorted(idx, key=lambda j: (-bits[j], j))[:10]
surprise_rows = [{"row": int(rows[j]) + 1, "tokens": int(n_row[j]), "bits": float(bits[j]), "min_k": float(mk_row[j])} for j in top]
fam = sorted(idx, key=lambda j: (-mk_row[j], j))[:10]
familiar_rows = [{"row": int(rows[j]) + 1, "tokens": int(n_row[j]), "min_k": float(mk_row[j]), "bits": float(bits[j])} for j in fam]
cols = [{"key": "row", "label": "Row", "type": "number"}, {"key": "tokens", "label": "Tokens", "type": "number"},
        {"key": "bits", "label": "Bits per token", "type": "number"}, {"key": "min_k", "label": f"Min-{K:g}% log-probability", "type": "number"}]
fam_cols = [cols[0], cols[1], cols[3], cols[2]]
charts = [cs.chart("min_k", "histogram", f"Min-{K:g}% log-probability per text", {"x": cs.col(f"Min-{K:g}% log-probability", mk_row[te])},
                   note="Higher (closer to 0) means GPT-2 finds even the text's least likely tokens predictable, as with text it saw in training.")]
cs.publish({
    "title": "N-gram language model perplexity",
    "engine": cs.engine_info("numpy", "pandas"),
    "n": len(rows),
    "summary": f"GPT-2 small: perplexity {ppl:.1f} per token on {int(te.sum())} rows ({math.log2(ppl):.2f} bits per token); mean Min-{K:g}% log-probability {values['lm_min_k']:.2f}.",
    "statistics": [
        {"key": "perplexity", "label": "Perplexity per token", "value": ppl},
        {"key": "cross_entropy", "label": "Bits per token", "value": values["cross_entropy"]},
        {"key": "lm_word_perplexity", "label": "Perplexity per word", "value": values["lm_word_perplexity"]},
        {"key": "lm_min_k", "label": f"Mean Min-{K:g}% log-probability", "value": values["lm_min_k"]},
    ],
    "tables": [
        {"key": "surprising", "title": "Least predictable rows", "columns": cols, "rows": surprise_rows},
        {"key": "familiar", "title": "Most familiar rows (highest Min-K%)", "columns": fam_cols, "rows": familiar_rows},
    ],
    "assumptions": assumptions,
    "charts": charts,
    "values": values,
    "warnings": warnings,
    "artifacts": [{"key": "scores", "path": os.path.join(out, "scores.parquet"), "format": "parquet"}],
})

GPT-2 small scores held-out sentences at 76.7 per GPT-2 token (6.26 bits per token), and 95.3 per word. A bigram model fitted on the same small corpus scores 13.2 per word, on a different held-out split.

None of these numbers can be ranked against the others: different units, splits and vocabularies (the bigram model only predicts words it has seen). Perplexity is comparable only under one tokenizer and one scoring rule, and low perplexity isn't truthfulness or instruction following.

04

CLIPScore

Read

CLIPScoreCLIPScore2.5 × max(cosine of an image and its caption, 0): how well a caption fits its image, without reference captions. encodes an image and a caption with a fixed CLIP model and scales their cosine similarity, floored at zero:

CLIPScore=c⋅max⁡(cos⁡(fI(I),fT(T)),0).\mathrm{CLIPScore} = c \cdot \max\left(\cos\left(f_I(I), f_T(T)\right), 0\right).

The original uses c=2.5c = 2.5; in the reference's two-number example the score is 2.255. It needs no reference caption, so valid wording that no reference used isn't punished.

It measures shared content under CLIP's view. It misses wrong counts, swapped spatial relations and negations, and a generator trained against the same encoder can learn shortcuts that raise it. Report the encoder and scaling, and add object, relation and counting checks.

Reference · EVA052 · Runs in CodeSplashCLIPScore for image–text alignmentUses a fixed image–text encoder to evaluate caption or prompt-image compatibility.
05

Rate–distortion

Read

A codec trades bits for quality. Its rate is encoded bits per second of audio or per pixel, and training often minimizes L=R+λDL = R + \lambda D. In the reference's example, a ten-second clip at 240,000 bits is 24 kilobits per second.

Compare codecs as rate–distortionRate–distortionHow a codec's quality changes with the bits it spends. Compare codecs as curves at real encoded bitrates, not at one point. curves across operating points, on the same content, at actual encoded bitrates with headers counted; a neural codec's token count isn't its bitrate. Add latency and memory. A decoder can produce detail that sounds or looks right but isn't in the source: better perceived quality can mean worse fidelity.

Reference · EVA059 · Runs as a notebookRate–distortion and rate–perception evaluationEvaluates the quality-cost tradeoff of learned image, audio, and video codecs.
06

Temporal consistency

Read

Generated or upscaled video can flicker. The warping errorWarping errorHow much a frame differs from the previous one moved along the estimated motion, in visible areas. A frozen video scores perfectly. moves each frame along the estimated motion and measures what is left in visible areas:

Ewarp=∑t,pMt,p ∥It+1(p)−W(It,Ft)(p)∥1∑t,pMt,p.E_{\text{warp}} = \frac{\sum_{t,p} M_{t,p}\,\lVert I_{t+1}(p) - W(I_t, F_t)(p)\rVert_1}{\sum_{t,p} M_{t,p}} .

In the reference's four-pixel example, with one occluded pixel masked out, it is 0.067. A video that never moves scores perfectly, so pair the error with motion magnitude and task adherence, and inspect fast motion and occlusions, where flow estimates fail.

Reference · EVA060 · Needs a data type CodeSplash doesn't load yetTemporal consistency and optical-flow warping diagnosticsMeasures short-term correspondence between adjacent frames after accounting for estimated motion.

DExplorable · Optical flow: Lucas–Kanade, warping and endpoint error

How can a computer tell how far each part of an image moved between two frames?

With this picture and motion, what will Lucas–Kanade find?

How sure?

Picture

Many small blobs (rich texture), diagonal stripes, or two broad smooth blobs.

1.5

How far the picture moves to the right between the frames.

−1.0

How far the picture moves down between the frames.

0.0

Turns the picture about its center, so the motion differs from place to place.

1.00

Scales the picture about its center: things move outward when it grows.

3

Lucas–Kanade assumes one motion inside a square window this many pixels around each point.

3

Each step warps the second frame by the current estimate and solves for the remaining motion.

0.01

Random noise added to the second frame.

Frame 1Frame 2 with motion (arrows drawn 2× long)0.210No warp0.017Warped by the estimate

Mean endpoint error 0.14 px. 4% of the windows see the pattern change in one direction only.

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

07

What runs here

Read
08

Check: generative and perceptual scores

Checkpoint

Check yourself

How should corpus perplexity be computed from many documents?

Show the answer

Answer: b

Per-document perplexities weight short documents too heavily and average an exponential. Pool the token losses first.

Check yourself

Model A reports perplexity 12 per token with a 50,000-token vocabulary; model B reports 30 per token with a 256-symbol byte vocabulary. Which predicts the text better?

Show the answer

Answer: c

A byte-level model makes many more, easier predictions. Normalize to a shared unit, such as bits per byte of the same text.

Check yourself

An image shows three dogs; the caption says "two dogs on grass". CLIPScore is high. Why?

Show the answer

Answer: b

High similarity doesn't guarantee correct counts, relations or negations. Add targeted checks.

Check yourself

A text-to-image model was fine-tuned to maximize CLIPScore with the same CLIP model used for evaluation. What is the risk?

Show the answer

Answer: b

Once a score is a training target, it stops being an independent measure of quality.

Check yourself

A neural audio codec reports its rate as the number of discrete tokens per second. Why can that mislead?

Show the answer

Answer: a

Compare full systems at real encoded bitrates, with headers and side information counted.

Check yourself

Codec A beats codec B at 6 kbps; B beats A at 24 kbps. Which is better?

Show the answer

Answer: c

Rate–distortion is a curve. The task contract's bitrate budget decides which part of it matters.

Check yourself

A video model's output has the lowest warping error of all candidates. What else should you check?

Show the answer

Answer: b

Low warping error can reward doing nothing. It is a diagnostic, not a quality score on its own.

Check yourself

Why does the warping error use a visibility mask?

Show the answer

Answer: b

Occluded and newly revealed regions can't be predicted by warping. Masking them keeps the score about real flicker.

09

Recap

Recap
  • Every generative score belongs to a protocol; compare only within one.
  • Perplexity: pool token losses; per token depends on the tokenizer; low perplexity isn't truth.
  • CLIPScore: shared content, not counts or relations; don't train and evaluate on one encoder.
  • Codecs: curves at real bitrates, with latency; plausible detail can be wrong detail.
  • Warping error: mask occlusions, and check that the video moves.

Concepts in this lesson