A custom lm-evaluation-harness task can run clean and still score the wrong answers

A custom lm-evaluation-harness task can run clean and still score the wrong answers

●1 ●22 ●66
calendar_today ago • schedule4 min read

A team ports an internal question set into lm-evaluation-harness as a custom task. The run finishes clean, with no errors and a plausible accuracy number in the table.

Two weeks later, someone opens the logged samples. Every row was scored against the wrong option. The labels in the dataset started at 1. The choice list starts at 0.

The reason is structural. A custom task is a YAML file, and the harness trusts it. Most porting mistakes do not raise an error. They change what gets scored.

So read the rendered prompt and the scored target before you trust the first number.

A custom task is one YAML file in your own directory

A task tells the harness four things: its name, where the examples live, how each example becomes a prompt, and how the answer gets judged. task, dataset_path, doc_to_text and doc_to_target cover those, plus a split such as test_split.

Keep the file in your own directory and point the harness at it with --include_path. There is no need to fork the repo or touch the installed lm_eval/tasks folder.

For data on disk, set dataset_path: json (or csv) and pass the file through dataset_kwargs with data_files. A bare file path is not the same thing.

Labels can point at the wrong choice without a warning

For a multiple-choice task, doc_to_target should resolve to an index into the doc_to_choice list. That list starts at 0.

If your labels start at 1, most rows do not fail. Label 1 scores against the second option, label 2 against the third, and so on. Only the top label falls out of range, logs a warning and scores 0.

String labels have a similar trap. A label like "B" only counts if it exactly matches one of the choice strings. If it does not, the row logs a warning, scores 0 and the run carries on.

Check the label base and the label type on ten rows before anything else.

Read the rendered prompt before a full run

Run with --limit 10 first. Add --log_samples to save every input, output and target, and pair it with --output_path, because the harness refuses --log_samples without one.

--write_out prints the rendered prompt as well. In v0.4.13 it logs only the first document, so treat it as a smoke test, not a review.

The CLI also has lm-eval validate --tasks <name> --include_path <dir>. In v0.4.13 it only confirms that the task name resolves from your include path. That catches a missing or misnamed task. The sample log is still the real check.

Watch the whitespace between prompt and choice. target_delimiter defaults to a single space, so doc_to_text should not end in a space and the choices should not start with one. A stray space shifts every likelihood the task computes.

Generative answers need a stop and an extractor

Leave out generation_kwargs on a generate_until task and the harness falls back to greedy decoding with a 256-token cap and a stop at the first blank line. A long reasoning answer can get cut before it reaches the answer.

exact_match is plain string equality, with optional switches such as ignore_case, ignore_punctuation and regexes_to_ignore. It does not strip whitespace on its own. A reply of 42 does not equal 42.

That is what filter_list is for. A regex filter pulls the answer out of the reply and strips it. If nothing matches, the prediction becomes the literal string [invalid] and scores as wrong, not as an error.

Two details in that pipeline get mixed up often. group_select on the regex filter picks which match to keep. The default is the first match. The gsm8k flexible-extract pipeline uses -1 for the last.

take_first is a different step. It keeps the first generated response when a task samples more than one. It does not pick between regex matches.

A greedy pattern such as The answer is (.*) also keeps a trailing period, so 42. fails against 42. Either tighten the pattern or add regexes_to_ignore.

Pick the multiple-choice metric before you see results

Multiple-choice tasks score each option by log-likelihood. With no metric_list, the harness reports two numbers. acc picks the option with the highest raw log-likelihood. acc_norm divides by the option's character length first.

The two can pick different answers on the same run when option lengths vary. Decide which one is the headline before the run, and write the reason next to the config.

Keep few-shot examples out of the scored split

With num_fewshot above zero and no fewshot_split, exemplars come from the training split. If there is no training split, they come from validation. If that is missing too, they come from the test split, with only a warning.

On a dataset that ships only a test split, the exemplars come from the same split you score. With fewshot_split unset, the sampler excludes nothing, so any test row, including the one being scored, can land in the prompt. Set fewshot_split explicitly.

Then add metadata with a version and bump it whenever the prompt, the filter or the metric changes. The version prints in the results table, so two scores from different configs are easy to tell apart.

Pitfalls that keep showing up

  • Forking the repo for one task. --include_path loads it from your own directory.
  • Trusting the first clean run. No error does not mean the labels lined up.
  • Skipping the sample log. --log_samples with --output_path on ten rows shows the prompt, the target and the parsed answer.
  • Scoring raw generations. Without a filter, exact_match compares the whole reply, spaces included.
  • Leaving the few-shot source implicit. A test-only dataset will feed test rows into the prompt.

The field reference, the prompt formats and the loading steps are in this guide to adding a custom task to lm-evaluation-harness.

Check ten rendered rows before you run ten thousand. Then the number in the table describes the task you meant to write.

Want more #python & #machine-learning deep dives?

Join 6,016+ developers sharing real benchmarks, code breakdowns, and projects. Free forever.

More Posts

A Textile Mill's Dyehouse Ramp Curve: Get One Step Wrong and the Sheet Belongs to the Master

aiomniu - Oct 18

Attention-Free Score: How Domain Reports Show Which Pages Need Work

ApogeeWatcherverified - Sep 1

Everyone says DeepSeek is cheaper, but I got tired of guessing the exact math. So I built a calculat

abarth23 - Apr 27

How AI Is Changing Web Development, and What Developers Still Need to Understand

Daniel Decker - Nov 10

Dashboard Operasional Armada Rental Mobil dengan Python + FastAPI

Masbadar - Mar 12
chevron_left
3.7k Points • 89 Badges
San Francisco Bay Area • futureagi.com
20Posts
106Comments
12Connections
Hey, Nikhil here. Engineer at heart, building the data layer of AGI. I’m big on collaboration, stayi... Show more

Related Jobs

View all jobs →

Commenters (This Week)

2 comments
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!