# This run trains the evidence-bundle recipe from v3.18.0 for 8000 steps as a production candidate.
# It also switches to locality-surface-lexicon-v4. That lexicon adds neighborhood surfaces.
# Over-trust in the evidence channels can grow with training time, so grade every 2k checkpoint.
#
# Launch the run:
#   node packages/mailwoman/tools/training/launch/launch.run.ts start --config v3.19.0-bundle-8k.yaml --fresh
data:
  # This corpus adds synth-nz, synth-es-pedania and synth-fr-lieudit to v0.14.0-gb.
  corpus_dir: /data/corpus/versioned/v0.15.0-deploc/corpus-v0.15.0-deploc
  tokenizer_dir: /data/models/tokenizer/v0.9.0-multisplice
  max_length: 128
  # The loader drops every row whose country is missing from this map.
  country_weights:
    US: 1.0
    FR: 1.0
    DE: 1.0
    ES: 1.0
    IT: 1.0
    NL: 1.0
    PT: 1.0
    BE: 1.0
    PL: 1.0
    AT: 1.0
    CH: 1.0
    CZ: 1.0
    DK: 1.0
    "NO": 1.0
    SE: 1.0
    FI: 1.0
    IE: 1.0
    GB: 1.0
    SK: 1.0
    SI: 1.0
    HR: 1.0
    HU: 1.0
    AU: 1.0
    CA: 1.0
    MX: 1.0
    NZ: 1.0
  source_weights:
    # The overture-latam source keeps the CA and MX Overture rows apart from the EU overture source.
    overture-latam: 6.0
    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-intersection: 1.0
    synth-german: 6.0
    synth-fr-order: 3.0
    synth-fr-admin-split: 6.0
    synth-unit: 1.5
    synth-po-box-cedex: 1.5
    synth-affix: 2.0
    synth-country: 2.0
    overture: 3.0
    gnaf: 6.0
    synth-anchor-absorption: 6.0
    synth-fr-bare-street: 12.0
    synth-si-bare-village: 12.0
    # The weight is zero because the on-disk part predates --exclude-surfaces and overlaps the eval board.
    synth-no-street-led: 0.0
    synth-cz-pcfirst-preposition: 12.0
    synth-nl-postcode: 6.0
    synth-fragment: 6.0
    synth-fr-fragment: 12.0
    synth-no-fragment: 12.0
    synth-gb: 10.0
    # The synth-nz key also covers the older NZ PO box recipe output.
    synth-nz: 4.0
    synth-es-pedania: 5.0
    synth-fr-lieudit: 3.0
  train_rows_per_epoch: 1000000
  val_rows: 4096
  coarse_filter: true
  augment_directional_prob: 0.3
  augment_region_prob: 0.3
  augment_glue_prob: 0.25
  # The punctuation drop teaches the model to split street and locality without relying on the comma.
  # A probability p yields a comma-free share of p/(1+p), so 0.6 gives about 0.38.
  augment_punct_drop_prob: 0.6
  anchor_lookup_path: /data/anchor/pilot-anchor-lookup.json
  gazetteer_lexicon_path: /data/gazetteer/anchor-lexicon-v1.json
  country_lexicon_path: /data/gazetteer/country-surface-lexicon-v1.json
  # The street-type lexicon uses the same JSON schema as the gazetteer lexicon.
  street_type_lexicon_path: /data/gazetteer/street-type-lexicon-v1.json
  locality_surface_lexicon_path: /data/gazetteer/locality-surface-lexicon-v4.json
  gazetteer_choreography: true
  affix_relabel_lexicon_path: /data/gazetteer/affix-relabel-lexicon-v1.json
  anchor_paint_mode: shaped
  anchor_value_mode: posterior_latlon

model:
  hidden_size: 384
  use_span_boundary_head: true
  span_boundary_loss_weight: 0.5
  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
  use_gazetteer_anchor: true
  gazetteer_feature_dim: 5
  # Each *_feature_dim below must equal the feature_dim of the matching lexicon.
  use_country_anchor: true
  country_feature_dim: 2
  use_street_type_anchor: true
  street_type_feature_dim: 1
  use_locality_surface_anchor: true
  locality_surface_feature_dim: 2
  # The model scales the country_ambiguous feature by this factor before the country projection.
  # The scale is baked into the exported ONNX graph.
  # A full-strength guard of 1.0 suppressed country names that are also other place names, such as Georgia.
  country_ambiguous_scale: 0.5
  class_weights:
    O: 0.5
    B-country: 3.5
    I-country: 3.5
    B-region: 1.5
    I-region: 1.5
    B-locality: 2.0
    I-locality: 2.0
    B-dependent_locality: 1.0
    I-dependent_locality: 1.0
    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

# With --fresh and a fresh output_dir, init_from loads only the weights and the optimizer starts fresh.
train:
  output_dir: /data/output-v3190-bundle-8k-s42/checkpoints
  seed: 42
  # The v385 checkpoint lives under the output-v384 directory name.
  init_from: /data/output-v384-latam-probe-s42/checkpoints/step-008000
  batch_size: 128
  eval_batch_size: 128
  grad_accum_steps: 1
  learning_rate: 1.0e-5
  weight_decay: 0.01
  warmup_steps: 500
  grad_clip_norm: 1.0
  max_steps: 8000
  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
  gazetteer_curriculum: false
  # The evidence curriculum zeroes the bundle channels on a ramp so the model learns not to over-trust them.
  evidence_curriculum: true
  # The classifier and both fresh bundle channels train at this higher rate.
  classifier_learning_rate: 1.0e-3
  trackio_project: mailwoman
  trackio_run_name: v3.19.0-bundle-8k-s42

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