# v0.8.0 — MLM self-supervised PRE-training (phase 1 of pretrain -> fine-tune).
#
# The first run of the new objective="mlm" path (feat/mlm-pretraining). Pre-trains the
# encoder on corpus text (BIO labels ignored) via masked-language-modeling, producing a
# checkpoint a later supervised run fine-tunes from (cfg.train.init_from). Goal: give the
# encoder a self-supervised prior before it ever sees a label, to attack the two diagnosed
# pathologies that two corpus-recipe cycles couldn't move — 81%-of-wrong-at->=0.9
# overconfidence + format/delimiter over-reliance (the small-encoder literature attributes
# both to training from scratch on labels only). See docs MLM spec.
#
# geometry is identical TO v0_7_2-intersection-bare.yaml on purpose: the pretrained encoder
# must be state_dict-key-identical to the supervised model so `init_from` loads every key.
# use_phrase_priors / use_crf stay true so their params exist in the checkpoint (untrained
# here. the fine-tune trains them). forward_mlm skips the phrase-projection + CRF heads.
#
# This is a validation run: 20k steps to check the loss value descends sanely + the Trackio
# dashboard works end to end, then a fine-tune from the resulting checkpoint decides whether
# pretraining helps (pre-registered revert: fine-tune harness <22% and resolver Acc@1 gain
# <1.5pp vs the from-scratch baseline -> drop pretraining).
#
# Launch (Trackio debut):
#   node packages/mailwoman/tools/training/launch/launch.run.ts start \
#     --config v0_8_0-mlm-pretrain.yaml --fresh

  # v0.3.0 (674 train parquet files), not v0.4.0 (12 synth-overlay parquet files): MLM wants broad,
  # representative text coverage, and v0.4.0 is a thin synth overlay meant to be used with
  # source-weighting (which we drop here). No row in launch/corpora.py stages v0.3.0 any more —
  # put it on the volume with `sync_assets --corpus-versions v0.3.0` before running this.
data:
  corpus_dir: /data/corpus/versioned/v0.3.0/corpus-v0.3.0
  tokenizer_dir: /data/models/tokenizer/v0.6.0-a0
  max_length: 128
  country_weights:
    US: 1.0
    FR: 1.0
  # No source_weights: MLM wants broad text exposure (it's learning token/morphology
  # structure rather than a label distribution), so let every source through uniformly. The
  # supervised fine-tune re-applies its own sampling recipe.
  train_rows_per_epoch: 1000000
  val_rows: 2048
  coarse_filter: true
  # No augmentation for pretraining — learn the raw token distribution as-is.
  augment_directional_prob: 0.0
  augment_region_prob: 0.0

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
  # Heads exist in the checkpoint (key-match for init_from) but are untrained by the MLM
  # objective — the supervised fine-tune trains them.
  use_crf: true
  label_smoothing: 0.0
  crf_normalization: per_sequence
  crf_loss_weight: 0.0
  use_phrase_priors: true
  phrase_feature_dim: 10

train:
  objective: mlm
  mlm_mask_prob: 0.15
  output_dir: /data/output-v080-mlm-pretrain/checkpoints
  seed: 42
  batch_size: 128
  eval_batch_size: 128
  grad_accum_steps: 1
  learning_rate: 1.0e-4
  weight_decay: 0.01
  warmup_steps: 1000
  grad_clip_norm: 1.0
  max_steps: 20000
  eval_every_steps: 1000
  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.8.0-mlm-pretrain

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