[ENH] Hidden layer droput uniformization in the deep learning models.
Is your feature request related to a problem? Please describe.
Hidden layer droput uniformization in the deep learning models (classifiers, regressors & networks).
Current behaviour:
- In some of the TensorFlow based deep learning models, hidden layer dropout is hardcoded and not exposed to the users. I have pasted one such example below for illustration. https://github.com/sktime/sktime/blob/071551b59669a946a386617fb7706e69349e5dff/sktime/networks/rnn/_rnn_tf.py#L123
- In Deep Learning models, currently we can only set the hidden layer activations globally but there is no support for setting it layer-wise. Or, if it is set layer-wise then it is hardcoded and not exposed to the end-user. For example, in
MLPNetworkthe dropout is different in each layer because the implementation is based on the model described in section3.2.1 Multi Layer Perceptronon page 14 in Deep learning for time series classification: a review paper from 2019 https://github.com/sktime/sktime/blob/071551b59669a946a386617fb7706e69349e5dff/sktime/networks/mlp.py#L68-L77
Describe the solution you'd like
Expected/Suggested behaviour:
- Wherever dropouts are used in the hidden layers, they should be exposed to the end-user via
dropoutparameter. - Currently, parameter
dropout(wherever present) is expected to be afloat, change it to expect either atupleof floats or a singlefloat. And use the tuple of floats to set layer-wise dropouts, whenever it is specified. - Care needs to be taken in handling the dropouts specified via a tuple, such as enforcing the length of the passed tuple be equal to the number of hidden layers specified, and using the correct dropout in each corresponding hidden layer, etc.
- Care needs to be taken where it is allowed and not-allowed to set the dropout layer-wise. There may be certain network implementations either in TensorFlow or PyTorch which do not allow setting layer-wise dropouts in the network, in such cases parameter
dropoutshould strictly be afloatonly and DOCSTRING should reflect the same. - In current behaviour section above, I have mentioned only 2 examples but all deep learning models should be investigated and fix should be implemented everywhere it is needed.
- In order to maintain the consistent behaviour, while setting the default value of
dropoutparameter- use the same value/s which are currently hard-coded,
- if it is not hard-coded then use the default value from the underlying library's implementation/documentation.
Additional context
This issue originated from the discussion in the comments of #9042
Working on this doesn't require much prior understanding of sktime or any other dependent library and I have made the issue descriptive enough for a new contributor to pick it up. Could you please mark this as a Good First Issue? @fkiraly
My thoughts on deprecation concerns regarding this:
We will be changing the expected behaviour of dropout parameter with this. But it is an enhancement and will not break the current usage or adversely affect any user's current workflow setup if we keep the same defaults which are hard-coded. I do not see a need for implementing this change in a phased manner with deprecation practices.
Let me know what are your thoughts on this.
Hi @RecreationalMath , I would like to work on this. I'll start with the mentioned files mlp.py and _rnn_tf.py first. I plan to expose the dropout parameter that accepts:
None (Default): Preserves the current hardcoded values. float: Sets a uniform dropout rate. list/tuple: Allows layer-wise control.across the deep learning models.
My thoughts on deprecation concerns regarding this: We will be changing the expected behaviour of
dropoutparameter with this. But it is an enhancement and will not break the current usage or adversely affect any user's current workflow setup if we keep the same defaults which are hard-coded. I do not see a need for implementing this change in a phased manner with deprecation practices.Let me know what are your thoughts on this.
Exactly - as long as the defaults stay the same, no deprecation is needed.
Hi @RecreationalMath , I would like to work on this. I'll start with the mentioned files mlp.py and _rnn_tf.py first. I plan to expose the dropout parameter that accepts:
None (Default): Preserves the current hardcoded values. float: Sets a uniform dropout rate. list/tuple: Allows layer-wise control.across the deep learning models.
Yes, exactly, although I would set the default explicitly to not None, i.e., a float or tuple, if that is the default.
Looking forward to your PR!
Hi @abhimanyudalal1, as pointed by Franz above, the default shouldn't be set to None everywhere. Point number 6 (in the Expected/suggested behaviour section of the issue) specifies the priority order in which to set the default value for dropout.
Hi @RecreationalMath , I would like to work on this. I'll start with the mentioned files mlp.py and _rnn_tf.py first. I plan to expose the dropout parameter that accepts:
None (Default): Preserves the current hardcoded values.
In the case of MLP, according to Point number 6, since the current values are hard-coded so precisely those values should be used as defaults so that the behaviour does not change. Hence, default value for MLP will be a tuple: (0.1, 0.2, 0.2, 0.3).
float: Sets a uniform dropout rate.
Correct
list/tuple: Allows layer-wise control.across the deep learning models.
No list, only a tuple.
Happy Coding!
Quick followup, @RecreationalMath - does https://github.com/sktime/sktime/pull/9109 deal with all remaining instances of missing dropout parameter?
does https://github.com/sktime/sktime/pull/9109 deal with all remaining instances of missing dropout parameter?
No,
- #9109 addressed only MLPNetwork and RNNNetwork.
I've opened
- #9208 to address the remaining instances.
Fixed in my PR:
- CNTCNetwork - Had 6 hardcoded
Dropout(0.1)andDropout(0.2)calls, now exposed via dropout parameter (supports float or tuple of 7 values) - TapNetNetwork - Had hardcoded
Dropout(0.8)for LSTM layer that ignored the existing dropout param, now exposed via newlstm_dropout parameter - Updated corresponding classifiers:
CNTCClassifier,CNTCRegressor,TapNetClassifier,TapNetRegressor
I this all now?
Would it be possible to write some programmatic code, where we use all_objects to find all classifiers in the deep_learning module, and get_params to check whether it has a dropout parameter?
Would it be possible to write some programmatic code, where we use
all_objectsto find all classifiers in thedeep_learningmodule, andget_paramsto check whether it has adropoutparameter?
I ran this programmatic check using all_estimators and get_params
from sktime.registry import all_estimators
all_classifiers = all_estimators(estimator_types='classifier')
dl_classifiers = [(n, c) for n, c in all_classifiers if 'deep_learning' in str(c.__module__)]
for name, cls in dl_classifiers:
obj = cls()
params = obj.get_params()
dropout_params = [k for k in params.keys() if 'dropout' in k.lower()]
print(f'{name}: {dropout_params if dropout_params else "NO dropout"}')
result:
| Estimator | Dropout Param(s) | Notes |
|---|---|---|
| CNTCClassifier | ✓ dropout | will be Fixed in #9208 |
| CNTCRegressor | ✓ dropout | will be Fixed in #9208 |
| TapNetClassifier | ✓ dropout, lstm_dropout | will beFixed in #9208 |
| TapNetRegressor | ✓ dropout, lstm_dropout | will be Fixed in #9208 |
| MLPClassifier | ✓ dropout | Fixed in #9109 |
| MLPRegressor | ✓ dropout | Fixed in #9109 |
| SimpleRNNClassifier | ✓ dropout | Fixed in #9109 |
| SimpleRNNRegressor | ✓ dropout | Fixed in #9109 |
| LSTMFCNClassifier | ✓ dropout | Already had it |
| LSTMFCNRegressor | ✓ dropout | Already had it |
| CNNClassifier | ✗ | No Dropout layers in architecture |
| CNNRegressor | ✗ | No Dropout layers in architecture |
| FCNClassifier | ✗ | No Dropout layers in architecture |
| FCNRegressor | ✗ | No Dropout layers in architecture |
| InceptionTimeClassifier | ✗ | No Dropout layers in architecture |
| InceptionTimeRegressor | ✗ | No Dropout layers in architecture |
| MACNNClassifier | ✗ | No Dropout layers in architecture |
| MACNNRegressor | ✗ | No Dropout layers in architecture |
| MCDCNNClassifier | ✗ | No Dropout layers in architecture |
| MCDCNNRegressor | ✗ | No Dropout layers in architecture |
| ResNetClassifier | ✗ | No Dropout layers in architecture |
| ResNetRegressor | ✗ | No Dropout layers in architecture |
verified that networks without a dropout parameter don't have any Dropout layers in their architecture. i.e. All networks that use dropout now have it exposed as a parameter.
Hi @fkiraly, if both #9208 and #9109 are merged, shouldn't this issue be closed? As @xenonnn4w mentioned,
All networks that use dropout now have it exposed as a parameter.
@srupat @xenonnn4w Here are my observations:
- In the programmatic list you shared, only
tensorflowbased models are there andtorchbased models are missing. Could you investigate why is it so? My hunch is, it might be because of inheritance from different base classes. There is some base class intensorflowinheritance trajectory which has the requiredestimator_types='classifier'tag while the same is missing intorchbase class inheritance tranjectory. - From a cursory glance it seems that the network for
ConvTimeNetClassifierhas a fully connected layer which has a dropout parameter. https://github.com/sktime/sktime/blob/f131a1c132c0ea663ad958ca7901eaf36cd07cc5/sktime/networks/convtimenet/_convtimenet.py#L63-L67 Does thisfc_dropoutneeds to exposed to the end user in theConvTimeNetClassifierclass? - Similarly, other
torchbased models also need to be checked.
Hi @RecreationalMath and @fkiraly, I'd like to pick up the remaining work on this, specifically the torch-based models that were missed by the all_estimators audit.
I'll start by looking into sktime/networks/ and sktime/classification/deep_learning/ to identify all hardcoded dropout values in torch models, then fix ConvTimeNetClassifier (fc_dropout=0.0) first, followed by any other torch-based models that need the same treatment. Will open a PR once I have a clear picture of the full scope.
Could I be assigned to this? Thanks!
@Nidhicodes Please do share your findings either here or in the PR description.
FYI: My above message suggests places to look into. What the exact fix should be remains to be checked. I welcome you to look into it.