Neural network architecture is not a data-science detail but an engineering decision: each architecture encodes assumptions (inductive biases) about your data's structure, and mismatching them wastes compute and underperforms regardless of tuning.
Overview
- An inductive bias is a built-in assumption about what patterns exist in the data - CNNs assume spatial locality/translation invariance, RNNs assume sequential/temporal dependency, and MLPs (plain ANNs) assume almost nothing, making them general but data-inefficient.
- All three architectures are composable modules, not competing end-to-end solutions - a Transformer's feed-forward layer is an MLP, a CNN's classification head is an MLP, and real systems often combine a CNN backbone with an RNN for temporal modeling.
- Each architecture has a signature engineering fix for its core weakness: MLPs need regularization to control overfitting from their unconstrained capacity, deep CNNs need residual connections to keep gradients flowing, and RNNs need gating (LSTM/GRU) to prevent vanishing gradients over long sequences.
- Architecture selection should start simple (the least complex model that could plausibly work) and add complexity only when justified by measured underperformance.
Key Concepts
Artificial Neural Networks (ANNs / MLPs)
- Feed-forward, acyclic stack of layers; each neuron computes
y = f(Wx + b)- the activation functionfis what prevents stacked layers from collapsing into a single linear function. - Common activations: ReLU (hidden layers, cheap and resists vanishing gradients), sigmoid (binary output), softmax (multi-class output).
- The Universal Approximation Theorem (Cybenko 1989; Hornik 1991) guarantees a wide-enough single hidden layer can approximate any continuous function on a compact domain - but says nothing about parameter count or learning efficiency needed to get there.
- Best suited to fixed-size, heterogeneous tabular data with no inherent spatial/temporal structure; also the universal building block inside every other architecture (Transformer FFN sublayers, CNN classification heads).
- Production pattern: batch norm + dropout + gradient clipping +
AdamW(correct weight decay handling vs. plainAdam) are standard, not optional, for stable training.
Convolutional Neural Networks (CNNs)
- Core assumption: the same feature (e.g., an edge) can appear anywhere in a grid, so a kernel's learned weights are shared across every spatial location (translation invariance) - this weight sharing is the source of CNNs' parameter efficiency versus a fully connected layer.
- Layers stack hierarchically: early layers learn low-level features (edges, textures), deeper layers combine them into higher-level abstractions (shapes, objects).
- Pooling (max/average) reduces spatial dimensions and adds translation invariance; Batch Normalization (Ioffe & Szegedy, 2015) stabilizes training and reduces learning-rate sensitivity; residual connections (He et al., 2016) let gradients skip through blocks directly, making 50-152+ layer networks trainable.
AdaptiveAvgPool2d((1,1))at the end of a backbone makes the model input-resolution agnostic - critical for production pipelines handling variable image sizes.- Model choice (ResNet-18 vs. ResNet-50 vs. EfficientNet vs. MobileNetV3) is typically driven by the latency-accuracy trade-off, not accuracy alone.
Recurrent Neural Networks (RNNs)
- Core mechanism: a hidden state
h_t = tanh(W_hh-h_{t-1} + W_xh-x_t + b)updated at each time step, giving the network a form of memory across sequence positions. - Backpropagation Through Time (BPTT) causes vanishing gradients (weight eigenvalues < 1) or exploding gradients (eigenvalues > 1) over many steps, so vanilla RNNs can't learn dependencies beyond roughly 10-20 steps.
- LSTM (Hochreiter & Schmidhuber, 1997) fixes this with a separate cell state updated additively, controlled by forget/input/output gates - gradients flow through the cell state largely unimpeded.
- GRU (Cho et al., 2014) merges cell and hidden state into one vector with just two gates (reset, update) - fewer parameters, faster training, comparable performance; a reasonable default when training time/size is constrained.
- Production pattern:
pack_padded_sequence/pad_packed_sequencein PyTorch prevents the LSTM from processing padding tokens, which would otherwise contaminate the final hidden state - this is a commonly missed but non-optional detail.
Trade-offs / Caveats
- ANNs: high overfitting risk on tabular data due to unconstrained capacity, especially with many features and few samples - requires disciplined regularization (dropout, weight decay, early stopping). Also heavily dependent on hand-engineered features (log transforms, categorical encoding); raw features often underperform.
- CNNs: highly sensitive to input normalization - training/inference preprocessing mismatch is a common, hard-to-debug accuracy killer. Fine-tuning pretrained backbones with a single learning rate (instead of discriminative, lower rates for pretrained layers) can corrupt useful pretrained representations before the new head adapts.
- RNNs: the fixed-size hidden state is a bottleneck - long sequences (beyond a few hundred tokens) lose fine-grained early context even with gating. Sequential dependency between time steps blocks parallelization, increasing training time and inference latency versus CNNs/Transformers. For new sequence-modeling work, Transformers or state-space models (e.g., Mamba) are generally stronger defaults; RNNs remain relevant mainly for legacy systems and resource-constrained settings where quadratic attention cost is prohibitive.
- Pretrained models generally: distribution shift between pretraining data and production data can silently degrade transferred representations - requires ongoing drift monitoring, not a one-time fine-tune.
Example in Practice
A video-understanding system illustrates composability: a CNN backbone (e.g., a ResNet-style feature extractor with residual blocks and adaptive pooling) extracts a fixed-size feature vector per frame, and a bidirectional LSTM consumes the sequence of per-frame features to model temporal dynamics across the clip, with pack_padded_sequence handling variable-length clips. The final classification head is itself an MLP. This mirrors the post's broader point: the three architectures are rarely deployed as isolated solutions but as composable stages, each handling the part of the problem its inductive bias is suited for.
Related topics
- Attention mechanisms and Transformers as a successor to RNN-based sequence modeling
- Transfer learning and discriminative learning rates for fine-tuning pretrained models
- Training/inference observability practices (gradient norm tracking, data pipeline validation, latency percentile monitoring)
- Data drift detection tooling (e.g., Evidently AI, WhyLabs) for monitoring pretrained model degradation in production