provides a convenient base configuration class for machine learning projects
Project description
ml-config
Super lightweight library to provide a simple base configuration class for machine learning projects.
There is only one module ml_config.configuration that contains the BaseConfig class.
Features
- Support for nested configurations
- Hassle-free configuration initialization from nested dictionary and yaml file.
- Hassle-free configuration output to dictionary and yaml file.
Installation
pip install easy-ml-config
Usage
Start with defining your own configuration by inheriting from BaseConfig. Once you have that, you can utilize all the predefined functionalities of BaseConfig.
Define Your Configuration
from dataclasses import dataclass
from easy_ml_config import BaseConfig
@dataclass
class MyModelConfig(BaseConfig):
num_layer: int
@dataclass
class MyExpConfig(BaseConfig):
model: MyModelConfig
batch_size: int
learning_rate: float
Instantiate Your Configuration
When you are running an experiment with a specific settings. Initialize your configurations.
Initialize from A Dictionary
def main():
nested_args = {
"model": {
"num_layer": 3,
},
"batch_size": 32,
"learning_rate": 0.001,
}
config = MyExpConfig.from_dict(nested_args)
# model = MyModel(num_layer=config.model.num_layer)
if __name__ == "__main__":
main()
Initialize from A YAML File
# config.yaml
model:
num_layer: 3
batch_size: 32
learning_rate: 0.001
config = MyExpConfig.from_yaml("config.yaml")
Output Your Configuration
Often you might want to save your configuration to a file. You can do that easily with the to_dict and to_yaml methods.
# Save to a dictionary
config_dict = config.to_dict()
# Save to a yaml file
config.to_yaml("config.yaml")
The exported dictionary and yaml file can be directly used again to recreate the Configurations.
# Load from a dictionary
config = MyExpConfig.from_dict(config_dict)
# Load from a yaml file
config = MyExpConfig.from_yaml("config.yaml")
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file easy_ml_config-1.0.1.tar.gz.
File metadata
- Download URL: easy_ml_config-1.0.1.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.29
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb75d8845d421edf450e4714aef79e1c11192fa719afc829f4a08cde42480376
|
|
| MD5 |
a24002b957d86a795d18d559ac63abc3
|
|
| BLAKE2b-256 |
0d3e4c2f16032430e471161f4972c7d4403c54bb567be60ab5515127e1f45fe5
|
File details
Details for the file easy_ml_config-1.0.1-py3-none-any.whl.
File metadata
- Download URL: easy_ml_config-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.29
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d27af1bf0180b1fff7a8321c08db32f03cfc3e7a63b6b6133b2753942a90ab09
|
|
| MD5 |
1e555c835356d4235d193f43a644f26e
|
|
| BLAKE2b-256 |
c77b1f1f3e4f5a547dadb950c03b0c94447b5619f530abc16d416d9517115ea3
|