Courses / Computer Science XII (HSSC-II) – FBISE Complete SLO-Based Course
5.2 Neural Networks and Deep Learning
Unit 5 – Application of Computer Science · 80 min read · 8 MCQs to check yourself
3Blue1Brown – but what is a neural network?
1. Artificial neural networks (ANN)
An artificial neuron takes inputs, multiplies each by a weight, adds a bias, and passes the total through an activation function (e.g. ReLU or sigmoid) to produce an output.
y = f(w₁x₁ + w₂x₂ + … + wₙxₙ + b)
A neural network connects many neurons in layers: an input layer (features), one or more hidden layers, and an output layer (prediction).
How it learns (training): the network makes a prediction, a loss function measures the error, and backpropagation with gradient descent adjusts all weights a little to reduce the error. This repeats over many examples (epochs) until predictions are good.
# one neuron deciding "admit to the merit list?" from two features
def neuron(marks, interview, w1=0.7, w2=0.3, bias=-66):
total = w1 * marks + w2 * interview + bias
return 1 if total > 0 else 0 # step activation
for m, i in [(85, 70), (70, 40), (60, 90)]:
print(m, i, "->", "admit" if neuron(m, i) else "reject")
Output:
85 70 -> admit
70 40 -> reject
60 90 -> admit
2. Deep learning
Deep learning is machine learning with neural networks that have many hidden layers (“deep”). So every deep learning network is a neural network, but not every neural network is deep – a network with one hidden layer is “shallow”.
The big idea: deep networks learn the features themselves from raw data. Early layers detect simple patterns; later layers combine them into complex ones.
| Traditional machine learning | Deep learning | |
|---|---|---|
| Features | Hand-engineered by people | Learned automatically from raw data |
| Data needed | Works with small/medium data | Needs large amounts of data |
| Hardware | Normal CPU | Usually GPUs/TPUs |
| Interpretability | Often easier to explain | Often a “black box” |
| Best for | Tables of numbers | Images, speech, text, video |
Types: CNNs (convolutional) for images and video; RNNs/LSTMs for sequences; Transformers for language (ChatGPT, Claude, Google Translate).
3. Applications
- Healthcare: detecting tuberculosis or cancer in X-rays and scans; diabetic-eye screening.
- Agriculture: identifying crop diseases from leaf photos on a phone.
- Speech and language: voice assistants, Urdu speech-to-text, translation, chatbots.
- Transport: self-driving cars detecting pedestrians and signs.
- Security: face recognition, fraud detection.
- Creative tools: image generation, photo enhancement, music.
4. Improving a deep learning model
More labelled data (and data augmentation – rotating/flipping images) · more hidden layers or neurons when underfitting · dropout/regularisation when overfitting · tuning the learning rate, batch size and epochs · transfer learning (start from a model pre-trained on millions of images) · better-quality labels.
Short and long questions
1. Give three applications of neural networks and deep learning.
Model answer
- Medical imaging – detecting TB, cancer or diabetic-eye disease from scans.
- Speech and language – voice assistants, Urdu speech-to-text, translation, chatbots.
- Agriculture / transport – crop-disease detection from leaf photos; self-driving cars recognising pedestrians. (Also face recognition, fraud detection.)
2. Describe deep learning and its applications. Explain the structure of a neural network (input, hidden and output layers, weights, activation), how it learns, and two ways to improve a model that classifies chest X-rays. (1 + 3 + 2)
Model answer
Deep learning (1): machine learning using neural networks with many hidden layers that learn features automatically from large raw datasets; applications include medical imaging, speech recognition, translation, self-driving cars and crop-disease detection.
Structure and learning (3):
- Input layer receives features (pixel values of the X-ray). Hidden layers contain neurons; each neuron computes a weighted sum of its inputs plus a bias and applies an activation function (ReLU/sigmoid). Output layer gives the prediction (e.g. probability of pneumonia).
- Weights decide how strongly each input affects a neuron.
- Learning: the network predicts, a loss function measures the error against the correct label, and backpropagation + gradient descent adjust the weights to reduce the error; this repeats for many epochs over thousands of labelled X-rays.
Improvements (2): (1) more labelled X-rays and data augmentation (rotations, brightness changes); (2) tuning: more hidden layers/neurons if underfitting, dropout if overfitting, learning-rate tuning; or transfer learning from a network pre-trained on millions of images.
3. How do deep learning networks help us extract features from a dataset? Give an example.
Model answer
Each layer transforms the output of the previous layer: early layers detect simple patterns, deeper layers combine them into complex features – so the network learns useful features automatically, without humans designing them. Example: in face recognition, layer 1 finds edges, later layers find eyes and noses, and the final layers recognise whole faces.
4. Explain the relationship between neural networks and deep learning networks.
Model answer
A neural network is a set of connected artificial neurons arranged in input, hidden and output layers. A deep learning network is a neural network with many hidden layers. So deep learning is a subset of neural networks: all deep networks are neural networks, but a network with only one hidden layer is a shallow (not deep) neural network.
5. What is deep learning and how is it different from traditional machine learning? (1.5 + 1.5)
Model answer
Deep learning is a type of machine learning that uses neural networks with many hidden layers to learn complex patterns from large amounts of raw data (images, speech, text). Difference: traditional ML usually needs hand-engineered features and works well on small, structured data; deep learning learns features automatically, needs much more data and computing power (GPUs), and is harder to interpret.
This lesson ends with a quiz of 8 MCQs. Open the lesson on PrepOasis to take it and save your progress.
Previous: 5.1 IoT, Cloud Computing and Blockchain: Designing Applications for Pakistan · Next: 5.3 Policies that Protect Stakeholders’ Interests
All lessons in Computer Science XII (HSSC-II) – FBISE Complete SLO-Based Course