hyperas
hyperas copied to clipboard
Index out of range.
I am trying to implement this for my predictive neural network but it returns the following error:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-21-66686af6d687> in <module>()
5 max_evals=5,
6 notebook_name='gridsearch',
----> 7 trials=Trials())
8 x_train, y_train, x_val, y_val = data()
9 print("Evalutation of best performing model:")
~/anaconda3/envs/poc/lib/python3.6/site-packages/hyperas/optim.py in minimize(model, data, algo, max_evals, trials, functions, rseed, notebook_name, verbose, eval_space, return_space)
65 full_model_string=None,
66 notebook_name=notebook_name,
---> 67 verbose=verbose)
68
69 best_model = None
~/anaconda3/envs/poc/lib/python3.6/site-packages/hyperas/optim.py in base_minimizer(model, data, functions, algo, max_evals, trials, rseed, full_model_string, notebook_name, verbose, stack)
94 model_str = full_model_string
95 else:
---> 96 model_str = get_hyperopt_model_string(model, data, functions, notebook_name, verbose, stack)
97 temp_file = './temp_model.py'
98 write_temp_files(model_str, temp_file)
~/anaconda3/envs/poc/lib/python3.6/site-packages/hyperas/optim.py in get_hyperopt_model_string(model, data, functions, notebook_name, verbose, stack)
182 imports = extract_imports(cleaned_source, verbose)
183
--> 184 parts = hyperparameter_names(model_string)
185 aug_parts = augmented_names(parts)
186
~/anaconda3/envs/poc/lib/python3.6/site-packages/hyperas/optim.py in hyperparameter_names(model_string)
249 parts.append(name[0])
250 else:
--> 251 parts.append(parts[-1])
252 part_dict = {}
253 for i, part in enumerate(parts):
IndexError: list index out of range
The code used can be found:
Id be glad to provide more information if needed.
the error indicates there are no {{}} patterns found in your model definition, hence parts is empty. We've recently had a fix for removing comments from scripts, so you might want to install current hyperas master.
In any case, it might be worth deleting stuff like #init_par = from your cells. Generally such lines make it harder for hyperas to parse your script.
I've deleted all my comments and made sure there are spaces in front of the {{, yet it still returns the same exact error. I've installed the most recent version of both hyperas and hyperopt according to the issue template. So I am on hyperas 4.0 and hyperopt 0.1. Also when I add a plain {{}} in on of the lines or a {{choice()}} they are also not found. I've exported the script from Jupyter and then tried running it but no avail... https://gist.github.com/GijsVermarien/ba532d90c78d89ccd1dec91e34a05c04
Thanks for providing the gist, much easier like this. So, stuff like:
depth_par = [3, 4, 5]
size_par = [72, 144, 256, 512, 1024]
activation_par = ["ReLU", "ELU"]
lr_par = [1e-1, 1e-2, 1e-3]
rr_par = [1e-1, 1e-3, 1e-6]
reg = ["l1", "l2"]
stop_par = [50, 100, 200]
layers = [x_size, {{choice([72, 144, 256, 512, 1024])}} , y_size]
won't work. e.g. model.add(Dense(layers[1],name=dense, ...) is bound to fail. Templates need to be inserted directly.
I have eliminated all the parameters and dumbed it down to just varying the layer size, depth, learning rate and early stopping. Yet it still doesn't seem to work. See the code attached in this gist: https://gist.github.com/GijsVermarien/c544ab23b9aaffad13c7f4283cff3e8d The error given is still:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-5-66686af6d687> in <module>()
5 max_evals=5,
6 notebook_name='gridsearch',
----> 7 trials=Trials())
8 x_train, y_train, x_val, y_val = data()
9 print("Evalutation of best performing model:")
~/anaconda3/envs/poc/lib/python3.6/site-packages/hyperas/optim.py in minimize(model, data, algo, max_evals, trials, functions, rseed, notebook_name, verbose, eval_space, return_space)
65 full_model_string=None,
66 notebook_name=notebook_name,
---> 67 verbose=verbose)
68
69 best_model = None
~/anaconda3/envs/poc/lib/python3.6/site-packages/hyperas/optim.py in base_minimizer(model, data, functions, algo, max_evals, trials, rseed, full_model_string, notebook_name, verbose, stack)
94 model_str = full_model_string
95 else:
---> 96 model_str = get_hyperopt_model_string(model, data, functions, notebook_name, verbose, stack)
97 temp_file = './temp_model.py'
98 write_temp_files(model_str, temp_file)
~/anaconda3/envs/poc/lib/python3.6/site-packages/hyperas/optim.py in get_hyperopt_model_string(model, data, functions, notebook_name, verbose, stack)
182 imports = extract_imports(cleaned_source, verbose)
183
--> 184 parts = hyperparameter_names(model_string)
185 aug_parts = augmented_names(parts)
186
~/anaconda3/envs/poc/lib/python3.6/site-packages/hyperas/optim.py in hyperparameter_names(model_string)
249 parts.append(name[0])
250 else:
--> 251 parts.append(parts[-1])
252 part_dict = {}
253 for i, part in enumerate(parts):
IndexError: list index out of range
Hello sir, I've came across the same error but still not found any fix for the issue. Can you help me by stating what you have done to fix it in your case?
Hello sir, I've came across the same error but still not found any fix for the issue. Can you help me by stating what you have done to fix it in your case?
Hi, in the end I choose to write my own custom loop doing essentially what hyperas should do. But I would now advise to just use hyperopt or another framework as this library has not been updated for the past 11 months.
Thank you sir, for your reply. Can you suggest me any specific framework as alternative of hyperas and related documentation sites, please?
Thank you sir, for your reply. Can you suggest me any specific framework as alternative of hyperas and related documentation sites, please?
I think this is what you could use: http://hyperopt.github.io/hyperopt/ but a for loop with your parameters could also work pretty well, only takes some time to develop it.
My fix for this error was to simply move my parameters into an assigned variable. So replace code like this:
args = {
'x': {{uniform(0,1)}}
}
With this:
x = {{uniform(0,1)}}
args = {
'x': x
}