medium end_to_end

Simple CNN

Build a minimal CNN: 1D convolution + max pooling + fully connected layer.

Pipeline:

  1. Conv1D: slide a kernel of size K over input with stride 1, add bias. $\text{conv}[i] = \sum_{k=0}^{K-1} x[i+k] \cdot w[k] + b_{conv}$ Output length: $L_{out} = L - K + 1$
  2. ReLU: element-wise $\max(0, z)$
  3. Global Max Pool: take the max over the sequence to get a single scalar.
  4. FC layer: $y = \text{pool\_out} \cdot w_{fc} + b_{fc}$

Input:

  • x: 1D input of shape (L,)
  • conv_w: kernel of shape (K,)
  • conv_b: scalar bias
  • fc_w: FC weight (scalar)
  • fc_b: FC bias (scalar)

Output: A scalar prediction.

Hints

cnn convolution max-pooling fully-connected
Detecting runtime...