# Seeing and remembering: CNNs & RNNs · AI in Bed

Intermediate level · 7 min · https://www.aiinbed.com/learn/intermediate/cnns-and-rnns

*Special network shapes for images and sequences, and why they mattered.*

A plain network treats every input pixel as unrelated. But pixels next to each other belong together, and words in a sentence come in order. Two architectures were built to respect that structure.

*Figure: A 3×3 filter slides across the image, producing a feature map that lights up wherever its pattern (here, a vertical edge) appears.*

### Convolutional Neural Networks (CNNs)

A small **filter** (say 3×3) slides across the image, checking each patch for a pattern like an edge.

The *same* filter is reused everywhere, so a cat ear is recognised wherever it appears and the model needs far fewer weights.

### Feature hierarchy

Stack conv layers with **pooling** (downsizing) in between.

Early layers find edges → then textures → parts (eyes, wheels) → whole objects.

AlexNet's win in the 2012 ImageNet competition kick-started the deep learning boom.

**Quick check:** Why do CNNs reuse the same filter across the whole image?

A. To save memory and detect a pattern wherever it appears
B. Because GPUs can only store one filter
C. To blur the image
D. It's a bug that turned out fine

Answer: A. Weight sharing means far fewer parameters and translation-friendly detection: an edge is an edge anywhere.

### Recurrent Neural Networks (RNNs)

Read a sequence one step at a time, carrying a **hidden state**, a running memory of what came before.

Used for text, speech, and time series before 2017.

### LSTMs: better memory

Plain RNNs forget long-ago inputs (vanishing gradients again).

**LSTMs** add gates that learn what to remember, forget and output, so they hold on to context much longer.

### Why transformers took over

RNNs read word by word, so they can't easily be parallelised and still struggle with long text.

Transformers (Advanced level!) look at every word at once with **attention**. Today they dominate language and are increasingly used for images too (Vision Transformers).

**Quick check:** What does an RNN's hidden state do?

A. Stores the final answer only
B. Carries a summary of earlier steps in the sequence
C. Hides the model from users
D. Holds the test data

Answer: B. The hidden state is the network's running memory, updated at each step of the sequence.

**Key takeaways**

- CNNs slide shared filters over images to detect local patterns.
- Layers build from edges to objects.
- RNNs/LSTMs process sequences with a running memory.
- Transformers replaced RNNs for most language tasks.

**Go deeper (free sources)**

- [CNN Explainer (interactive)](https://poloclub.github.io/cnn-explainer/) by Wang et al., Georgia Tech Polo Club
- [CS231n: Convolutional Neural Networks for Visual Recognition](https://cs231n.github.io/) by Stanford University
- [Understanding LSTM Networks](https://colah.github.io/posts/2015-08-Understanding-LSTMs/) by Christopher Olah
