Skip to content

Add a CIDEr scorer for captioning tasks to the image-understanding evaluator - #793

Open
amazloumi wants to merge 2 commits into
mainfrom
feat/image-eval-cider
Open

amazloumi wants to merge 2 commits into
mainfrom
feat/image-eval-cider

Conversation

@amazloumi

@amazloumi amazloumi commented Dec 6, 2026 •

Copy link
Copy Markdown
Member

Summary

  • cider scorer (evaluation/scorers.py): CIDEr-D with n-grams of one to four words, sigma 6 and the factor 10, written from its definition (cider_d): n-gram counts weighted by inverse document frequency over the references of the split, a cosine for each n with the prediction's counts clipped to the reference's, a Gaussian penalty on the difference in length, averaged over the references and the four n. No new dependency.
  • Tokenization: the prediction and the references are split on whitespace as written, as the recipe scores captions, so case and punctuation count (yak. is not yak). The standard COCO caption evaluation lowercases and drops punctuation with the PTB tokenizer first, so these numbers differ from its; the docstring and the README say so.
  • CIDEr-D's weights come from the whole split, so Scorer gains an optional corpus, which rates a split's scored rows together. The evaluator applies it on rank 0 once the ranks' records are merged (score_corpus, before summarize): each caption row's record holds its own CIDEr-D under the split's weights, and the task's metric is the mean of the rows', as pycocoevalcap's per-image scores average to its corpus score. The metric does not depend on the number of ranks or the batch size, and a row's reference is the one evaluate_batch scores against (reference(row) for a reader that has one, otherwise the turn's answers). As a row is decoded, cider checks its inputs as the other text scorers do and scores it alone (0, as in a split of one row), which score_corpus then replaces. No other scorer has a corpus, so their records and metrics are unchanged.
  • configs/eval_tasks.toml: coco-captions (Karpathy val, 5,000 images) and flickr30k (val, 1,014 images) with placeholder paths, both read by the coco_captions reader, which asks each image the task's prompt and keeps every non-blank caption of the image as a reference, scored by cider and capped at the recipe's 100 tokens. The prompt is "Provide a short caption for the image.", the one the training mixtures caption with. They come before VQAv2, so the file's header stays true.
  • README: cider in the scorer list, the two tasks in the sample file's paragraph, and the corpus step in the evaluator section and in the note on adding a scorer.

Testing

All at 2bf0d2c8, on main d4e9b7ce; Python 3.12.11 and 3.14.10, torch 2.14.1+cu130, transformers 5.5.0. No file under kempnerforge/, tests/ or docs/ changes, so the core tiers do not apply.

  • Expected values from pycocoevalcap 1.2 (PyPI; numpy 2.5.5, Python 3.12.11): Cider() at its defaults (n=4, sigma=6.0), given the raw strings with no tokenizer, on two splits of fixed captions, stored with the captions in tests/evaluation/cider_pycocoevalcap_scores.json; the tests do not import pycocoevalcap. The first split's 11 rows cover case and punctuation, a repeated n-gram (clipping), n-grams in no reference, a one-word and a long prediction (the length penalty), one, two, three and five references, an empty prediction, runs of whitespace, a one-word reference and a prediction equal to a reference; the second split is one of those rows alone. cider_d matches every row and both splits to a relative 1e-12 (the largest difference measured is 4.4e-16, on 3.12 and 3.14).
  • Evaluator path: a caption task through evaluate_checkpoint records each row's CIDEr-D under the split's weights and reports their mean; the shards of 2 and 3 ranks, merged and scored on rank 0, give the same records and metrics as one rank, and two gloo ranks write the same files as one process, byte for byte.
  • ruff check . and ruff format --check .: clean
  • pyright examples/image_understanding/evaluation: 0 errors
  • examples/image_understanding/tests (--timeout=60): 1,613 passed, 0 failed, 0 skipped, on 3.12 and on 3.14
  • examples/vlm/tests without the eval integration tier (--timeout=60): 407 passed on each; examples/assembled_run/tests: 9 passed on each
  • Added lines and branches in evaluation/: all covered (branch coverage, 3.12 and 3.14)
  • Doc pages unit test (test_documented_commands_write_each_override_with_an_equals_sign): passed

Closes #647

CIDEr-D weighs n-grams by document frequency over the whole split, so a
scorer may now rate a split's rows together (Scorer.corpus), which the
evaluator does on rank 0 once the ranks' records are merged. Each caption
row records its own CIDEr-D under the split's weights, and the task's
metric is their mean. Texts are split on whitespace as written.
@amazloumi amazloumi added enhancement New feature or request image_understanding labels Dec 6, 2026
The case and punctuation test had no capital letter, so lowercasing the
texts before the whitespace split left it green, and only the fixture row
caught that. A prediction "A yak" against the reference "a yak" now has to
score above 0 and below the exact match.
@amazloumi
amazloumi marked this pull request as ready for review December 6, 2026 09:31

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a CIDEr scorer for captioning tasks to the image-understanding evaluator

1 participant