Causal Padding and Look-Ahead Leakage
Standard convolution padding centers each kernel on its position and secretly uses future timesteps to compute the present; causal padding pads only on the past side so a prediction at time t can never depend on data after t.
Prerequisites: Receptive Fields and Dilation, One-Dimensional Convolutions for Price Series
A convolution layer slides a small kernel across a sequence, and the standard ("same") padding scheme centers that kernel on each output position so the output shape matches the input shape. For images, centering is harmless — there is no "before" or "after" a pixel. For a time series, centering means the kernel's output at time silently includes inputs from after too, which is exactly the information a real forecast at time would never actually have.
The analogy: never read tomorrow's newspaper
A detective solving today's case must never sneak a look at tomorrow's newspaper for clues — that would invalidate the whole investigation, even if the peek happens buried inside some innocuous-looking procedure. Any layer that lets a prediction at time depend, even partially, on data from after has done exactly this, whether or not it looks like cheating on the surface.
The mechanics
For a kernel of size and dilation , "same" padding splits padding values evenly across both sides of the sequence, so the kernel window centered at position reaches both before and after . Causal padding instead places all padding on the left (past) side only:
In words: the output at time is a weighted sum built exclusively from and earlier values — never from or beyond — because every index in the sum is minus something non-negative.
Worked example 1: which positions get touched
Kernel size 3, sequence . Under same padding, the output at position uses — it depends on , which lies in the future relative to . Under causal padding, the output at position 4 uses — entirely past-and-present, never future.
Worked example 2: a value that shouldn't matter but does
Weights (oldest to newest in the window), and suppose . Under causal padding, — changing afterward has zero effect on this number, by construction. Under same padding, : if later changes from to , the already computed output at position 4 changes too — a live model, computing this in real time, could never have known yet, so this "prediction" for time 4 was never actually producible at time 4.
Standard "same" padding centers a convolution kernel on each position, which for time-ordered data means the output at time t silently depends on inputs after t; causal padding places all padding on the past side only, guaranteeing the output at t depends exclusively on data at or before t.
What this means in practice
This exact bug is one of the most common ways a backtested time-series model looks excellent in-sample and then fails once deployed live — if any layer touching time-ordered data used symmetric or "same" padding, the reported validation accuracy is contaminated by future information the model would never actually have at prediction time.
The leakage from non-causal padding is silent. The model trains normally, the loss goes down, and offline validation metrics look fine — because during offline evaluation, "future" data is sitting right there in the dataset too. The failure only shows up live, where the future genuinely doesn't exist yet, which is exactly why every convolutional or sequence layer touching time-ordered financial data needs to be explicitly checked for causal padding, not just RNNs, which are causal by construction.
Related concepts
Practice in interviews
Further reading
- van den Oord et al., WaveNet: A Generative Model for Raw Audio (2016)