Skip to content

Allow selecting few-shot examples by explicit ids - #1489

Open
amalsaidov wants to merge 1 commit into
huggingface:mainfrom
amalsaidov:feat/fewshot-id-selection
Open

amalsaidov wants to merge 1 commit into
huggingface:mainfrom
amalsaidov:feat/fewshot-id-selection

Conversation

@amalsaidov

Copy link
Copy Markdown

Fixes #634

What

Adds two optional fields to LightevalTaskConfig:

  • few_shots_id_column (str | None): dataset column used to identify few-shot samples.
  • few_shots_id_list (list[str] | None): explicit list of identifiers restricting which samples from the few-shot split may be used as few-shot examples.

When few_shots_id_list is set, the few-shot pool is restricted to the samples whose few_shots_id_column value is in the list. This mirrors the id_sampler behavior requested in the issue (and available in LM Evaluation Harness), letting you pin exactly which rows are used as in-context examples.

Why

Previously few-shot examples could only be chosen via a split + a selection strategy (balanced/random/sequential). There was no way to specify exact samples, which makes reproducing a fixed few-shot prompt across runs impossible. See #634.

Behavior / safety

  • Only the few-shot pool is filtered; evaluation documents are unaffected.
  • Matching is done on the raw dataset column value (compared as strings), so int/str ids both work.
  • ValueError is raised at config time if few_shots_id_list is given without few_shots_id_column.
  • KeyError is raised if the configured column is absent from the dataset.
  • A warning is logged for any requested id that is not found in the split.
  • Fully backward compatible: both fields default to None.

How tested

  • Added unit tests in tests/unit/tasks/test_lighteval_task.py:
    • test_few_shots_id_list_selection — only the listed ids end up in the few-shot pool, eval docs unchanged.
    • test_few_shots_id_list_without_column_raises — config validation.
    • test_few_shots_id_list_missing_column_raises — missing column raises.
  • python -m pytest tests/unit/tasks/test_lighteval_task.py → 6 passed.
  • ruff check and ruff format --check → clean.

🤖 Generated with Claude Code

Add `few_shots_id_column` and `few_shots_id_list` to LightevalTaskConfig
so a task can pin which samples from the few-shot split are used as
few-shot examples, matching them against a dataset column (similar to
the id_sampler in LM Evaluation Harness).

When `few_shots_id_list` is set, the few-shot pool is restricted to the
samples whose `few_shots_id_column` value is in the list; evaluation docs
are unaffected. Validation errors are raised when the column is missing
or when the list is given without a column, and a warning is logged for
requested ids that are not found.

Fixes huggingface#634

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FT] Build in a way to specify specific IDs/Lines in Dataset to use as few-shot examples in the same split

1 participant