Training Steps API
Public API for training steps.
This module exposes step functions from lib.steps through the public API. CLI and web clients should use these functions, not call lib.steps directly.
Steps can be run via CLI: pstrain step ci_hmm [args]
- class pstrain.api.steps.CDHMMUntiedStep[source]
Bases:
StepCD HMM untied training step.
- add_arguments(parser)[source]
Add CD HMM untied specific arguments.
- Parameters:
parser (ArgumentParser)
- Return type:
None
- execute(ctx, **params)[source]
Execute CD HMM untied training by delegating to the pipeline runner.
Upstream tasks (flat, ci-1g, cd-untied-init) will run automatically if their outputs are stale. Use pstrain build cd-untied from the CLI.
- Parameters:
ctx (StepContext)
params (Any)
- Return type:
- get_inputs(ctx)[source]
Get input files for CD HMM untied training.
- Parameters:
ctx (StepContext)
- Return type:
- get_outputs(ctx)[source]
Get output files from CD HMM untied training.
- Parameters:
ctx (StepContext)
- Return type:
- class pstrain.api.steps.CIHMMStep[source]
Bases:
StepCI HMM training step.
- add_arguments(parser)[source]
Add CI HMM specific arguments.
- Parameters:
parser (ArgumentParser)
- Return type:
None
- execute(ctx, **params)[source]
Execute CI HMM training by delegating to the pipeline runner.
The pipeline does the right thing for stale dependencies: if flat or features are missing/older than their inputs, those tasks will run too. Use pstrain build ci-1g for the same effect from the CLI.
- Parameters:
ctx (StepContext)
params (Any)
- Return type:
- get_inputs(ctx)[source]
Get input files for CI HMM training.
- Parameters:
ctx (StepContext)
- Return type:
- get_outputs(ctx)[source]
Get output files from CI HMM training.
- Parameters:
ctx (StepContext)
- Return type:
- class pstrain.api.steps.FeaturesStep[source]
Bases:
StepFeature extraction step.
- add_arguments(parser)[source]
Add feature extraction specific arguments.
- Parameters:
parser (ArgumentParser)
- Return type:
None
- default_params: dict[str, Any] = {'agc': 'none', 'alpha': 0.97, 'cmn': 'batch', 'cmninit': '40,3,-1', 'dither': True, 'frate': 100, 'lifter': 22, 'lowerf': 130.0, 'ncep': 13, 'nfft': 512, 'nfilt': 25, 'remove_dc': True, 'remove_noise': True, 'samprate': 16000, 'seed': -1, 'transform': 'dct', 'upperf': 6800.0, 'varnorm': 'no', 'wlen': 0.025625}
- execute(ctx, **params)[source]
Execute feature extraction via the pipeline runner.
This is the single-step variant of pstrain build features. It builds a pipeline scoped to the current project/experiment/config and runs the “features” target.
- Parameters:
ctx (StepContext)
params (Any)
- Return type:
- get_inputs(ctx)[source]
Get input files for feature extraction.
- Parameters:
ctx (StepContext)
- Return type:
- get_outputs(ctx)[source]
Get output files from feature extraction.
- Parameters:
ctx (StepContext)
- Return type:
- class pstrain.api.steps.Step[source]
Bases:
ABCBase class for training steps.
Subclasses must implement: - name, description, script (class attributes) - get_inputs(), get_outputs() - return file paths - execute() - perform the step
- add_arguments(parser)[source]
Add step-specific arguments to parser.
Override in subclasses to add custom arguments.
- Parameters:
parser (ArgumentParser)
- Return type:
None
- abstractmethod execute(ctx, **params)[source]
Execute the step.
This is the single code path - ctx methods emit shell in dry-run, execute otherwise.
- Parameters:
ctx (StepContext) – Step context (with dry_run support)
**params (Any) – Step parameters
- Returns:
Exit code (0 for success)
- Return type:
- get_definition(ctx, **params)[source]
Get this step’s declarative definition.
- Parameters:
ctx (StepContext) – Step context
**params (Any) – Parameter overrides
- Returns:
StepDefinition with inputs, outputs, params, and script.
- Return type:
- abstractmethod get_inputs(ctx)[source]
Get input file paths.
- Parameters:
ctx (StepContext) – Step context with project/experiment info
- Returns:
List of input file paths (must exist before step runs)
- Return type:
- abstractmethod get_outputs(ctx)[source]
Get output file paths.
- Parameters:
ctx (StepContext) – Step context with project/experiment info
- Returns:
List of output file paths (created by this step)
- Return type:
- get_params(ctx, **overrides)[source]
Get step parameters.
- Parameters:
ctx (StepContext) – Step context
**overrides (Any) – Parameter overrides
- Returns:
Merged parameters
- Return type:
- get_params_from_args(args)[source]
Extract step parameters from parsed args.
Override in subclasses to handle custom arguments.
- class pstrain.api.steps.StepContext(project_dir, experiment='default', config='baseline', dry_run=False, _header_emitted=False)[source]
Bases:
objectContext for step execution.
Similar to CLI’s CommandContext but for library-level steps. Supports dry-run mode where actions emit shell instead of executing.
- __init__(project_dir, experiment='default', config='baseline', dry_run=False, _header_emitted=False)
Get shared directory.
- class pstrain.api.steps.StepDefinition(name, description, inputs, outputs, params, script)[source]
Bases:
objectDeclarative rule definition for a step (inputs/outputs/params/script).
- Parameters:
- __init__(name, description, inputs, outputs, params, script)
- pstrain.api.steps.run_build_lm(train_transcripts, output_path, max_order=3, smoothing='auto')[source]
Build an ARPA language model from training transcripts.
Uses arpabo with auto mode (optimized Katz backoff) by default.
- Parameters:
- Returns:
Path to created LM file
- Return type:
- pstrain.api.steps.run_step_cd_hmm_untied(project_dir, experiment='default', config='baseline', dry_run=False, **params)[source]
Run CD HMM untied training.
- Parameters:
- Returns:
Exit code (0 for success, non-zero for failure)
- Return type:
- pstrain.api.steps.run_step_ci_hmm(project_dir, experiment='default', config='baseline', dry_run=False, **params)[source]
Run CI HMM training.
- Parameters:
- Returns:
Exit code (0 for success, non-zero for failure)
- Return type:
- pstrain.api.steps.run_step_features(project_dir, experiment='default', config='baseline', dry_run=False, **params)[source]
Run feature extraction step.
- Parameters:
- Returns:
Exit code (0 for success, non-zero for failure)
- Return type:
- pstrain.api.steps.step_cd_hmm_untied(project_dir, experiment='default', config='baseline', **params)[source]
Get the rule definition for CD HMM untied training.
- pstrain.api.steps.step_ci_hmm(project_dir, experiment='default', config='baseline', **params)[source]
Get the rule definition for CI HMM training.
- pstrain.api.steps.step_features(project_dir, experiment='default', config='baseline', **params)[source]
Get the rule definition for feature extraction.
- pstrain.api.steps.features_step
Public feature-extraction step instance.
- pstrain.api.steps.ci_hmm_step
Public context-independent HMM training step instance.
- pstrain.api.steps.cd_hmm_untied_step
Public untied context-dependent HMM training step instance.