You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think giving users better errors and validating their inputs like you are doing here can be a very valuable part of SciKeras, but currently it is done in an ad-hoc manner via _check_model_compatibility, etc. I think if we add more of these types of things, it would be nice to have an organized interface for it.
It would be good to organize these checks. We can split them into two categories:
Checks before fit is called. This includes checking if the model is compiled, if it has a loss, that the number of outputs match the target, etc.
Error handling after fit or predict are called: translating cryptic Keras/TF erorrs into user friendly errors with suggestions to fix them.
I envision something like this, inspired by Pydantic:
wrappers.py
classBaseWrapper(...):
def__get_pre_fit_validators__(self) ->Generator[Callable[[BaseWrapper, Dict[str, Any]], None], None, None]:
yieldvalidate_compiled# accepts self & self.model_.fit kwargsyieldvalidate_has_lossyieldvalidate_outptus_match_target
....
def__handle_keras_exceptions__(self) ->Generator[Callable[Exception, BaseWrapper, Dict[str, Any], Literal["fit", "predict"]], None, None]:
yieldcatch_some_cryptic_error# can pass by just returning without raisingyieldcatch_some_other_cryptic_errordef_fit_keras_model(....):
fit_kwargs= ...
forvalidatorinself.__get_pre_fit_validators__():
validator(self, fit_kwargs)
try:
self.model_.fit(..., **fit_kwargs)
exceptExceptionase:
forhandlerinself.__handle_keras_exceptions__():
handler(e, fit_kwargs, "fit")
raise# if no handler caught it
And then we can split out SciKeras' default checks into their own modules:
From #208 (comment) :
It would be good to organize these checks. We can split them into two categories:
fit
is called. This includes checking if the model is compiled, if it has a loss, that the number of outputs match the target, etc.fit
orpredict
are called: translating cryptic Keras/TF erorrs into user friendly errors with suggestions to fix them.I envision something like this, inspired by Pydantic:
wrappers.py
And then we can split out SciKeras' default checks into their own modules:
_utils.validators.py
_utils.erorr_handlers.py
And adding new checks (eg. to check things in
KerasClassifier
that don't make sense inBaseWrapper
is made more explicit:wrappers.py
The text was updated successfully, but these errors were encountered: