I'm having trouble with the logic of the search space definition.
I want to search over these:
Here's the way I've set this up, following this example (second post on page, by jacobzweig)
def para_space():
space_paras = {'model_type': hp.choice('model_type', ['features_and_hours', 'features_only', 'hours_only', 'no_features_no_hours']),
'output_units': hp.uniform('output_units', 1, 10),
'kernel_reg': hp.choice('kernel_reg', [{'reg_type':'l1', 'reg_vals': hp.uniform('reg_vals', 0.0, 0.5)},
{'reg_type':'l2','reg_vals': hp.uniform('reg_vals', 0.0, 0.5)},
{'reg_type':'l1l2', 'reg_vals': hp.uniform('reg_vals', 0.0, 0.5)}]),
'activity_reg': hp.choice('activity_reg', [{'reg_type':'l1', 'reg_vals': hp.uniform('reg_vals', 0.0, 0.5)},
{'reg_type':'l2','reg_vals': hp.uniform('reg_vals', 0.0, 0.5)},
{'reg_type':'l1l2', 'reg_vals': hp.uniform('reg_vals', 0.0, 0.5)}]),
'num_epochs': hp.choice('num_epochs', [1, 5, 10]),
'optimizer': hp.choice('optimizer', ['adadelta', 'adam', 'rmsprop']),
'attention': hp.choice('attention', ['before', 'after', 'none'])}
return space_paras
The error I'm getting is:
Using TensorFlow backend.
Traceback (most recent call last):
File "Jan22Model1.py", line 374, in <module>
best = fmin(lstm_model_1, params, algo=tpe.suggest, max_evals=5, trials=trials)
File "/user/pkgs/anaconda2/lib/python2.7/site-packages/hyperopt/fmin.py", line 307, in fmin
return_argmin=return_argmin,
File "/user/pkgs/anaconda2/lib/python2.7/site-packages/hyperopt/base.py", line 635, in fmin
return_argmin=return_argmin)
File "/user/pkgs/anaconda2/lib/python2.7/site-packages/hyperopt/fmin.py", line 314, in fmin
pass_expr_memo_ctrl=pass_expr_memo_ctrl)
File "/user/pkgs/anaconda2/lib/python2.7/site-packages/hyperopt/base.py", line 776, in __init__
raise DuplicateLabel(label)
hyperopt.exceptions.DuplicateLabel: reg_vals
But in the example, there seem to be duplicate labels that don't throw an error. What am I doing wrong?
I ended up restructuring the space, which solved the problem:
def para_space():
space_paras = {'model_type': hp.choice('model_type', ['features_and_hours', 'features_only', 'hours_only', 'no_features_no_hours']),
'output_units': hp.uniform('output_units', 1, 10),
'kernel_reg': hp.choice('kernel_reg', ['l1', 'l2', 'l1_l2']),
'kernel_reg_value': hp.uniform('kernel_reg_value', 0.0, 0.5),
'activity_reg': hp.choice('activity_reg', ['l1', 'l2', 'l1_l2']),
'activity_reg_value': hp.uniform('activity_reg_value', 0.0, 0.5),
'optimizer': hp.choice('optimizer', ['adadelta', 'adam', 'rmsprop']),
'attention': hp.choice('attention', ['before', 'after', 'none'])}
return space_paras