Skip to content

Add callback so we can do pruning and check for nan values. #327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 4, 2020

Conversation

PhilipMay
Copy link
Contributor

@PhilipMay PhilipMay commented Jul 28, 2020

I added a callback function. This way I can implement pruning and check for nan values when doing automated hyperparameter optimization. What do you think?

Some docstrings are still missing so if you agree I would complete the PR.

Thanks
Philip

@PhilipMay PhilipMay changed the title Add callback to eval do we can do pruning and check for `nan values. Add callback so we can do pruning and check for `nan values. Jul 28, 2020
@PhilipMay PhilipMay changed the title Add callback so we can do pruning and check for `nan values. Add callback so we can do pruning and check for nan values. Aug 2, 2020
@PhilipMay
Copy link
Contributor Author

PhilipMay commented Aug 6, 2020

Do you have any questions about this PR?
I would really appreciate a merge.

@nreimers
Copy link
Member

nreimers commented Aug 6, 2020

Hi,
thanks for adding this. I think is is a useful function and I will try to merge it into the next release.

Currently I try to think about if the callback could return something that influences the training, for example, stopping the training or what so ever.
But:

  1. I am not sure what the best option would be to implement this.
  2. Which features would be needed? Stopping training? Trigger to save / not save the model?
  3. And if a return would be needed at all.

Also, it would be an option to add the callback to the evaluators instead of to the fit function. This would have the advantage that each evaluator could have it's own callback, which might (or might not) be quite useful if you evaluate your model on more than dev dataset.

It would be great to learn more how you are using this callback for hyperparameter tuning.

@PhilipMay
Copy link
Contributor Author

PhilipMay commented Sep 2, 2020

It would be great to learn more how you are using this callback for hyperparameter tuning.

I use it in optuna for automated hyperparameter optimization. Optuna has something called pruning where
you can stop evaluating one set of hyperparameters when you see that it is unpromising.

I noticed that some hyperparameter combinations return nan at some point during training.
This is when I prune by raising a special "prune exception" in the callback.

It looks like this:

def callback(value, a, b):
    print('callback:', value, a, b)
    if math.isnan(value):
        raise optuna.exceptions.TrialPruned()

See more here: https://optuna.readthedocs.io/en/stable/tutorial/pruning.html

@nreimers nreimers merged commit 2e0b5d6 into UKPLab:master Sep 4, 2020
@nreimers
Copy link
Member

nreimers commented Sep 4, 2020

Thanks for the PR. Merged it and it will be part of the next release (0.3.6)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants