L02

W06 · 5 hours · complete online handout

Query-set engineering

Research question

Does the query bank represent a declared universe rather than a desired result?
Download offline package
01

Contract

What this lab must demonstrate

  • Define a query population and strata.
  • Detect duplicates and leakage.
  • Version exclusions and provenance.

Prerequisites

  • W06 population statement.
  • Basic CSV and Python use; a no-code review route is included.
Equivalent low-compute route

Use token-based similarity and the supplied adjudication report; no embedding model is necessary.

02

Milestones

Four reviewable checkpoints

The windows are planning budgets, not hidden grading criteria. Pause at every gate; do not compress a failed check into the final submission.

  1. 01

    Freeze the sampling frame

    Work
    Declare target population, unit, locale, time boundary, exclusions, strata, allocation, and representativeness limits before authoring queries.
    Checkpoint evidence
    Versioned sampling frame and allocation table.
    Advance only when
    No query writing starts until the inference population and exclusions are explicit.
  2. 02

    Author and label the bank

    Work
    Create at least 60 queries across four substantive intent strata; preserve stable IDs, provenance, synthetic status, locale, and split.
    Checkpoint evidence
    Query bank with held-out rows, negative controls, and counterfactuals.
    Advance only when
    The desired answer is not embedded in target prompts.
  3. 03

    Audit duplication and leakage

    Work
    Run exact and near-duplicate checks, review lexical candidates, and adjudicate leakage and sensitive-data flags rather than accepting automation blindly.
    Checkpoint evidence
    Duplicate-pair review and exclusion log with reasons.
    Advance only when
    Every exclusion remains visible; difficult queries are not removed merely because they hurt a result.
  4. 04

    Freeze the instrument

    Work
    Reconcile stratum counts, codebook, exclusions, and limitations; freeze v1 and its checksum.
    Checkpoint evidence
    Five-file release with coverage report and checksum.
    Advance only when
    Every query has stratum and provenance, and all language extensions remain separately analyzable.
03

Validation

Checks, pass gate, and assessment

Every query has stratum and provenance.

Unique IDs survive copy edits.

Exact duplicates are zero.

Near duplicates are adjudicated.

Desired-answer leakage and personal data are absent or explicitly excluded.

Pass gate

Every query has stratum/provenance; duplicates and desired-answer leakage are resolved; second-language extensions remain separately analyzable.

L02 Rubric — 100 points

Rendered from the canonical package rubric. Source SHA-256: 2ee8c2cd377c381a7eba0aea38d268417ce75a8298e0267eadf29eef0f591c0a.

L02 canonical 100-point assessment rubric
CriterionPointsFull-credit evidence
Sampling frame20Population, unit, strata, allocation, exclusions, locale, time, and limitations were frozen before analysis.
Coverage and controls20At least 60 English queries span four substantive intents and include justified counterfactuals and negative controls.
Provenance and split15Every row has provenance; held-out items were reserved before tuning; added locales are separate.
Duplicate audit15Exact and near duplicates are reproducibly surfaced and human-adjudicated with retained decisions.
Leakage and exclusion audit20Desired-answer wording and sensitive data are addressed; every exclusion remains visible.
Boundary statement10Representativeness, lexical-method, and synthetic-data limits are explicit.

Hard fail pending remediation: fabricated naturalistic provenance, post-outcome replacement of prompts, undisclosed desired-answer prompts, exposed personal queries, or reuse of held-out queries during tuning.

Pass threshold: 70/100 and no hard-fail condition.

04

Handout

Complete browser-readable lab handout

Generated from the same controlled README shipped in the offline package. Source SHA-256: bc0e764999a764d4522dde8f055ff372b2bbea4b303bc8fb6d22c491c31fbb73.

On this page 10 sections

Linked course week: W06
Expected effort for the full assignment: 5 hours
Core path: offline, deterministic, Python standard library only

Research question

Does the query bank represent a declared universe rather than a desired result?

Learning objectives

You will learn to:

  1. define a population before writing prompts;
  2. stratify queries by intent, entity class, locale, provenance, and development/held-out role;
  3. add counterfactual and negative-control prompts without contaminating the target set;
  4. detect exact and near duplicates with a transparent lexical rule;
  5. detect desired-answer leakage and preserve exclusions; and
  6. state the representativeness limits of synthetic or convenience-sampled queries.

Input contract

  • data/sampling_frame.json declares the population, unit, exclusions, strata, allocation, locale, time boundary, and sampling limitations.
  • data/query_bank.csv follows ../shared/schemas/query.schema.json. query_id is stable and unique. Boolean values are lowercase strings because CSV has no native Boolean type.
  • Every row names intent_stratum, entity_class, locale, provenance, is_synthetic, and split.

The checked-in bank is a small demonstration fixture, not the required 60-query assignment. It intentionally contains one near duplicate and one desired-answer prompt so the exclusion workflow is observable.

Run

python3 scripts/engineer_queries.py \
  --frame data/sampling_frame.json \
  --input data/query_bank.csv \
  --output /tmp/geo-l02 \
  --similarity-threshold 0.80

Near-duplicate similarity is token-set Jaccard similarity. It is intentionally inspectable, English-oriented, and not a semantic-equivalence oracle.

Output contract

Table from the controlled L02 lab handout
ArtifactContract
accepted_query_bank.csvvalid, non-leaking records retained in input order
query_report.jsoncounts, coverage, exclusions, warnings, and method boundary
duplicate_pairs.csvexact/near-duplicate candidates with score and decision
exclusion_log.csvevery excluded ID with a machine-readable reason
coverage.csvaccepted counts by intent stratum, locale, and split
run_manifest.jsonhashed inputs and threshold

Contract violations such as duplicate identifiers or unknown vocabularies fail the run. Quality findings such as a near duplicate, leakage, insufficient sample size, or an empty declared stratum are reported without turning a scientifically honest negative result into a software error.

Full assignment procedure

  1. Freeze the sampling frame and target allocation before authoring the bank.
  2. Create at least 60 English queries across at least four substantive intent strata.
  3. Reserve a held-out split before tuning any retrieval, response, or intervention method.
  4. Add labeled counterfactuals and negative controls.
  5. Record naturalistic, transformed, and synthetic provenance separately.
  6. Run the tool; adjudicate near duplicates rather than blindly accepting the rule.
  7. Preserve every exclusion and its reason. Never replace a difficult prompt merely because it hurts a metric.
  8. Analyze any additional language/locale as a separate sampling frame before pooling.

Low-compute and no-network route

The lexical audit processes thousands of short queries on one CPU and uses no model, embedding, external corpus, API, or personal search history. If semantic review is unavailable, perform a blinded human adjudication of the candidate pairs in duplicate_pairs.csv.

Negative results and interpretation

  • Poor stratum coverage means the bank is not yet a valid measurement instrument.
  • High duplicate rates may reveal a narrow authoring process, not merely a cleaning problem.
  • Desired-answer leakage can invalidate an apparent brand or method advantage.
  • Lexical similarity can miss paraphrases and can flag legitimate controlled variants. Report both error directions.
  • A balanced synthetic bank is not automatically representative of real demand.

Ethics and stop conditions

Do not use private search logs, personal queries, protected attributes, or deanonymizable free text without approved governance and de-identification. Never ask annotators to infer sensitive intent. Brand comparisons must not embed fabricated accusations or endorsements. Stop if provenance cannot be established.

Acceptance

python3 scripts/engineer_queries.py --frame data/sampling_frame.json --input data/query_bank.csv --output /tmp/geo-l02 --similarity-threshold 0.80
python3 -c 'import json; r=json.load(open("/tmp/geo-l02/query_report.json")); assert r["status"] == "PASS" and r["excluded_count"] >= 2'

See RUBRIC.md.

05

Execute

Use one source of executable truth

Ethics and stop condition

Do not use personal queries without approved de-identification. Label all synthetic queries and avoid harmful or sensitive prompts.

Optional extension

Compare a transparent embedding-assisted duplicate route and document changed decisions.

The page is the complete reading and planning surface. The versioned package README and scripts remain authoritative for exact local commands, filenames, fixtures, and validation behavior.