﻿# Lighteval Doc objects: choices, gold indices and sampling-method contracts

Read Lighteval's Doc and task configuration before adapting a dataset to generation, choice-logprob or perplexity evaluation.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/data-guide-lighteval-task-document-contract/
Language: en

## A prompt function creates an evaluation document

Lighteval's custom-task guide converts a dataset row into a Doc. The document carries query, choices and correct-choice indices, alongside optional instructions, images and metadata. This is a semantic adapter between source fields and the model-facing evaluation.

Inspect a rendered example before treating the conversion as correct. A function can return a valid object while putting a reference answer into the visible query or associating a class with the wrong candidate position.

## Choices and gold indices must remain aligned

The Doc definition permits a correct index or multiple indices. Candidate order therefore belongs to the target mapping. If choices are reordered, their gold mapping must be updated at the same time.

For generative tasks, the documented role of choices can differ from multiple-choice options. Do not infer the scoring contract from the field name alone. Keep the task's expected output and metric definition beside the document representation used for each example.

## Sampling methods request different evidence

The inspected source distinguishes generation, choice log probabilities and whole-prompt perplexity modes. These require different model responses and backend capabilities. A generated answer and the likelihood of a supplied choice are not interchangeable observations.

Check whether the selected backend supports the evidence required by the metric. Replacing an unavailable likelihood operation with free-form generation creates another adapter and should be reported as an experimental change, not a transparent technical substitution.

## Task configuration supplies the surrounding policy

LightevalTaskConfig includes dataset revision and filters, evaluation/few-shot splits, metrics and generation controls. It also exposes task versioning and document-count tracking. These fields explain why a short task name cannot reconstruct the complete experiment.

Keep generation size, stop sequences and few-shot selection with the task artifact. A stopping rule can cut off a valid answer, while demonstration selection can change the prompt. Distinguish configuration validity from the substantive correctness of the resulting model input.

## Preserve resolved documents for diagnosis

The Doc source includes fields for original query and task-specific metadata, while registry code resolves available and custom tasks. Record the actual implementation revision and adapter used rather than assuming an identically named registry entry never changes.

A proposed review compares source row, Doc, effective request and metric input on a bounded example set. This article runs no evaluation. It explains how to keep label leakage, candidate mismatch and backend substitution visible instead of attributing every changed Lighteval score to the model weights.

## Primary references

[Lighteval custom-task guide](https://github.com/huggingface/lighteval/blob/main/docs/source/adding-a-custom-task.mdx).

[Lighteval Doc source](https://raw.githubusercontent.com/huggingface/lighteval/main/src/lighteval/tasks/requests.py).

[Lighteval task configuration source](https://raw.githubusercontent.com/huggingface/lighteval/main/src/lighteval/tasks/lighteval_task.py).

[Lighteval registry source](https://raw.githubusercontent.com/huggingface/lighteval/main/src/lighteval/tasks/registry.py).

Related explanations: [Choice targets and likelihood](/journal/cross-entropy-logits-target-indices/); [Few-shot and evaluation separation](/journal/document-level-data-split-leakage/).
