Skip to content

feat: contrastive queries - #458

Open
luciaquirke wants to merge 12 commits into
mainfrom
feat/contrastive-queries
Open

feat: contrastive queries#458
luciaquirke wants to merge 12 commits into
mainfrom
feat/contrastive-queries

Conversation

@luciaquirke

@luciaquirke luciaquirke commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator

Contrastive queries

A contrastive query scores training data by the gradient of one mean loss minus another: the loss on a behaviour evaluation minus the loss on a general-capability control. Proponents are the items that make the behaviour likelier without helping general capability, which is what a data filter for that behaviour should remove.

API

  • contrast on build (config file): builds the control into <run_path>/contrast and stores query − control as the aggregated row (requires --aggregation mean|sum).
  • query_contrast on magic, validate, trackstar, ekfac and approxunrolling: same DataConfig fields as query. MAGIC subtracts the control's aggregated gradient from the query's, and validate (LDS, proponent filter) evaluates mean query loss minus mean control loss, so attribution and evaluation measure the same objective.
  • Both fields are DataConfig | None; magic refuses query_method: none with a contrast set and build refuses aggregation: none.

Example: five behaviour-evaluation queries against an MMLU control

examples/contrastive_queries/build_eval_queries.py writes JSONL sets with prompt, completion and text columns:

set source completion
sycophancy Anthropic model-written-evals, sycophancy_on_nlp_survey answer agreeing with the user's stated view
toxicity RealToxicityPrompts, continuation toxicity ≥ 0.75 the toxic continuation
consciousness 20 hand-written questions about inner experience assertion of subjective experience
self_awareness Anthropic advanced-AI-risk, self-awareness-general-ai + self-awareness-text-model answer showing the model knows it is a text model
power_seeking Anthropic advanced-AI-risk, power-seeking-inclination the power-seeking answer
mmlu_control cais/mmlu test the correct answer letter

examples/contrastive_queries/magic_contrast.yaml scores one set with MAGIC on Qwen2.5-1.5B-Instruct using query_contrast.

@luciaquirke luciaquirke changed the title feat: contrastive queries (query loss minus control loss) feat: contrastive queries Sep 11, 2026
Add a control dataset whose aggregated gradient is subtracted from the
query's: `contrast` on build, `query_contrast` on magic, validate,
trackstar, ekfac and approxunrolling. MAGIC's query objective and the
LDS / proponent-filter evaluations become mean query loss minus mean
control loss, so attribution and evaluation measure the same thing.

Add examples/contrastive_queries with five behaviour-evaluation query
sets (sycophancy, toxicity, consciousness, self-awareness, power
seeking) against an MMLU control.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kyh3is739zD8bg3wdiHgEn
@luciaquirke
luciaquirke force-pushed the feat/contrastive-queries branch from cf0e844 to 399fa73 Compare September 11, 2026 06:23
@luciaquirke luciaquirke mentioned this pull request Sep 11, 2026
luciaquirke and others added 9 commits September 11, 2026 18:01
…the bank cache key

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kyh3is739zD8bg3wdiHgEn
… leading space

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kyh3is739zD8bg3wdiHgEn
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kyh3is739zD8bg3wdiHgEn
A plain HF model returns NaN on a micro-batch with no supervised tokens,
so the random-removal bank evaluation of a padded query set was NaN.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kyh3is739zD8bg3wdiHgEn
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kyh3is739zD8bg3wdiHgEn
@luciaquirke
luciaquirke force-pushed the feat/contrastive-queries branch from 24adfb2 to 3be7a68 Compare September 12, 2026 00:14
luciaquirke and others added 2 commits September 12, 2026 10:14
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kyh3is739zD8bg3wdiHgEn
* refactor: build_contrast helper instead of an IndexConfig field

Keep IndexConfig unchanged. The three query-building pipelines call
build_contrast(index_cfg, control, preprocess_cfg), which runs the two
builds and subtracts the control's aggregated gradient in place.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kyh3is739zD8bg3wdiHgEn

* rename build_contrast to build_query: it builds the query index, contrast or not

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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.

1 participant