# v0.5.0 classifier verdict-smoke — thread C-s recipe.
#
# Hand off: not for immediate use. This config is parked here as part of Thread C-s
# (the scaffold-now-train-later ship). It becomes invocable when:
#
#   - Thread A (tokenizer retrain) has landed under /data/models/tokenizer/v0.5.0/, and
#   - Thread B (corpus-v0.4.0 with phrase proposals + adversarial expansion) has landed
#     under /data/corpus/versioned/v0.4.0/corpus-v0.4.0/, and
#   - Thread F (verdict-smoke framework) is merged to main so the `--smoke-mode constant`
#     flag + `train.lr_schedule: constant` config field are wired through.
#
# When all three blockers clear, the recipe becomes:
#
#   node packages/mailwoman/tools/training/launch/launch.run.ts start --config v0_5_0-classifier-smoke.yaml --cpu
#
# Purpose mirrors v0_4_0-smoke.yaml: a ~2-minute integration check before the full
# 50K run on rented GPU. Catches:
#
#   - Phrase-prior feature plumbing: corpus loader emits the (B, S, 10) feature tensor
#     in the layout the model expects (see phrase_priors.py for the slot interface).
#   - Top-k inference returns calibrated paths when sanity-checked against the eval set.
#   - CRF + class_weights + per_token + phrase-prior projection all coexist without
#     NaN or dtype mismatch under bf16 on gfx1103.
#   - Constant-LR schedule (per VERDICT_SMOKES.md): sustained peak LR for the smoke
#     window so dual-loss divergence has a chance to surface visibly — v0.4.0's
#     cw-only false-positive (cosine decay masked the destabilization) doesn't
#     recur.
#
# Expected: ~2 minutes wall, ~50 steps, train_log.csv shows finite + decreasing loss.

data:
  # Thread B output. Path will exist once Thread B's corpus build completes.
  corpus_dir: /data/corpus/versioned/v0.4.0/corpus-v0.4.0
  # Thread A output. Path will exist once Thread A's tokenizer retrain completes.
  # 48K-64K vocab budget (vs v0.1.0's 32K) for non-Latin sub-piece coverage.
  tokenizer_dir: /data/models/tokenizer/v0.5.0
  max_length: 128
  country_weights:
    US: 1.0
    FR: 1.0
  # Reuse of v0.4.0's source rebalance (the only §-recipe change that shipped clean
  # in v0.4.0). Re-evaluate after the first v0.5.0 eval run — corpus-v0.4.0's adversarial
  # additions may shift the optimal mix.
  source_weights:
    wof-admin: 2.0
    wof-postalcode: 2.0
    ban: 3.0
    tiger: 4.0
    usgov-nppes: 2.0
    usgov-hrsa-fqhc: 2.0
    usgov-imls-pls: 2.0
    usgov-nad: 1.0
    state-ia-contractors: 2.0
    state-tx-notaries: 1.5
    state-ny-notaries: 2.0
  # Cap rows-per-epoch so the smoke doesn't burn time on a giant per-epoch scan during
  # resume — same shape as v0_4_0-smoke.yaml.
  train_rows_per_epoch: 10000
  val_rows: 256
  coarse_filter: true

model:
  # Hidden-size stays at v0.3.0/v0.4.0 baseline per Thread C-s scope. The plan doc mentions
  # a 256 → 384 or 512 bump as "likely paid for by rented GPU" for the full v0.5.0 run,
  # but the scaffold validates that the new architecture trains without divergence at the current
  # size first. Treat the bump as an orthogonal training-side concern, bumped in a
  # follow-up `v0_5_0-classifier-large.yaml` if the v0.5.0 baseline lands clean.
  hidden_size: 256
  num_hidden_layers: 6
  num_attention_heads: 4
  intermediate_size: 1024
  max_position_embeddings: 128
  type_vocab_size: 1
  hidden_dropout_prob: 0.1
  attention_probs_dropout_prob: 0.1
  use_crf: true
  label_smoothing: 0.0
  # v0.4.0 dual-loss lessons still apply.
  crf_normalization: per_token
  crf_loss_weight: 1.0
  # v0.4.0 class-weight recipe — coarse-biased CE. Re-validate after the v0.5.0 corpus
  # mix lands. the relative class frequencies will shift with the adversarial additions.
  class_weights:
    O: 1.0
    B-country: 2.0
    I-country: 2.0
    B-region: 2.0
    I-region: 2.0
    B-locality: 1.5
    I-locality: 1.5
    B-dependent_locality: 1.5
    I-dependent_locality: 1.5
    B-postcode: 1.5
    I-postcode: 1.5
    B-subregion: 1.5
    I-subregion: 1.5
    B-cedex: 2.0
    I-cedex: 2.0
    B-venue: 0.5
    I-venue: 0.5
    B-street: 0.5
    I-street: 0.5
    B-house_number: 0.5
    I-house_number: 0.5
  # v0.5.0 thread C: phrase-prior conditioning on. The headline architectural change for
  # this iteration — Stage 2.7's PhraseProposals flow into the classifier as per-token
  # features (see phrase_priors.py for the layout). Default is off for backward-compat;
  # turning it on here is the explicit v0.5.0 opt-in.
  use_phrase_priors: true
  # Per-token feature width = PHRASE_BIE_DIM (3) + PHRASE_KIND_DIM (7) = 10.
  # Surfaced as a config field so the corpus loader's emitted tensor width and the
  # model's projection layer width stay in lockstep through the model card.
  phrase_feature_dim: 10

train:
  output_dir: /data/models/checkpoints/v0_5_0-classifier-smoke
  seed: 42
  # gfx1103 envelope, matched to v0_4_0-smoke.
  batch_size: 8
  eval_batch_size: 16
  grad_accum_steps: 1
  learning_rate: 5.0e-4
  weight_decay: 0.01
  warmup_steps: 10
  grad_clip_norm: 1.0
  # Just enough steps to exercise loss + eval + a checkpoint save under the constant-LR
  # schedule. Per VERDICT_SMOKES.md mode A, the smoke window stays at sustained peak LR
  # — divergence surfaces immediately if the dual-loss + phrase-prior recipe is unstable.
  max_steps: 50
  eval_every_steps: 25
  save_every_steps: 25
  log_every_steps: 5
  precision: bf16
  num_workers: 0
  csv_log_path: "{output_dir}/train_log.csv"
  # Constant linear warmup → flat at learning_rate. no cosine decay. Per Thread F's
  # VERDICT_SMOKES.md mode A: sustained peak LR for the smoke window means dual-loss
  # divergence surfaces immediately rather than being masked by a decaying tail
  # (the v0.4.0 cw-only false-positive trap). Equivalent to passing
  # `--smoke-mode constant` on the CLI.
  lr_schedule: constant

eval:
  # Golden v0.1.2 stays the eval anchor for v0.5.0. The non-Latin adversarial subset +
  # kryptonite catalogue are new eval splits per the plan doc § Success metrics. their
  # fixtures land alongside Thread D (reconcile).
  golden_dir: ""
  val_jsonl: ""
