← Course Home Module 5 · Convolutional Neural Networks
Module 5 · Core Architectures

Convolutional Neural Networks

A CNN is a network built around one idea: slide a small pattern detector across the input and note where it fires. That single idea powers Paper 1's DNA motif detection (Conv1D), the tactile baselines Paper 2 competes against (Conv2D), and the Grad-CAM explanations both fields rely on.

▶
Audio recap
A ~2-minute spoken summary of this module — great for revision on the go.

5.1 The idea: sliding pattern detectors

A dense layer (Module 3) connects every input to every output — for a 101×4 DNA window that means thousands of independent weights, and a pattern learned at position 12 tells the network nothing about the same pattern at position 80. Convolution fixes both problems.

A filter (or kernel) is a small weight vector — say 3 positions long. You slide it along the input, and at each position compute a dot product between the filter and the input chunk under it. From Module 1, a dot product measures similarity: so each output value answers "how much does this spot look like my pattern?" The sequence of answers, one per position, is the activation map (or feature map).

Two consequences of using the same filter at every position (weight sharing):

Why you care "Why a CNN and not a plain dense network?" is a near-certain oral question. The two-word answers are weight sharing (efficiency) and translation invariance (a motif matters wherever it appears) — then give the DNA example.

5.2 Conv1D on DNA, concretely

Take a toy one-hot sequence and a toy length-3 filter that "looks for" the pattern TAA (large weights on T, then A, then A). Slide it:

Input: G T A A C → filter at pos 1: sees GTA → low score → pos 2: sees TAA → HIGH score → pos 3: sees AAC → low score → activation map (0.1, 2.9, 0.3)

A length-5 input with a length-3 filter yields 5 − 3 + 1 = 3 output positions. In general, Paper 1's Equation 1 (simplified notation) says exactly this:

ct(k) = σ( Σi wk,i · yt+i + bk ),   t = 1 … L − f + 1Paper 1, Eq. 1

Read it aloud: the activation of filter k at position t is a nonlinearity σ (ReLU) applied to the dot product of the filter's weights wk with the one-hot input y starting at position t, plus a bias. For input length L and filter size f, there are L − f + 1 valid positions — e.g. L = 101, f = 7 gives 95 outputs.

Each filter is a learnable motif detector: gradient descent shapes its weights until it fires on whatever short subsequence helps classification. Using K filters in parallel gives K different motif detectors, producing K activation maps.

Paper 1: multiscale Conv1D Biological motifs come in different lengths, so a single filter size is a bet. Paper 1 hedges with multiscale convolutions: parallel banks of Conv1D filters with different sizes, so short motifs and longer motifs are both caught in a single layer. Their outputs are combined before moving on to pooling and the BiLSTM.

5.3 Pooling: "was the motif there at all?"

After convolution we have, per filter, an activation value at every position — often more detail than we need. Max pooling keeps only the strongest activation per filter (or per local region). Paper 1's Equation 2 is global max pooling in one symbol:

p(k) = maxt ct(k)Paper 1, Eq. 2

Why do this?

The trade-off: pooling discards precise location. "Motif present" survives; "motif at position 37" does not. When exact position matters, the architecture must recover it elsewhere — one reason Paper 1 also runs a BiLSTM over the sequence (Module 6).

5.4 Stacking layers & going 2-D

Stack conv layers and a hierarchy emerges: early filters detect simple, tiny patterns (in images: edges and color blobs; in DNA: short motifs), and deeper layers combine those detections into larger, more abstract structures (textures, object parts; composite regulatory patterns). Each layer's "pixels" are the previous layer's pattern-detections.

Conv2D is the same machinery for images: a small square filter (say 3×3, spanning all C channels) slides across the H×W grid in both directions, producing a 2-D activation map per filter. Everything else — weight sharing, translation invariance, pooling, stacking — carries over unchanged.

Where Paper 2 meets CNNs Recognizing material from a tactile image is classically a texture recognition task, and CNNs excel at texture. Paper 2's baselines and much earlier tactile work use CNN architectures (e.g. ConvNeXt) on gel-deformation images. Paper 2's own student is a Vision Transformer (Module 7) — but you must know the CNN approach it is measured against.

5.5 What CNNs are good and bad at

The cliffhanger This weakness motivates both papers' next moves. Paper 1 pairs its CNN with a BiLSTM that reads the whole window in both directions and carries context across all 101 positions (Module 6). Paper 2 replaces convolution entirely with a Transformer, whose attention connects every patch to every other patch in one step (Module 7). Same disease, two cures.

5.6 Seeing what a CNN sees: Grad-CAM

A trained CNN is a black box: it says "aluminum, 97%" but not why. Grad-CAM (gradient-weighted class activation mapping) opens the box. The recipe: take the class score (e.g. the "aluminum" logit), compute its gradients flowing back into the last convolutional layer's activation maps, use those gradients to weight how much each map mattered for that class, and combine the weighted maps into a heatmap over the input showing which regions drove the decision. Intuition: "if nudging this region's activations would change the class score a lot, that region mattered."

Paper 2's Grad-CAM evidence Paper 2 uses Grad-CAM to compare its language-distilled model against the baseline. The distilled model's heatmaps concentrate on localized, material-relevant structures — edges and texture variations for wood, specular (shiny highlight) regions for aluminum — while the baseline's heatmaps activate on broad, noisy regions with no material meaning. This is qualitative evidence that language supervision taught the student not just what to answer but where to look. Paper 1 plays the analogous explainability game on DNA with motif-level maps and SHAP (Module 9).
Exam warm-up — say it out loud
  1. Explain weight sharing and why it gives translation invariance, using a DNA motif as the example.
  2. An input of length 101 meets a filter of size 7 — how many output positions, and why?
  3. What does max pooling buy you, and what does it cost you?
  4. In one minute: how does Grad-CAM produce a heatmap, and what did it reveal in Paper 2?

Module 5 Quiz

10 questions. Conv1D and pooling are Paper 1's Eqs. 1–2 — examiners quote them.

← Previous
Module 4: Data — Sequences, Images & Imbalance