TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
←

11. Dropout Forward

Medium

Implement the dropout forward pass in training mode.

Signature: def dropout_forward(x: np.ndarray, p: float, seed: int = 0) -> np.ndarray

  • Each element is zeroed independently with probability p
  • Surviving elements are scaled by 1/(1-p) (inverted dropout)
  • Use np.random.default_rng(seed) for reproducibility

Math

y=1−px⊙mask​,maski​∼Bernoulli(1−p)

Related problems

  • Dropout Forward (PyTorch)mediumPyTorch

Asked at

Python 30/10 runs today

Output

Anything you print() in your code will show up here after you click Run.

Test Results

○p=0 no dropout
○p=0.5 with seed 42
○p=0.5 with seed 0🔒 Premium
○p=0 → output equals input (negative values too)
○idempotent when p=0
○3D (B, T, C) transformer input with p=0.5