v9.1.1
Menu

Inverted Dropout Forward

mediumPRORegularization & TuningDeep LearningDeep Learning 1

Problem Statement

Implement the forward pass of Inverted Dropout.

Background

Dropout is a regularization technique that randomly "drops" neurons during training to prevent overfitting. In Inverted Dropout:

  1. Each neuron is dropped with probability pp (drop_prob)
  2. Remaining neurons are scaled by 11−p\frac{1}{1 - p} to keep expected values the same
  3. During inference (test mode), no dropout is applied

The scaling ensures that expected output values are consistent between training and testing.

Your Task

Write a function dropout_forward(activations, drop_prob, mask, train_mode=True) that:

  • If train_mode=False: return activations unchanged
  • If train_mode=True: apply the given mask (0s and 1s) and scale by 1/(1-drop_prob)

The mask is provided as input (list of 0s and 1s) to make testing deterministic.

Output Format

Return a list of values after applying dropout. Round each value to 4 decimal places.

Example

Input
activations=[10, 20, 30], drop_prob=0.5, mask=[1, 0, 1], train_mode=True
Output
[20.0, 0, 60.0]
Reasoning

Scale = 1/(1-0.5) = 2. First: 10×110 \times 1×2=20. Second: 20×020 \times 0=0. Third: 30×130 \times 1×2=60.

Constraints

  • 0 < drop_prob < 1
  • len(activations) == len(mask)
  • mask contains only 0s and 1s
  • List length: 1 to 100 elements

Learn this in

More from Deep Learning 1

PRO

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test results

Sign in to run your code against the test cases.