From scratch (& bare bones) Experiment Management.
with open(f'{EXPERIMENT_STORE}/lstm_base/experiment.yaml', 'rb') as f:
exp = yaml.full_load(f)
exp
exp['params']['model_params']
print(exp['params']['model_params']['lstm_layers'])
exp['params']['data_params']['labels']
Once we import Addict, like this ..
from addict import Dict
It allows us to access dict keys like an attribute.
A discussion on StackOverflow details other options like AttrDict and Munch.
exp_addict = Dict(exp)
exp_addict
exp_addict.params.model_params
exp_addict.params.model_params.values()
sys.version_info[1]>=8
Only the first 5 arguments are required, if the rest are not passed in, default values will be used (including for stores - EXPERIMENT_STORE
and MODEL_STORE
).
Creating an LSTM experiment with default parameters will look like this ..
labels = ['diabetes', 'stroke', 'alzheimers', 'coronary_heart', 'breast_cancer', 'epilepsy']
lstm_base = Experiment.create('lstm_base', 'baseline for LSTMs', PATH_1K, labels, 'Adagrad', 'LSTM')
Testing __repr__()
lstm_base
lstm_base.fit(3, verbosity=1)
Loading that saved experiment into a variable with a different name ..
lstm_base_exp = Experiment.load('lstm_base')
%time lstm_base_exp.fit(2, from_checkpoint=True)
Predicting ..
lstm_base_exp.predict()
Testing - creating a new experiment from file
- here we will use the settings file saved by the last experiment
- in reality, this is for when you create multiple experiment settings after a hyperparameter search
- In that case each experiment will be in its own directory in the
EXPERIMENT_STORE
- And each will have a dedicated settings file called
experiment.yaml
- In that case each experiment will be in its own directory in the
lstm_exp_2 = Experiment.create_from_file(EXPERIMENT_STORE, 'lstm_base')
lstm_exp_2
Creating a CNN experiment with default parameters
cnn_base = Experiment.create('cnn_base', 'baseline for CNNs', PATH_1K, labels, 'Adagrad', 'CNN')
cnn_base
cnn_base.fit(3)
cnn_base_exp = Experiment.load('cnn_base')
%time cnn_base_exp.fit(2, from_checkpoint=True, plot=False)
cnn_base_exp.predict()
Testing creating from file, like we did above with the LSTM
cnn_exp_2 = Experiment.create_from_file(EXPERIMENT_STORE, 'cnn_base')
cnn_exp_2
cnn_exp_2.fit(3)