Rock, Paper, Scissors AI!
About this lesson
Year band: 7-8Curriculum Links Assessment
Links with the Digital Technologies Curriculum Area.
Define and decompose real-world problems taking into account functional requirements and economic, environmental, social, technical and usability constraints (ACTDIP027)
Design algorithms represented diagrammatically and in English, and trace algorithms to predict output for a given input and to identify errors (ACTDIP029)
Implement and modify programs with user interfaces involving branching, iteration and functions in a general-purpose programming language (ACTDIP030)
Evaluate how student solutions and existing information systems meet needs, are innovative, and take account of future risks and sustainability (ACTDIP031)
Years 7 and 8 Achievement Standards
They define and decompose problems in terms of functional requirements and constraints. Students design user experiences and algorithms incorporating branching and iterations, and test, modify and implement digital solutions. They evaluate information systems and their solutions in terms of meeting needs, innovation and sustainability. They analyse and evaluate data from a range of sources to model and create solutions.
Refer to the following artefacts to assess to what extent students covered the assessment criteria listed in the sample rubric.
- Worksheet: Labelling and classifying images (How well have they considered was to address bias?)
- Machine learning model and evaluation of how well it worked.
- Worksheet planning: AI powered rock, paper, scissors game
- Final product: Video capture of game in operation with commentary.
Share the assessment criteria and rubric before commencing the programming project. (This rubric can be modified to suit different contexts chosen by students.)
|Criteria||1 pt||2 pt||3 pt||4 pt|
functional requirements and constraints
a functional requirement is listed
a functional requirement and constraint is listed
most functional requirements are listed and constraints are listed
a detailed list of functional requirements are included together with where they are required
Constraints are listed and elaborated
design user experiences and algorithms
minimal changes have been made to the sample code
a screen sketch is provided
attempts at changing the algorithm to include game play which include adding a variable such as scoring
a basic set of screens is provided
the algorithm has been modified to include elements of game play such as randomising and including variables such as scoring
user design has been considered which may include feedback and explained using well constructed screens
the algorithm has been modified to clearly explain game play and includes functions, variables, randomising, loops and branching.
Detailed screens clearly describe the user experience and how a game is won and lost and how the user is updated on the score.
meeting needs, innovation
the game works for some users but has issues recognising hand gestures correctly.
the game works for many users and recognises hand gestures correctly most times.
an explanation is provided explaining how it meets user needs and is innovative
the game works for most users and accurately recognises hand gestures.
a clear explanation is provided to explain how the game meets users needs and how it is innovation citing relevant examples.
the game works for all users and accurately recognises hand gestures with evidence to back up these claims.
a clear explanation is provided to explain how the game meets users needs, how bias was avoided and and how it is innovation citing relevant examples.
|Artificial intelligence (AI)||The ability of machines to mimic human capabilities in a way that we would consider 'smart'.|
|Machine Learning||An application of AI and a process we give the machine lots of examples of data, demonstrating what we would like it to do so that it can figure out how to achieve a goal on its own. The machine learns and adapts its strategy to achieve this goal.|
|Bias||AI systems are vulnerable to errors introduced by its human creators. These errors are referred to as a bias. Bias can creep into data sets and algorithms in several ways. AI systems learn to make decisions based on training data, which can include biased human decisions. Another source of bias is flawed data sampling, in which groups are over- or underrepresented in the training data.|
- Teachable Machine
- P5 Web Editor
Familiarise yourself with the Teachable machine application. View the supporting videos.
Note: Teachable machine requires an internet connection, Google Chrome on Windows or Macintosh (tablets are not supported) and a webcam.
Image 1: Teachable machine application screenshot
The image above shows the view of a project created in the Teachable machine AI application. On the left, the classes are shown. Once the model is created and trained a preview will be shown.
Privacy and personal information: Discuss the potential misuse of personal images when uploading images of ourselves or friends on websites. Instruct students not to record images of themselves or others via the webcam or uploading images.
The conditions of use for Teachable machine state that images are not stored on external servers if the teachable machine program is closed when completed and the project is not saved. If students close the tab, nothing is saved in their browser or on any servers. View the conditions when saving projects to the cloud on what data is stored and ‘who’ is able to view the model.
P5 web editor
Note: The P5 web editor for this lesson requires an internet connection, browser on Windows or Macintosh and a webcam.
Familiarise yourself with the P5 web editor.
Note: The P5 web editor was chosen over other similar web editors because it provides a solution to show and use camera input and use the URL from the Teachable machine. A pre-made version is provided to enable students to easily input their model. They can duplicate and remix the code depending on their skill level.
Image 2: P5 web editor screenshot
Learning map and outcomes
In this lesson, students will:
- Describe the process used to train a simple AI using machine learning and describe potential for bias.
- Create, train and test their machine learning model using an online AI tool.
|By the end of this lesson students will:||Mindset||Skillset||Toolset|
Describe the process in training a simple AI using machine learning.
Create, train and test their machine learning model using an online AI tool.
Analytical, Reflective, Curious, Algorithmic
Video: Machine learning
A browser based AI tool: Teachable Machine that requires a device with camera input enabled
P5 web editor on a device with camera input enabled
For more information about learning maps refer to: Mindset, skillset, toolsets
Share the assessment criteria and rubric (in the assessment button) with students.
Show students a real example of an AI that uses computer vision.
Familiarise students with machine learning and the process involved. View this video that concisely defines AI, then defines machine learning through a simple example: What is Machine Learning?
Use the context of training an AI to recognise hand gestures for a game of rock, paper, scissors, for students to consider the training data required while also introducing the idea of bias.
Image 3 Rock, paper scissors
The machine learning process
- Discuss the general process of training an AI for example:
- labelling and classifying images, (paper, or scissors or rock) Q. What images are required and how many of them in order to achieve a good learning outcome?
- training the model (the AI uses the data to look for patterns and create fine tunes existing algorithms)
- testing the model (use new images to test the AI; how well does it predict the correct label and to what level of confidence?)
Labelling and classifying images
Use the worksheet: Labelling and classifying images to consider the range of training data the AI would need to effectively recognise new images of hand gestures.
- Discuss the fact that AI systems are vulnerable to errors introduced during the training process by its human creators. This is referred to as bias. Brainstorm potential areas for bias and how these can be addressed. Examples may include capturing gestures:
- of only left or only right hand [bias: left or right handed]
- at the same distance from camera [bias: size]
- one person’s hand [bias: skin colour and size]
- same position [bias: positional]
- only front of the hand [bias: front or back]
- only one type of background is used [bias: background type/colour]
- Ask students to explain how they plan to avoid introducing bias in their AI model.
Explain that computers can be programmed to be intelligent, or at least smart.
Explain that students are going to work in small groups to create, train and test an AI model that recognises hand gestures for a game of Rock, paper, scissors.
Ask students to apply their learning from the unplugged activity related to labelling and classifying images and avoiding bias.
- Introduce the tool Teachable machine. Explain that this tool lets you train up an AI application – without having to code – to recognise inputs and match them each to a particular output.
- Some students may need the process modelled; others may be able to create a model without assistance (for these students go to Learning construction). If required, model how to create, train and test an AI model. Refer to this video explanation or follow these steps:
Image 4: Teachable Machine Application screenshot
- Edit ‘Class 1’ and label it as Rock. Record images of hand gestures for rockheld in front of the webcam.
- Edit ‘Class 2’ and label it as Paper. Record images of hand gestures for paper held in front of the webcam. Add a class following the same process to add scissors Class.
- Once students understand how to create the model, train and preview the model, they can then go to Learning construction to create their own model.
- Provide students with the opportunity to create their own AI model using Teachable Machine.
- Students label the classes and record images, providing as many different data types for each class. Consider the background against which the hand gestures are recorded. They can preview and test their model. If required they can make modifications and retrain the model. Once completed they can save their model to the cloud and copy the link so they can import this into another program.
- Ask students to preview their model and record a screen capture of their trained AI model. As part of the recording ask them to explain how they minimised the chance of bias. Use this as a form of assessment.
- A completed rock, paper, scissors classifier will look something like this AI model: Rock, paper, scissors. [Requires device with camera enabled].
You may want to open the project up and provide students with a different context other than the game Rock, paper, scissors. Some students may prefer to apply this programming project to one of the following contexts:
- Create a way to use teachable machine AI model to communicate with a person with a disability.
- Teach a young child to recognise the world around them and read
- Use visual cues such as arrows or hand gestures to control a game for example a maze game such as pac man.
Girls in Focus:
Research suggests that girls are motivated when they are given opportunities to approach projects their own way, exercising their personal preferences and creativity. Engaging with creative problem solving also encourages students to embrace failure as part of the learning process, building resilience.
Students will need the URL of the model they created using Teachable Machine. Alternatively students can use this pre-made model
Note this model is created against a light background; so it has a bias.
Provide students access to a computer with a camera enabled and the sample code (sketch)
Ask students to duplicate the sketch and save it. They can then make changes to the sketch.
To get the program working with their own AI model, ask students to insert their own URL copied from their Teachable machine project. Replace the highlighted modelURL as shown.
Image 5: P5 sketch with Teachable machine model URL highlighted
Students select ‘run’ to test the program to make sure it is operational and that their AI model is working as expected (correctly recognising hand gestures as Rock, Paper or Scissors). Students can then further develop the program to add a level of game play. The program should output as follows (refer to image).
Image 6: Output: P5 sketch with Teachable machine model
The program uses a series of if/else statements to show text onscreen if the label is recognised. Students could firstly modify this section of code.
Ask students to use pseudocode to map out changes to the program to incorporate game play. Students code the program and trace errors to fix issues and ensure the program runs as expected. To guide students through decomposing the problem and considering user interface and coding the program refer to the Worksheet planning: AI powered rock, paper, scissors game.
Talk about the bar on the Teachable Machine interface, which displays the AI’s confidence level.
Discuss the scale and percentage. If the bar is fully coloured 100%, the AI is very sure. If the bar is only partly coloured, the AI is not quite sure. Here’s an example from Rock, Paper, Scissors AI model:
|Correct: 100% sure||Correct: quite sure||Incorrect|
|The model is working as expected. The scissors are predicted with 100% confidence.||The model is working as expected. The rock is predicted with 73% confidence.||The model is not working as expected. The model predicts the hand gesture is paper (83%) and less sure it’s a rock (16%). ; sufficient data may not have been used in training.|
- When was the AI very sure of its guess?
- When was it not so sure?
- A bias may be experienced if the data used does not contain a diverse range. Examples may include one size, one type of image etc.
Discuss application of these types of technologies for people with a disability.
- How might this application help people communicate who may experience difficulties.
- What images could be used to assist in communicating day to day conversations.
- How might these technologies be used by a person who is vision impared?
Why is this relevant?
AI is the ability of machines to mimic human capabilities in a way that we would consider 'smart'.
Machine learning is an application of AI. With machine learning, we give the machine lots of examples of data, demonstrating what we would like it to do so that it can figure out how to achieve a goal on its own. The machine learns and adapts its strategy to achieve the goal.
In our example, we are feeding the machine images via the inbuilt camera. The more varied the data we provide, the more likely the AI will correctly classify the input as the appropriate classification. In machine learning, the system will give a confidence value; in this case, a percentage and the bar filled or partially filled, represented by colour. The confidence value provides us with an indication of how sure the AI is of its classification.
This lesson focuses on the concept of classification. Classification is a learning technique used to group data based on attributes or features.
Bias can be introduced into the training of an AI. It may be through using a small sample size of data for example one type of image for each classification or the way the data is labelled due to human error or human short comings such training on limited hand types, positions and left or right handedness.
In this video, students are shown how to train an image classifier and import the machine learning model into a p5.js sketch with the ml5.js library. The sketch provided uses this sketch as a basis. Some students may be interested in how to code the program from the start.