kiudee / cs-ranking

Context-sensitive ranking and choice in Python with PyTorch
https://cs-ranking.readthedocs.io
Apache License 2.0
66 stars 15 forks source link

Move stateful initialization to a pre_fit function #159

Closed timokau closed 4 years ago

timokau commented 4 years ago

Description

Creates a _pre_fit function to bridge the gap between __init__ and fit: Everything which initializes some state, but does not actually depend on the data, belongs there. This separates concerns a bit and makes it possible to inherit those initializations.

I thought about making this an implicit wrapper (a wrapper defined in learner that inherits signature & docs and automatically prepends a call to pre_fit to every fit call). This might be possible with wrapt and a meta-class, but it would be a little complex. Since it would also be less explicit, it might be a bit confusing for people who are not very familiar with the code. So I just went with an explicit call to _pre_fit for now.

I could imagine to automate the calls to initialize_optimizer and initiialize_regularizer in the future, but again I'm not entirely certain its desirable because it would feel a little "magic".

Motivation and Context

https://github.com/kiudee/cs-ranking/pull/157#issuecomment-690261372

How Has This Been Tested?

Pre-commit & test suite.

Does this close/impact existing issues?

Impacts #94, #116, #146.

Types of changes

Checklist: