Layers & Activations
Dropout & Flatten
Inverted Dropout regularization and tensor dimension flattening for MLP and CNN pipelines.
ochreml.nn.Dropout applies inverted dropout during training (scaling surviving activations by 1 / (1 - p)) and acts as a no-op during eval(). ochreml.nn.Flatten collapses trailing tensor dimensions from start_dim onward.
Import & Signatures
import ochreml.nn as nn
drop = nn.Dropout(p=0.5, seed=42)
flat = nn.Flatten(start_dim=1)Parameters
| Class | Parameter | Type | Default | Description |
|---|---|---|---|---|
Dropout | p | float | 0.5 | Probability of zeroing an element during training (0.0 <= p < 1.0). |
Dropout | seed | int | 42 | Deterministic PRNG seed (advances automatically each forward call). |
Flatten | start_dim | int | 1 | First dimension to flatten (default 1 preserves batch dimension N). |
Usage Example
import ochreml.nn as nn
x = nn.Tensor.randn([4, 16, 8, 8])
flat = nn.Flatten(start_dim=1)(x) # shape: (4, 1024)
drop = nn.Dropout(p=0.2)
drop.train()
h_train = drop(flat)
drop.eval()
h_eval = drop(flat) # identity pass-through