Evaluate a Model#

Evaluation uses the same config and runner API as training. Keep the dataset entry and architecture settings used for training, set stage to eval, and point model_config.pretrained_model_dir at the saved model.

Evaluation configuration#

The following experiment can live beside the data.taxi entry shown in Training a Model:

NHP_eval:
  base_config:
    stage: eval
    backend: torch
    dataset_id: taxi
    runner_id: std_tpp
    model_id: NHP
    base_dir: ./checkpoints/
  trainer_config:
    seed: 2019
    gpu: -1
    batch_size: 256
    max_epoch: 1
    shuffle: false
    metrics: [acc, rmse]
  model_config:
    hidden_size: 64
    time_emb_size: 16
    num_layers: 2
    num_heads: 2
    use_mc_samples: true
    loss_integral_num_sample_per_step: 20
    dropout_rate: 0.0
    use_ln: false
    pretrained_model_dir: ./checkpoints/<run-id>/models/saved_model
    thinning:
      num_sample: 1
      num_exp: 500
      over_sample_rate: 5
      num_samples_boundary: 5
      dtime_max: 5
      patience_counter: 5
      num_step_gen: 1

The architecture and time-rescaling settings must match the checkpoint. Checkpoint statistics and the saved time scale allow evaluation without the training split; keep the checkpoint sidecar files together. See Data loading for cases that still require training statistics. stage: eval uses valid_dir by default; to evaluate the held-out test split from local files, point valid_dir at the test file. For a Hub dataset, explicitly pass a test loader as shown below. Thinning is used for next-event time prediction by intensity-based models. The supported thinning keys are num_sample, num_exp, over_sample_rate, num_samples_boundary, dtime_max, patience_counter, and num_step_gen.

Run evaluation#

Add NHP_eval to examples/configs/experiment_config.yaml and run the following from the repository root:

Use Config, not a separate evaluation config class:

from easy_tpp.config_factory import Config
from easy_tpp.runner import Runner

config = Config.build_from_yaml_file(
    "examples/configs/experiment_config.yaml",
    experiment_id="NHP_eval",
)
runner = Runner.build_from_config(config)
runner.run()

Metrics are printed and written to the log below base_dir. When dataset time rescaling is active, predicted and target times are restored to their original units before RMSE is calculated.

To evaluate the Hub test split, replace runner.run() with:

from easy_tpp.preprocess import TPPDataLoader

data_loader = TPPDataLoader(
    config.data_config,
    backend="torch",
    batch_size=config.trainer_config.batch_size,
    shuffle=False,
)
runner.evaluate(valid_loader=data_loader.test_loader())