Training Script
The training script connects your target function to a specific task type and wires both into the foundation model. Each task type has its own class, constructor parameters, default metrics, and output format.
In This Section
| Guide | Description |
|---|---|
| This page | Understand script structure, training execution, and recommended path forward |
| Binary Classifier Script | Yes/no outcomes — churn, fraud, conversion |
| Multi-Class Classifier Script | One category from a set — favorite brand, plan tier |
| Multilabel Classifier Script | Multiple labels at once — cross-sell, category affinity |
| Regression Script | Continuous numeric values — LTV, spend, usage volume |
| Recommendation Script | Ranked item lists — next product, content suggestions |
Each ML task-specific guide covers the task class, constructor parameters, and a complete training script for one task type.
Script Structure
Every scenario training script follows the same structure. The only parts that change between task types are the imports, the target function, and the task class:
# --- Imports ----------------------------------------------------------------
from monad.ui.module import load_from_foundation_model, <TaskClass> # (1)
from monad.ui.config import TrainingParams
from monad.ui.target_function import Events, Attributes, has_incomplete_training_window
...
# --- Names & Paths ----------------------------------------------------------
foundation_model_path = ... # path to your trained foundation model
scenario_model_path = ... # where to save the scenario model
# --- Target Function --------------------------------------------------------
def target_fn(history: Events, future: Events, entity: Attributes, ctx: dict):
... # your labeling logic
return label # return type depends on the task
# --- Training ---------------------------------------------------------------
task = <TaskClass>(...) # (2)
training_params = TrainingParams(
checkpoint_dir=scenario_model_path,
learning_rate=..., # see TrainingParams reference
epochs=...,
)
trainer = load_from_foundation_model(
checkpoint_path=foundation_model_path,
downstream_task=task, # determines output shape, loss, and default metrics
target_fn=target_fn,
)
trainer.fit(training_params=training_params)
- Replace
<TaskClass>with the class for your task — e.g.BinaryClassificationTask. - Some task classes require constructor arguments (e.g.
class_namesfor multiclass). See the individual guides.
Each guide below shows the concrete version for one task type.
Running Training
Once your script is ready, run it with Python. Use limit_train_batches and limit_val_batches for a quick smoke test before committing to a full run:
Training splits the data into train/validation sets, trains for the configured number of epochs, and saves the best checkpoint to checkpoint_dir. When it finishes, move on to Evaluation to test the trained model.
Recommended Path
- Pick a task from the guides above based on your business question
- Write a target function — see Tasks & Targets for the API and Target Examples for patterns
- Configure and run — wire task + target into
load_from_foundation_modeland run the script - Evaluate — test the trained model and review metrics with Evaluation
- Iterate — try different metrics (Custom Metrics) or tune loading parameters (Loading Overrides)
For the full load_from_foundation_model parameter reference, see Scenario Model API. For TrainingParams options, see Training Parameters.