kd.kontext.path_builder_from

kd.kontext.path_builder_from#

kauldron.kontext.path_builder_from(
prefix: str,
cls: type[kauldron.kontext.path_builder._T],
) kauldron.kontext.path_builder._T[source]

Create a path builder from a class.

Used to dynamically create the Keys inside the configs from typed-objects ( e.g. dataclasses). This adds type-checking and auto-complete (rather than using raw str).

Usage:

def get_config():
  batch = kontext.path_builder_from('batch', my_project.Batch)
  out = kontext.path_builder_from('preds', my_project.ModelOutput)

  cfg.model = my_project.MyModel(
      input=batch.image
  )
  cfg.train_losses = {
      'loss': kd.losses.L2(pred=out.logits, target=batch.label)
  }
Parameters:
  • prefix – Prefix name of the key (e.g. batch, preds)

  • cls – Class to validate.

Returns:

The path builder