Deep Learning Basics: CNN and RNN Introduction For students.
Deep learning is machine learning with neural networks that have many layers. Depth lets each layer build on the last: early layers detect edges, middle layers shapes, late layers whole objects. Two architectures shaped the field: convolutional neural networks (CNNs) for grid-like data such as images, and recurrent neural networks (RNNs) for sequences like text and speech.
Each architecture matches its data's structure. A CNN reuses one small filter across the whole image, spotting a cat's ear anywhere with far fewer weights than a plain network. An RNN carries a memory (hidden state) from one time step to the next, using earlier words to interpret later ones. This structural match is why deep learning leapt past older methods on vision and language.
Key Concepts
- Convolution: sliding a small filter over the input and computing dot products, producing a feature map.
- Filter (kernel): a small learned weight matrix, e.g., 3 by 3, detecting one pattern like a vertical edge.
- Pooling: downsampling a feature map (max of each 2 by 2 block) for smaller, shift-tolerant maps.
- Feature map: the output grid of one filter applied across the whole input.
- Hidden state: an RNN's memory vector, updated each step from the previous state and the new input.
- Sequence: ordered data like sentences or audio where position matters.
- Vanishing gradient: gradients shrinking over many time steps, blocking long-range learning — the reason LSTMs and transformers were invented.
Formulas
- Convolution output size: output = (n − f + 2p) divided by s, plus 1, where n is input size, f filter size, p padding, s stride. This fixes each feature map's exact size.
- RNN hidden-state update: h_t = tanh(W_hh times h_{t−1} + W_xh times x_t + b). The new memory blends old memory with the current input through learned weights; tanh bounds values to (−1, 1). Real models stack layers and often use LSTM or GRU cells instead.
Worked Example
CNN sizing: a 5 by 5 grayscale image, a 3 by 3 filter, stride 1, no padding. Output = (5 − 3) divided by 1, plus 1 = 3, so the feature map is 3 by 3. Work per position: one 3 by 3 dot product = 9 multiplications; total = 9 positions times 9 = 81 multiplications — far fewer than a fully connected layer's 25 times 9 = 225. RNN step: h_0 = 0, x_1 = 1, W_xh = 0.5, W_hh = 0.8, bias 0. Then h_1 = tanh(0.5). Since e^0.5 is about 1.6487 and e^(−0.5) about 0.6065, tanh(0.5) = 1.0422 divided by 2.2552, about 0.462 — the network carries 0.462 of "memory" into the next word.
Common Misconceptions
- Deep learning is all of AI. It is one branch of machine learning; search, logic, and rule systems solve much else.
- CNNs see like humans. They match texture statistics and can be fooled by pixel changes invisible to us.
- RNNs remember everything. Vanishing gradients limit plain RNNs; LSTMs, GRUs, and transformers were built to fix this.
Real-World Applications
- Image classification: objects, faces, and medical anomalies in scans.
- Speech recognition: audio to text for assistants and captions.
- Machine translation: encoder-decoder models translating between languages.
- Video analysis: combined CNN and RNN pipelines detecting actions across frames.
Deep learning stacks layers so simple patterns compose into complex understanding: CNNs share small filters across images to catch local patterns anywhere, and RNNs carry a hidden state forward through sequences. Concrete arithmetic, not magic — and the foundation on which LSTMs and transformers were built.
Related blogs
- Supervised Learning: Regression and Classification
- Linear and Logistic Regression: Complete Beginner's Guide
- Decision Trees and Random Forests: Complete Beginner's Guide
- Support Vector Machines: Complete Beginner's Guide
- Clustering: K-Means and Hierarchical With easy examples.
- Neural Networks and Backpropagation With easy examples.