The Pythonic API#
Hypster’s API is designed to be intuitive and expressive, allowing you to use familiar Python constructs in your configuration functions.
Conditional Statements for Dependent Variables#
You can use conditional statements to define dependent variables:
from hypster import HP, config
@config
def conditional_config(hp: HP):
model_type = hp.select(["CNN", "RNN", "Transformer"], default="CNN")
if model_type == "CNN":
num_layers = hp.select([3, 5, 7], default=5)
elif model_type == "RNN":
cell_type = hp.select(["LSTM", "GRU"], default="LSTM")
else: # Transformer
num_heads = hp.select([4, 8, 16], default=8)
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 1
----> 1 from hypster import HP, config
4 @config
5 def conditional_config(hp: HP):
6 model_type = hp.select(["CNN", "RNN", "Transformer"], default="CNN")
ModuleNotFoundError: No module named 'hypster'
Loops#
You can use loops to define repetitive configurations:
from hypster import HP, config
@config
def loop_config(hp: HP):
num_layers = hp.select([3, 5, 7], default=5)
layer_sizes = []
for i in range(num_layers):
layer_sizes.append(hp.select([32, 64, 128], default=64, name=f"layer_{i}_size"))
Changing Options Conditionally#
You can dynamically change the options based on other selections:
from hypster import HP, config
@config
def dynamic_options_config(hp: HP):
dataset_size = hp.select(["small", "medium", "large"], default="medium")
if dataset_size == "small":
model_options = ["simple_cnn", "small_rnn"]
elif dataset_size == "medium":
model_options = ["resnet", "lstm"]
else:
model_options = ["transformer", "large_cnn"]
model = hp.select(model_options)
Summary#
By allowing pythonic configuration spaces you can:
Use conditional statements to define dependent variables
Utilize loops for repetitive configurations
Dynamically change options based on other selections
And much more! :)