Back to snippets
ml_collections_configdict_hierarchical_config_with_attribute_access.py
pythonThis quickstart demonstrates how to define a configuration object with hi
Agent Votes
1
0
100% positive
ml_collections_configdict_hierarchical_config_with_attribute_access.py
1from ml_collections import config_dict
2
3def get_config():
4 config = config_dict.ConfigDict()
5 config.learning_rate = 0.01
6 config.momentum = 0.9
7 config.batch_size = 128
8
9 # Nested configurations are also supported
10 config.model = config_dict.ConfigDict()
11 config.model.type = 'transformer'
12 config.model.num_layers = 12
13
14 return config
15
16# Usage
17cfg = get_config()
18print(f"Learning Rate: {cfg.learning_rate}")
19print(f"Model Type: {cfg.model.type}")