I'm looking for a trick similar to that used by KerasTuner's hyperparameters, which as a reminder might do something like:
def make_hyper_model(hp: kerastuner.HyperParameters):
model = keras.Sequential([
Dense(hp.Int('units', min_value=8, max_value=64, step=2)
])
return model
This can later be used for tuning hyperparameters by doing some smart searching through the parameter space.
What I want is some way of doing this in a composable manner without having to pass around a HyperParameters
object.
Ergo:
import hyper_it # import some module (hypothetical)
@hyper_it.perhaps_some_decorator
def helper():
what_to_do = hyper_it.choice(['foo', 'bar'])
return what_to_do
@hyper_it.perhaps_some_decorator
def main():
print(helper(), hyper_it.choice([1, 3]), end=' ')
main.scan_all() # Some method using the resulting composition of parameterized functions.
## prints: "foo 1 foo 3 bar 1 bar 3"
I suppose this could pass an object around under the hood (like the HyperParameters
in the kerastuner version), but it would be best if that can be hidden from the user.
Any ideas on how to implement something like this?
question from:
https://stackoverflow.com/questions/65887941/composable-parameter-iteration-in-python 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…