Grades 9-12 CS + Math 120 Minutes

Lesson 4: Introduction to Neural Networks

Explore how artificial neural networks mimic the human brain to recognize patterns and make predictions, with hands-on coding activities and visual demonstrations.

Learning Objectives

  • Understand the biological inspiration for artificial neural networks and how they mimic neuron structure and function
  • Explain the architecture of neural networks including input layers, hidden layers, output layers, weights, and biases
  • Implement a simple neural network using Python to solve a classification problem
  • Analyze how training works through forward propagation, loss calculation, and backpropagation

Standards Alignment

  • CSTA 3B-AP-08: Describe how artificial intelligence drives many software and physical systems
  • CSTA 3B-AP-16: Demonstrate code reuse by creating programming solutions using libraries and APIs
  • Common Core Math HSF-IF.C.7: Graph functions expressed symbolically and show key features of the graph
  • NGSS HS-LS1-2: Develop and use a model to illustrate the hierarchical organization of interacting systems

Materials Needed

  • Computer with Python 3.x installed (one per student or pair)
  • Jupyter Notebook or Google Colab access
  • Required libraries: NumPy, Matplotlib, scikit-learn (installation guide provided)
  • Neuron diagram handout (biological vs. artificial comparison)
  • Network architecture visualization poster
  • Dataset: Iris flowers or MNIST digits (included in starter code)
  • Projector for live coding demonstrations

Lesson Procedure

  1. Hook - The Pattern Recognition Challenge (10 minutes)

    Present students with pattern recognition tasks that humans do effortlessly but were historically difficult for computers:

    • Recognize handwritten digits with varied styles
    • Identify objects in cluttered images
    • Distinguish between cat and dog photos

    Discussion: "How does your brain know this is a '7' even though everyone writes it differently? Today we'll learn how to build artificial systems that can learn patterns like your brain does."

  2. Biological Inspiration - From Brain to Code (20 minutes)

    Part 1: Biological Neurons

    • Structure: dendrites (receive signals), cell body (processes), axon (transmits)
    • Function: electrical signals, threshold activation, network connections
    • Learning: synaptic plasticity, strengthening/weakening connections

    Part 2: Artificial Neurons (Perceptrons)

    • Inputs (like dendrites) with weights (connection strength)
    • Weighted sum + bias (like cell body processing)
    • Activation function (threshold, like firing/not firing)
    • Output (like axon transmission)

    Mathematical Model: output = activation(Σ(input × weight) + bias)

    Use the comparison handout to show side-by-side diagrams. Emphasize: Neural networks are inspired by biology but work quite differently!

  3. Network Architecture Exploration (15 minutes)

    Layer Types:

    • Input Layer: Receives raw data (pixels, features, etc.)
    • Hidden Layers: Extract increasingly complex patterns
    • Output Layer: Produces final prediction or classification

    Key Concepts:

    • Weights: Strength of connections between neurons, learned during training
    • Biases: Threshold adjustments for each neuron
    • Activation Functions: ReLU, Sigmoid, Tanh - introduce non-linearity
    • Deep Learning: Networks with multiple hidden layers

    Draw network diagrams on board showing information flow. Use interactive visualization tools if available (TensorFlow Playground).

  4. Hands-On Coding - Build Your First Network (45 minutes)

    Guided Coding Exercise: Create a neural network to classify iris flowers

    Step 1: Setup and Data Loading

    • Import libraries: NumPy, scikit-learn
    • Load Iris dataset
    • Explore data: features, labels, dimensions
    • Split into training and testing sets

    Step 2: Build the Network

    • Define network architecture: input size, hidden layers, output size
    • Initialize weights and biases randomly
    • Implement activation function (ReLU, Sigmoid)
    • Code forward propagation

    Step 3: Training Process

    • Define loss function (cross-entropy)
    • Implement gradient descent
    • Code backpropagation (or use built-in library)
    • Train for multiple epochs, track loss

    Step 4: Evaluation and Visualization

    • Test on held-out data
    • Calculate accuracy
    • Plot training loss over time
    • Visualize decision boundaries

    Teaching Strategy: Code together, explaining each section. Pause for questions. Students type along. Checkpoint: ensure everyone's code runs before moving forward.

  5. Experimentation and Analysis (20 minutes)

    Students modify their neural networks to explore how architecture affects performance:

    Experiments to Try:

    • Change number of hidden layers (1 vs. 2 vs. 3)
    • Adjust neurons per layer (10 vs. 50 vs. 100)
    • Try different activation functions
    • Modify learning rate
    • Increase/decrease training epochs

    Analysis Questions:

    • How does network depth affect accuracy?
    • What happens with too few or too many neurons?
    • Can you identify overfitting or underfitting?
    • What is the training time tradeoff?

    Students record observations in lab notebook format. Share interesting findings with class.

  6. Reflection and Real-World Applications (10 minutes)

    Discussion: "Now that you understand how neural networks work, where do you see them in the real world?"

    Applications to Explore:

    • Image recognition (medical diagnosis, facial recognition, autonomous vehicles)
    • Natural language processing (translation, chatbots, voice assistants)
    • Recommendation systems (Netflix, Spotify, Amazon)
    • Game playing (chess, Go, video games)
    • Scientific research (protein folding, climate modeling)

    Exit Ticket: "Explain in your own words how a neural network learns. What surprised you most about how they work?"

Assessment Strategies

Formative Assessment

  • Code functionality checks at each step
  • Verbal explanations of concepts during coding
  • Quality of experimentation and documentation
  • Participation in discussions
  • Troubleshooting approach when encountering errors

Summative Assessment

  • Working neural network code with documentation
  • Experimental results report with analysis
  • Written explanation of network architecture and learning
  • Optional: Apply network to new dataset (MNIST digits)
  • Quiz on neural network concepts and mathematics

Success Criteria

Students demonstrate mastery when they can:

  • Explain biological inspiration for neural networks
  • Describe network architecture components
  • Code a functional neural network from scratch
  • Interpret training loss and accuracy metrics
  • Analyze effects of hyperparameter changes
  • Connect concepts to real-world applications

Differentiation Strategies

For Advanced Learners:

  • Implement backpropagation from scratch without libraries
  • Explore convolutional neural networks for image classification
  • Research and present on advanced architectures (ResNet, Transformers)
  • Optimize network using advanced techniques (dropout, batch normalization)
  • Work with larger datasets like CIFAR-10

For Students New to Programming:

  • Provide complete starter code with clear comments
  • Use higher-level libraries (Keras/TensorFlow) that abstract complexity
  • Focus on understanding concepts rather than implementation details
  • Pair with experienced programmers
  • Allow use of no-code neural network builders (teachable machine)

For Visual Learners:

  • Use TensorFlow Playground for interactive visualization
  • Emphasize graphing and visualization of results
  • Create flowcharts of the training process
  • Watch animated explanations (3Blue1Brown neural network series)

Extension Activities

Project Ideas:

  • Custom Dataset: Train network on student-collected data (plant species, car models, etc.)
  • Transfer Learning: Use pre-trained networks and fine-tune for specific tasks
  • Comparative Study: Test different ML algorithms, compare to neural networks
  • Real-World Problem: Apply networks to local issue (traffic prediction, energy usage, weather)

Advanced Topics:

  • Recurrent neural networks for sequence data
  • Generative adversarial networks for creating images
  • Reinforcement learning for game agents
  • Neural network interpretability and explainable AI

Interactive Online Tools

These free, browser-based tools help students visualize and experiment with neural networks without any installation:

  • TensorFlow Playground: Interactive visualization of neural network training. Students can adjust layers, neurons, activation functions, and learning rate while watching the network learn in real-time. Perfect for understanding how architecture affects learning.
  • Google Teachable Machine: Train a neural network using your webcam, microphone, or uploaded files. No coding required! Great for students new to programming or as a quick demonstration of image/sound classification.
  • ml5.js: Friendly machine learning library for JavaScript. Students can build neural networks that run directly in web browsers. Excellent for creative coding projects.
  • Google Colab: Free Jupyter notebook environment with GPU access. Students can run Python code in the cloud without any local setup. Perfect for the hands-on coding activities in this lesson.
  • 3Blue1Brown Neural Networks Series: Excellent animated videos explaining the mathematics behind neural networks. Visual learners especially benefit from these clear explanations of backpropagation and gradient descent.

Suggested Workflow:

  1. Start with TensorFlow Playground to build intuition about network structure
  2. Use Teachable Machine for a quick hands-on experience
  3. Progress to Google Colab for the Python coding activities
  4. Assign 3Blue1Brown videos for homework or extra credit

Common Misconceptions to Address

  • "Neural networks work exactly like the brain."

    While inspired by biological neurons, artificial neural networks are a mathematical abstraction. Real brains have billions of neurons with complex chemical signaling, while ANNs use simplified mathematical operations. Help students appreciate the inspiration while understanding the differences.

  • "More layers and neurons always mean better performance."

    Overly complex networks can overfit to training data and generalize poorly. They also require more data and computational resources. The best architecture depends on the problem complexity and available data.

  • "Neural networks understand what they're doing."

    Neural networks recognize patterns but don't have understanding or consciousness. A network trained to classify cats doesn't "know" what a cat is—it has learned statistical patterns in pixel data that correlate with the label "cat."

  • "Once trained, a neural network is fixed forever."

    Networks can be retrained, fine-tuned, and updated. Transfer learning allows networks to adapt their knowledge to new tasks. This is an active area of research called continual learning.

  • "Neural networks always give the right answer."

    Networks make predictions with varying confidence and can be wrong, especially on data different from their training set. Understanding model limitations and confidence levels is crucial for responsible AI use.

  • "You need to understand advanced math to use neural networks."

    While understanding the math deepens comprehension, modern libraries like TensorFlow and PyTorch abstract away much complexity. Students can build functional networks while gradually learning the underlying mathematics.

Real-World Applications Deep Dive

Help students connect classroom learning to real-world impact with these detailed examples:

Healthcare

  • Medical Imaging: Detecting tumors in X-rays and MRIs with accuracy rivaling radiologists
  • Drug Discovery: Predicting molecular interactions to accelerate new medicine development
  • Disease Prediction: Analyzing patient data to identify at-risk individuals before symptoms appear

Transportation

  • Self-Driving Cars: Processing camera and sensor data to navigate safely
  • Traffic Prediction: Google Maps uses neural networks to estimate arrival times
  • Route Optimization: Delivery companies use networks to find efficient paths

Language & Communication

  • Translation: Google Translate and DeepL use neural networks for natural translations
  • Voice Assistants: Siri, Alexa, and Google Assistant understand speech using deep learning
  • Writing Assistance: Grammar checkers and autocomplete use language models

Creative Applications

  • Art Generation: DALL-E and Midjourney create images from text descriptions
  • Music Composition: AI can generate original music in various styles
  • Video Games: NPCs with more realistic, adaptive behavior

Download Lesson Materials

Access all lesson materials including Jupyter notebooks, datasets, diagrams, and assessment tools. Each file can be downloaded individually.