sktime icon indicating copy to clipboard operation
sktime copied to clipboard

[ENH] Hidden layer droput uniformization in the deep learning models.

Open RecreationalMath opened this issue 1 year ago • 14 comments

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 MLPNetwork the dropout is different in each layer because the implementation is based on the model described in section 3.2.1 Multi Layer Perceptron on 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:

  1. Wherever dropouts are used in the hidden layers, they should be exposed to the end-user via dropout parameter.
  2. Currently, parameter dropout (wherever present) is expected to be a float, change it to expect either a tuple of floats or a single float. And use the tuple of floats to set layer-wise dropouts, whenever it is specified.
  3. 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.
  4. 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 dropout should strictly be a float only and DOCSTRING should reflect the same.
  5. 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.
  6. In order to maintain the consistent behaviour, while setting the default value of dropout parameter
    1. use the same value/s which are currently hard-coded,
    2. 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

RecreationalMath avatar Nov 22 '25 23:11 RecreationalMath

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

RecreationalMath avatar Nov 23 '25 00:11 RecreationalMath

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.

RecreationalMath avatar Nov 23 '25 00:11 RecreationalMath

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.

abhimanyudalal1 avatar Nov 23 '25 18:11 abhimanyudalal1

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.

Exactly - as long as the defaults stay the same, no deprecation is needed.

fkiraly avatar Nov 23 '25 21:11 fkiraly

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!

fkiraly avatar Nov 23 '25 22:11 fkiraly

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!

RecreationalMath avatar Nov 23 '25 22:11 RecreationalMath

Quick followup, @RecreationalMath - does https://github.com/sktime/sktime/pull/9109 deal with all remaining instances of missing dropout parameter?

fkiraly avatar Jan 03 '26 21:01 fkiraly

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) and Dropout(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 new lstm_dropout parameter
  • Updated corresponding classifiers: CNTCClassifier, CNTCRegressor, TapNetClassifier, TapNetRegressor

xenonnn4w avatar Jan 04 '26 07:01 xenonnn4w

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?

fkiraly avatar Jan 04 '26 08:01 fkiraly

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?

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.

xenonnn4w avatar Jan 04 '26 08:01 xenonnn4w

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 avatar Jan 31 '26 05:01 srupat

@srupat @xenonnn4w Here are my observations:

  1. In the programmatic list you shared, only tensorflow based models are there and torch based 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 in tensorflow inheritance trajectory which has the required estimator_types='classifier' tag while the same is missing in torch base class inheritance tranjectory.
  2. From a cursory glance it seems that the network for ConvTimeNetClassifier has a fully connected layer which has a dropout parameter. https://github.com/sktime/sktime/blob/f131a1c132c0ea663ad958ca7901eaf36cd07cc5/sktime/networks/convtimenet/_convtimenet.py#L63-L67 Does this fc_dropout needs to exposed to the end user in theConvTimeNetClassifier class?
  3. Similarly, other torch based models also need to be checked.

RecreationalMath avatar Feb 02 '26 15:02 RecreationalMath

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 avatar Mar 08 '26 06:03 Nidhicodes

@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.

RecreationalMath avatar Mar 08 '26 09:03 RecreationalMath