HyperPyYAML

1.2.3 · active · verified Sat Apr 11

HyperPyYAML is a Python library that extends the YAML syntax for enhanced interaction with Python objects and better hyperparameter definition. It is actively maintained, with a recent version 1.2.3, and typically releases updates as needed for bug fixes and new features.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to load a YAML string containing HyperPyYAML extensions. It shows the use of `!ref` for referencing other parameters and `!new` for instantiating Python objects (like PyTorch modules) directly from the YAML.

import torch
from hyperpyyaml import load_hyperpyyaml

example_hyperparams_yaml = """
base_channels: 32
kernel_size: 11
padding: !ref <kernel_size> // 2
layer1: !new:torch.nn.Conv1d
  in_channels: 1
  out_channels: !ref <base_channels>
  kernel_size: !ref <kernel_size>
  padding: !ref <padding>
model: !new:torch.nn.Sequential
  - !ref <layer1>
  - !new:torch.nn.LeakyReLU
"""

# Using load_hyperpyyaml to parse the YAML string
loaded_hparams = load_hyperpyyaml(example_hyperparams_yaml)

print(loaded_hparams['base_channels'])
print(loaded_hparams['padding'])
print(loaded_hparams['model'])

view raw JSON →