AI classroom activity: Machine learning

In my first Teacher article, I discussed the importance of teaching artificial intelligence (AI) to schoolchildren. Based on my experience, the key to demystifying AI is to emphasise that in almost all real-world situations AI is nothing more than imitation of human-like behaviours.

Last week, we looked at an unplugged activity that illustrated how we could build a simple program to perform facial recognition. In this article, I will discuss how to build an AI system that can exhibit another behaviour that is often associated with human intelligence: learning.

Humans have a superb natural ability to learn from experience. Everyone who has taken care of a child can tell you the sense of amazement observing a toddler taking their first step walking and saying their first word. Babies do not learn these skills overnight, they learn from repeatedly trying the same action, failing, and readjusting their actions. This process of trial-and-error is the at the heart of human learning and machine learning.

In collaboration with Matthew Scadding from the Ravenswood School for Girls in Sydney, I have developed a two-week computer programming activity to teach the concept of machine learning to their Year 6 robotic classes. We used the Lego Mindstorms EV3 kit to build the program. The concept should be general enough so that this activity can be carried out using different programming languages.

The number guessing game

In the first week, we asked the students to build a computer program so that their robot could play a number guessing game. The game is as follows: the (human) player comes up with a whole number between 1 and 100 in their mind. The robot will repeatedly make a guess, say 26; after every guess, the human player provides feedback to the robot saying whether its guess was correct (=26), too small (>26) or too large (<26). The robot aims to guess the correct number in the smallest number of guesses.

Before the activity: I asked the class to brainstorm some strategies to make the robot guess the correct number as fast as possible. After a few minutes of discussion with the class, I asked them to compare three game strategies.

  1. Randomly pick a number between 1 and 100 every time, regardless of the previous attempts and human feedback;
  2. Systematically guess 1, 2, 3, … until the correct answer is reached;
  3. At the end of the iteration, use the feedback from the human to restrict the range of values to pick from. For example, if the first guess is 80 and the human feedback indicate this guess was too large, the robot will only select a number between 1 and 79 in the next round.

Key concept: Most students in my class could see that the third strategy was the best. It was the best strategy because every new guess uses the feedback from the previous rounds to narrow down the solution search space. The first two strategies do not use human feedback in any meaningful way, so are very inefficient. The third strategy is said to be able to learn from previous mistakes and progressively adjust its guesses. This is the essence of learning by trial-and-error.

A prerequisite of this activity is that students need to have basic computer coding skills, including the knowledge of variables, loops, if-else statements, reading input from a sensor or keyboard, and printing text on screen. I have converted my code into computer pseudocode so it can be easily used for teachers who teach computer coding in different languages (Figure 1).

School support for refugee students

[Figure 1 : Computer pseudocode for the number guessing game. Variable names are highlighted in red.]

At the end of the activity, I explained to the students that this number guessing program was actually learning as the game progressed. This was a process of learning by trial-and-error. They had just built a simple machine learning program!

Building a self-learning lawn bowling robot

In the second week, we asked the students to build a lawn bowling robot which can learn from past experience. Lawn bowling is a suitable activity because this game is all about accuracy. To bowl a perfect ball, the robot needs to use the right among of force, so that it won't go too far or not far enough.

Before the activity: I first explained the game of lawn bowling to the class. I then pointed out that the process of finding the right amount of bowling force is exactly the same as the number guessing game; it is a process of trial-and-error. Initially a certain amount of force is randomly chosen and tried, and based on the human feedback regarding whether the bowl was too strong or weak, the robot can adjust the force it uses the next time.

The activity: In the class, the largest amount of time was spent on physically building the robotic arm that was used to release the bowl (see Figure 2). I then asked the students to copy the code from the number guessing game, and replaced “PRINT ‘is it myGuess?'” with ‘MOVE the robotic arm with force = myGuess'. The rest of the code can mostly be reused.

School support for refugee students

[Figure 2: A lawn bowling robot that is programmed to learn from past experience.]

To make the lesson more fun, I turned this activity into a lawn bowling robot competition. Students were grouped into teams of two or three. They could modify the design of the robotic arm or the computer code to make their robot bowl better or learn faster. Once their robots were built, I gave all of them about five minutes to ‘train' their robots. After the training period, they competed in a simple lawn bowling competition – each team can bowl once, and the team whose ball was closest to the target won. Our students had a lot of fun.

Introducing your own activities

I hope the number guessing game and the lawn bowling robot activity serve as good examples to inspire you to come up with new and innovative ways to introduce the concept of AI in your class.

It is my belief that demystifying AI is the key to preparing our schoolchildren to be creative and bold when it comes to using new computer technology.

In what ways is your school engaging students in STEM subjects?

Dr Joshua Ho is working with educators as part of the CSIRO’s STEM professionals in schools program. Think about a STEM-related topic you’re teaching next term. How could you develop links to tap into external expertise?