AiTechWorlds
AiTechWorlds
University learning companion
Machine Learning · Deep Learning Applications: When to Use It and When Not To
Use this course-level map to place “Deep Learning Applications: When to Use It and When Not To” in the larger system. It complements—not replaces—a topic-specific worked diagram.
A hydraulic press can crush a car in seconds. It is one of the most powerful machines ever built. But if you need to drive a nail into wood, a hydraulic press is the wrong tool. You reach for a hammer.
Deep learning is the hydraulic press of machine learning. It achieves superhuman performance on image recognition, speech transcription, language translation, and protein folding. But apply it to a dataset of 500 rows with 10 tabular features, and a gradient boosted tree trained in two seconds will likely outperform a deep network trained for hours.
Knowing when to reach for deep learning and when not to separates effective practitioners from those chasing complexity.
Deep learning excels in one specific scenario: unstructured data at scale.
Images and Video: Raw pixel values are meaningless to traditional ML. Deep learning, specifically CNNs, learn to interpret spatial relationships automatically. At scale (>10,000 labeled images), deep learning far outpaces any hand engineered approach. Applications: medical imaging, quality control, autonomous vehicles, satellite analysis.
Text and Language: Sequences of words carry contextual meaning that classical bag of words approaches miss. Transformer models (BERT, GPT) learn rich contextual representations. Applications: sentiment analysis, question answering, translation, summarization, code generation.
Audio and Speech: Spectrograms of sound are spatial patterns in time amenable to CNN like treatment. Recurrent and transformer architectures handle temporal dependencies. Applications: speech recognition, speaker identification, music generation, environmental sound classification.
Large Datasets: Deep learning's performance scales with data in a way that traditional ML does not. Give a random forest 10 million examples and it barely improves past 100,000. Give a neural network 10 million examples and it keeps getting better.
Tabular data with limited samples: For structured tables (customer records, sensor readings, financial transactions) with fewer than ~100,000 rows, gradient boosted trees (XGBoost, LightGBM) consistently outperform neural networks. This has been validated repeatedly in Kaggle competitions: the top tabular data solutions almost never use deep learning.
Interpretability required: A logistic regression model explains exactly why it made a prediction you can read the coefficients. A 50-layer neural network cannot. Healthcare, finance, legal, and regulatory contexts often demand explainability that deep learning cannot easily provide.
Small teams and limited compute: Deep learning requires GPU hardware, large datasets, and considerable engineering effort. A well tuned XGBoost model on a laptop can solve many real business problems that deep learning would take ten times longer to build and deploy.
Fast iteration required: Training a deep model takes hours. Training a random forest takes seconds. When you need to rapidly test ideas and iterate, traditional ML is far more efficient.
| Framework | Primary Language | Best For | Key Strength |
|---|---|---|---|
| TensorFlow 2 + Keras | Python | Production deployment, mobile, web | TensorFlow Serving, TFLite, TF.js |
| PyTorch | Python | Research, custom architectures | Dynamic graph, pythonic, most popular in research |
| Keras (standalone) | Python | Beginners, fast prototyping | Simple API, readable code |
| JAX | Python | High performance research | XLA compilation, functional style, excellent for custom math |
| ONNX Runtime | Multi language | Cross framework inference | Model portability between frameworks |
For production systems: TensorFlow. For research and custom work: PyTorch. For learning and prototyping: Keras. These distinctions are shrinking as frameworks converge.
Training a large model from scratch requires millions of labeled examples and weeks of GPU time. Most projects do not have that. Pretrained models let you start from a powerful foundation.
BERT (Bidirectional Encoder Representations from Transformers, Google 2018): Pretrained on 3.3 billion words, understands context in both directions. Fine tune on your text classification, named entity recognition, or question answering task with as few as a few hundred labeled examples. Available in many sizes: BERT base (110M params), BERT large (340M params), DistilBERT (66M, 97% of BERT performance, twice as fast).
ResNet (Residual Networks, He et al. 2015): Deep CNNs with skip connections that solve the vanishing gradient problem in very deep networks. ResNet-50 (50 layers) achieves 76% top-1 accuracy on ImageNet. ResNet-152 achieves 78%. Use as a feature extractor or fine tune on your image classification task.
EfficientNet: Scales CNNs by depth, width, and resolution simultaneously using a compound scaling method. EfficientNet B7 achieves 84% top-1 on ImageNet with 66M parameters more accurate than ResNet-152 (60M params) while being similarly sized.
GPT (Generative Pre trained Transformer, OpenAI): Causal language model trained on vast text corpora. GPT-2 is open and freely usable. GPT-3/4 are accessed via API. Fine tune GPT-2 on your domain text for specialized generation tasks.
Training from scratch: Initialize random weights, train the entire network on your data. Requires large datasets and long training times. Only justified when your domain is fundamentally different from any available pretrained model (e.g., medical imaging with highly specialized modalities).
Feature extraction (frozen backbone): Load pretrained weights, freeze all layers, add a new classification head on top, train only the head. Fast (minutes), works with small datasets, low risk of overfitting. Start here.
Full fine tuning: Load pretrained weights, unfreeze all layers (or the top several), train the entire network on your data with a very small learning rate (1e-5 instead of 1e-3). The pretrained weights give you a massive head start; the small learning rate prevents destroying them. Use when you have moderate data (1,000–100,000 examples) and need the best accuracy.
from tensorflow.keras.applications import ResNet50
from tensorflow.keras import layers, Model
import tensorflow as tf
# Load ResNet50 pretrained on ImageNet, without the top classification layer
base_model = ResNet50(weights='imagenet', include_top=False, input_shape=(224, 224, 3))
# --- Phase 1: Feature extraction (frozen backbone) ---
base_model.trainable = False
inputs = tf.keras.Input(shape=(224, 224, 3))
x = base_model(inputs, training=False)
x = layers.GlobalAveragePooling2D()(x)
x = layers.Dropout(0.3)(x)
outputs = layers.Dense(5, activation='softmax')(x) # 5-class problem
model = Model(inputs, outputs)
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
print(f"Trainable params (phase 1): {sum([tf.size(w).numpy() for w in model.trainable_weights]):,}")
# Output: Trainable params (phase 1): 10,245 (only the new head)
# Train phase 1 (fast — only 10K params)
# model.fit(train_dataset, epochs=5, ...)
# --- Phase 2: Fine-tuning (unfreeze top layers) ---
base_model.trainable = True
# Freeze early layers, only fine-tune the last 30 layers
for layer in base_model.layers[:-30]:
layer.trainable = False
model.compile(optimizer=tf.keras.optimizers.Adam(1e-5), # Very small LR
loss='categorical_crossentropy', metrics=['accuracy'])
print(f"Trainable params (phase 2): {sum([tf.size(w).numpy() for w in model.trainable_weights]):,}")
# Output: Trainable params (phase 2): 14,930,181 (top 30 layers + head)
# Fine-tune phase 2 (slower, higher accuracy)
# model.fit(train_dataset, epochs=10, ...)Batch Normalization: Normalize layer activations during training. Stabilizes training, allows higher learning rates, reduces sensitivity to initialization. Add after conv layers and before activation functions.
Dropout: Randomly set a fraction of neuron activations to zero during training. Forces the network to learn redundant representations. Prevents overfitting. Typical values: 0.3–0.5 for fully connected layers, 0.1–0.2 for conv layers.
Learning Rate Scheduling: Start with a moderate learning rate and reduce it as training progresses. Common schedules: cosine annealing, reduce on plateau, warmup then decay. A well chosen schedule often matters more than the specific optimizer.
Early Stopping: Monitor validation loss. Stop training when it stops improving (or starts increasing). Prevents overfitting without you having to guess the number of epochs.
Data Augmentation: Artificially expand your training set by applying random transformations (flips, rotations, crops, color jitter) to images. Dramatically reduces overfitting when data is limited.
| Use Case | Recommended Approach | Framework | Notes |
|---|---|---|---|
| Tabular data (<100k rows) | XGBoost / LightGBM | scikit learn / xgboost | Almost always best |
| Image classification (few images) | Fine tune ResNet/EfficientNet | TensorFlow or PyTorch | Use ImageNet weights |
| Image classification (many images) | Full fine tuning or train from scratch | PyTorch | GPU required |
| Text sentiment / classification | DistilBERT fine tuning | HuggingFace Transformers | 97% of BERT at 2x speed |
| Text generation | GPT-2 fine tuning or GPT-4 API | HuggingFace / OpenAI API | Depends on use case |
| Time series forecasting | LightGBM with lag features | Any | Beat LSTM on most benchmarks |
| Audio classification | CNN on mel spectrograms | PyTorch | Treat like image classification |
| Real time inference (<10ms) | Quantized model + ONNX | ONNX Runtime | Model compression required |
University learning companion
Machine Learning · Deep Learning Applications: When to Use It and When Not To
Complete the steps without looking at the answer first; record evidence rather than only a final result.
These are primary or established learning references for this subject. Check the relevant chapter or specification for the exact topic and version.
Get this course's notes on Telegram!
Free cheat sheets, summaries & practice exercises