# Order-robustness retrain — v0.9.2 (#239/#240 follow-up). One variable vs v0.9.1-pilot-anchor-on:
# the German recipe now renders the same tuples in both orders (native + international) instead of
# native-only. Everything else is held — anchor on, self-conditioning on, v0.7.2-proven recipe, seed 42.
#
# why. The anchor pilot's "German collapse" turned out to be substantially an eval-rendering artifact:
# our OpenAddresses de-sample renders German US-style (`27 Straußstraße, Berlin, 12623`), but the
# v0.9.1 model trained German order only (`Straußstraße 27, 12623 Berlin`). On the same 3,000 points,
# the same anchor-on checkpoint scores 45.5% locality in US order and 83.8% in native order — beating
# v0/Pelias (78.7%). Native-only training taught German order so well it traded away the US/feed order.
# Teaching both layouts of the same components removes the trade. Full analysis:
#   docs/articles/evals/2026-06-06-anchor-pilot.md (the order-artifact correction).
#
# single variable: identical to v0.9.1-pilot-anchor-on except corpus v0.4.2-de-bothorder. That corpus's
# `synth-german` recipe output is built with `--intl-fraction 0.4` (≈40% international order, ≈60% native). Any
# delta is attributable to the order mix rather than the recipe.
#
# PRE-registered check (stop at 20k, the early check. extend to 100k only if it holds):
#   - native-order DE locality >= 80% — hold the 83.8% we already have. do not regress native.
#   - international-order DE locality >> 45.5% (target >= 65%) — the gap this run exists to close.
#   - US/FR within ~1pp of v0.7.2 (no regression on the incumbents).
#   - cross_pollution < 1% per locale (live regression check).
# Measure both orders explicitly via the two committed eval assets:
#   data/eval/external/openaddresses-de-sample.jsonl                (US/international order, as shipped)
#   data/eval/external/openaddresses-de-sample-native-order.jsonl   (native German order. render-de-native-order.ts)
#
# follow-up (not this run): once both-orders holds, A/B dropping the anchor (use_postcode_anchor:false)
# to learn whether training on both orders closes it without the anchor — the anchor may have been rescuing a symptom
# (US-order fragility) that this run fixes at the root. Keep the anchor on here for a single-variable read.
#
# corpus: v0.4.2-de-bothorder — v0.4.0 (US/FR) base overlaid with a both-order `synth-german` source
# (200K train + 4K val, real OpenAddresses Berlin/Saxony tuples). Reproduce + deploy to the Modal volume:
#   built by the German recipe (packages/corpus/lib/de/recipes/locale.ts) with --output /tmp/german-train.jsonl --count 200000 --seed 42 --intl-fraction 0.4
#   built by the German recipe (packages/corpus/lib/de/recipes/locale.ts) with --output /tmp/german-val.jsonl   --count 4000   --seed 99 --intl-fraction 0.4
#   mailwoman dev jsonl-to-parquet --input /tmp/german-train.jsonl --out /tmp/part-german-train.parquet
#   mailwoman dev jsonl-to-parquet --input /tmp/german-val.jsonl   --out /tmp/part-german-val.parquet
#   # Assemble the overlay manifest (v0.4.0 parquet files + the 2 German parquet files) — mirror v0.4.1-de via
#   # scripts/assemble-de-overlay-manifest.py (point it at v0.4.2-de-bothorder), then:
#   # Not `modal volume put`: a mounted container cannot see what it writes, so a run staged that
#   # way trains on whatever was already there and reports success. Route it through R2 instead.
#   mailwoman corpus upload --corpus-version v0.4.2-de-bothorder
#   node packages/mailwoman/tools/training/launch/launch.run.ts sync --corpus v0.4.2-de-bothorder
#
# Launch:
#   node packages/mailwoman/tools/training/launch/launch.run.ts start \
#     --config v0.9.2-de-bothorder.yaml --fresh

data:
  corpus_dir: /data/corpus/versioned/v0.4.2-de-bothorder/corpus-v0.4.2-de-bothorder
  tokenizer_dir: /data/models/tokenizer/v0.6.0-a0
  max_length: 128
  country_weights:
    US: 1.0
    FR: 1.0
    DE: 1.0
  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
    deepseek-kryptonite: 3.0
    synth-po-box: 1.5
    synth-intersection: 0.2
    # German at ~18% of the mix — same weight as v0.9.1. the only change is the `synth-german` rows now contain both
    # orders. The key tunable if a check lags: raise for more DE, lower if US/FR slip the 1pp regression check.
    synth-german: 6.0
  train_rows_per_epoch: 1000000
  val_rows: 4096
  coarse_filter: true
  augment_directional_prob: 0.3
  augment_region_prob: 0.3
  anchor_lookup_path: /data/anchor/pilot-anchor-lookup.json

model:
  hidden_size: 384
  num_hidden_layers: 6
  num_attention_heads: 6
  intermediate_size: 1536
  max_position_embeddings: 128
  type_vocab_size: 1
  hidden_dropout_prob: 0.1
  attention_probs_dropout_prob: 0.1
  use_crf: true
  crf_loss_weight: 0.0
  crf_normalization: per_sequence
  label_smoothing: 0.1
  use_locale_conditioning: true
  locale_loss_weight: 0.3
  use_postcode_anchor: true
  class_weights:
    O: 0.5
    B-country: 2.0
    I-country: 2.0
    B-region: 1.5
    I-region: 1.5
    B-locality: 2.0
    I-locality: 2.0
    B-dependent_locality: 0.3
    I-dependent_locality: 0.3
    B-postcode: 1.5
    I-postcode: 1.5
    B-subregion: 0.3
    I-subregion: 0.3
    B-cedex: 1.0
    I-cedex: 1.0
    B-venue: 1.5
    I-venue: 1.5
    B-street: 2.0
    I-street: 2.0
    B-house_number: 1.5
    I-house_number: 1.5
    B-street_prefix: 1.5
    I-street_prefix: 1.5
    B-street_suffix: 1.5
    I-street_suffix: 1.5
    B-unit: 1.5
    I-unit: 1.5
    B-po_box: 1.5
    I-po_box: 1.5
    B-intersection_a: 1.0
    I-intersection_a: 1.0
    B-intersection_b: 1.0
    I-intersection_b: 1.0
  use_phrase_priors: true
  phrase_feature_dim: 10

train:
  output_dir: /data/output-v092-de-bothorder-s42/checkpoints
  seed: 42
  batch_size: 128
  eval_batch_size: 128
  grad_accum_steps: 1
  learning_rate: 1.5e-4
  weight_decay: 0.01
  warmup_steps: 1000
  grad_clip_norm: 1.0
  max_steps: 20000
  eval_every_steps: 2000
  save_every_steps: 2000
  log_every_steps: 50
  precision: bf16
  num_workers: 0
  csv_log_path: "{output_dir}/../train_log.csv"
  lr_schedule: constant
  trackio_project: mailwoman
  trackio_run_name: v0.9.2-de-bothorder-s42

eval:
  golden_dir: /data/eval/golden/v0.1.2
  val_jsonl: ""
