Hyperopt for people who'd rather not learn Hyperopt
A thin wrapper that lets you tune Keras hyperparameters by sprinkling {{mustache}} templates into your model code.

What it does
Hyperas bridges Keras and Hyperopt so you can optimize dropout rates, layer sizes, optimizers, and even conditional layer stacks without writing Hyperopt’s verbose search-space syntax. You wrap your data and model in functions, drop {{uniform(0, 1)}} or {{choice([64, 128])}} where you want variation, and call optim.minimize(). Under the hood it does Jinja-style template replacement, spits out a temporary Python file, and feeds that to Hyperopt’s TPE sampler.
The interesting bit
The trick is that your create_model() function stops being valid Python the moment you add those double curly braces. Hyperas leans into this: it parses your source as text, swaps the templates for Hyperopt variables, and runs the generated code. It’s a hack, but a deliberate one that saves you from manually building Hyperopt’s space dictionary.
Key highlights
- Supports conditional architecture changes (e.g., add a fourth layer only if a
choiceresolves to'four') - Can swap entire layer blocks, not just scalar hyperparameters
- Distributed search via MongoDB by copying the generated
temp_model.pyto worker machines - Data function stays separate so Hyperopt doesn’t reload your dataset on every trial
- Passes positional arguments to your data loader through
data_args
Caveats
- Requires
networkx==1.11to avoid a known generator subscripting bug (issue #125) - Jupyter notebooks need explicit
notebook_name='...'parameter to avoid file-not-found errors - The README itself warns: “If it’s not convenient to use in your situation, simply don’t use it — and choose Hyperopt instead”
- Keyword arguments to
data()are not supported; only positional args thatrepr()can display
Verdict
Worth a look if you’re already using Keras and want to dip a toe into hyperparameter search without committing to Hyperopt’s API. Skip it if you need fine-grained control over the search space or if template-based code generation makes you nervous.