classification_report.config

Module Contents

class classification_report.config.Config(**kwargs)[source]

Bases: object

This class can be used to create and store data for an type of configuration.

Parameters:**kwargs – Arbitrary keyword arguments.
Examples::
>>> from classification_report import Config
>>> training_config = Config(lr=0.1, batch_size=32, device="GPU")
>>> model_config = Config(number_layers=3, num_head=32)
>>> model_config.number_layers
3
__setattr__(self, name, value)[source]
__getattr__(self, name)[source]
__delattr__(self, name)[source]
update(self, **kwargs)[source]

To update the config class attributes values.

This will add new attribute for a non existing attribute in the Config class or replace the value with a new a value for an existing attribute.

Parameters:**kwargs – Arbitrary keyword arguments.
Examples::
>>> from classification_report import Config
>>> training_config = Config(lr=0.1, batch_size=32, device="GPU")
>>> training_config.lr
0.1
>>> training_config.update(lr=0.2,precision:16)
>>> training_config.lr
0.2
append_values(self, **kwargs)[source]

This method can be used to append values to an existing attribute.

For Example if using Lr Scheduler then this can be use to track all lr values by appending in a list.

Note

The attribute should be prexisiting.

Parameters:**kwargs – Arbitrary keyword arguments.
Examples::
>>> from classification_report import Config
>>> training_config = Config(lr=0.1, batch_size=32, device="GPU")
>>> training_config.lr
0.1
>>> training_config.append_values(lr=0.2)
>>> training_config.lr
[0.1,0.2]
>>> training_config.append_values(lr=[0.3,0.4])
>>> [0.1,0.2,0.3,0.4]
__str__(self)[source]
save_config_json(self, path: str)[source]

Save the Configuration in json format.

Parameters:path – The file path to save json file.
Examples::
>>> from classification_report import Config
>>> training_config = Config(lr=0.1, batch_size=32, device="GPU")
>>> training_config.save_config_json("training_config.json")
Configuration Saved
classmethod load_config_json(cls, path: str)[source]

Loading the saved configuration.

Parameters:path – The file from json config will be loaded.
Returns:A Config Class is returned with attributes set from json file
Return type:Config
Examples::
>>> from classification_report import Config
>>> training_config = Config.load_config_json("training_config.json") # Execute the saving code first.
>>> training_config.lr
0.1
get_dict_repr(self)[source]
Returns:The Dictionary representation of Config class
Return type:dict
Example::
>>> from classification_report import Config
>>> training_config = Config(lr=0.1, batch_size=32, device="GPU")
>>> training_config.get_dict_repr()
{"lr":0.1,"batch_size":32,"device":"GPU"}
class classification_report.config.HyperParameters(**configs)[source]

Bases: classification_report.config.Config

It stores collections of Config in one place. It inherits the Config class.

Parameters:**config – Arbitary Config objects
Raises:AssertionError – Pass only Config class object.
Examples::
>>> from classification_report import Config, HyperParameters
>>> model_config = Config(**{'hid_dim': 512,'n_layers': 8,'n_heads': 8,'pf_dim': 2048,'dropout': 0.1})
>>> training_config = Config(num_epochs=15, max_lr=0.09, batch_size=64)
>>> inference_config = Config(batch_size=16)
>>> hyper = HyperParameters(model_config = model_config, training_config=training_config,infer_config=inference_config)
>>> hyper.model_config.hid_dim
512
>>> hyper.save_config_json("hyper.json")
Configuration Saved
>>> hyper = HyperParameters.load_config_json("hyper.json")
Saved Configuration Loaded
static flatten(d: dict, parent_key: str = '', sep: str = '_')[source]

Flatten the nested dictionary using recusrion.

Parameters:
  • d – The dictionary to flatten.
  • parent_key – The parent key.
  • sep – The sep to be used to join parent_key with nested_key
Returns:

Flattened dictionary.

Return type:

dict