1 00:00:00,680 --> 00:00:05,440 To make your AI storytelling friend,  you’ll train a machine learning,   2 00:00:05,440 --> 00:00:11,120 or ML, model to recognise when  a toy moves in different ways.  3 00:00:11,120 --> 00:00:16,280 You’ll then combine this model with code  to make different sounds and show different   4 00:00:16,280 --> 00:00:20,856 icons on the micro:bit’s LED display. 5 00:00:20,856 --> 00:00:28,480 Then you’ll download the model and the code to a micro:bit and use it on your toy to help tell a story.  6 00:00:28,480 --> 00:00:34,264 Our story is about a bear called Lucy, but  you can change the project to fit your own. 7 00:00:34,264 --> 00:00:40,360 [MUSIC] This is Lucy the bear. 8 00:00:40,360 --> 00:00:47,520 She wants to be a gymnast when she grows up, so every  day when she wakes up, she practices her jumping. 9 00:00:47,520 --> 00:00:54,640 She jumps as high as the ceiling. Then after breakfast she practices her rolling. 10 00:00:54,640 --> 00:00:59,920 She rolls round and round until  her whole world is spinning.  11 00:01:01,469 --> 00:01:06,490 Then she takes a break and has a little nap. 12 00:01:10,048 --> 00:01:18,760 To start making your AI storytelling friend, click ‘Open in micro:bit  CreateAI’ to launch the project.  13 00:01:18,760 --> 00:01:23,829 This project comes with 8 samples  of movement data for three different actions: 14 00:01:23,829 --> 00:01:28,959 jumping, rolling and sleeping. 15 00:01:28,959 --> 00:01:38,120 micro:bit CreateAI collects movement data samples using the accelerometer, the micro:bit’s movement sensor.  16 00:01:38,120 --> 00:01:43,560 To add your own data samples, you need  to make a data collection micro:bit.  17 00:01:43,560 --> 00:01:50,160 If your computer has Bluetooth enabled, then  you'll just need 1 micro:bit and a USB data lead.  18 00:01:50,160 --> 00:01:54,840 If you don’t have a Bluetooth connection,  you’ll need to use 2 micro:bits.  19 00:01:54,840 --> 00:01:59,554 Follow the instructions on screen to connect. 20 00:01:59,554 --> 00:02:06,777 Once your data collection micro:bit is connected, attach it to your toy like this. 21 00:02:06,777 --> 00:02:15,400 You’ll see the lines on the live graph change as you move your toy. As this project already includes quite a lot 22 00:02:15,400 --> 00:02:25,000 of data samples, we suggest you add 1 sample for  each action for now and collect more data later.  23 00:02:25,000 --> 00:02:29,440 Click on the ‘jumping’ action so  you can add more data samples to it.  24 00:02:29,440 --> 00:02:33,600 You will get a countdown before  a 1 second recording starts.  25 00:02:33,600 --> 00:02:39,800 Click record and start moving your toy immediately  to make sure you get a clean data sample.  26 00:02:39,800 --> 00:02:43,440 A clean sample is one where you’re  moving for the entire sample,   27 00:02:43,440 --> 00:02:50,800 you don’t start late or finish moving early. Next try adding an extra data sample to the   28 00:02:50,800 --> 00:02:57,115 ‘rolling’ and ‘sleeping’ actions. 29 00:02:57,115 --> 00:03:07,520 You’ll notice that when your toy is asleep, the x,y, and z lines change places depending on the orientation of the micro:bit.  30 00:03:07,520 --> 00:03:14,600 Click ‘Train model’ to build the ML model. The tool now builds a mathematical   31 00:03:14,600 --> 00:03:19,960 model that should recognise different  actions when you move your micro:bit.  32 00:03:19,960 --> 00:03:25,640 As soon as the model has been trained,  you’ll see the Testing model page.  33 00:03:25,640 --> 00:03:30,760 Your data collection micro:bit can now be  used to test how well the model is working.  34 00:03:30,760 --> 00:03:35,880 It should still be connected to the tool, and  you’ll see that as you move it, CreateAI is   35 00:03:35,880 --> 00:03:40,317 estimating what action you are doing. 36 00:03:40,317 --> 00:03:47,027 Move your toy in different ways to see the estimated action and the certainty bar graph change.  37 00:03:47,400 --> 00:03:56,160 The percentage shows how certain, or confident,  the model is that you are doing each action. 38 00:03:56,160 --> 00:04:00,760 You may notice your model is not  estimating some actions accurately.  39 00:04:00,760 --> 00:04:07,920 In that case it’s a good idea to click on  ‘Edit data samples’ and improve your model.  40 00:04:07,920 --> 00:04:13,960 Machine learning models usually work best with  more data, so record some extra samples for each   41 00:04:13,960 --> 00:04:22,400 of the actions, or focus on collecting more data  for the action that was problematic in testing.  42 00:04:22,400 --> 00:04:28,360 Clean data samples also help an ML model  work better so examine your data set and   43 00:04:28,360 --> 00:04:38,200 identify any samples that could confuse the  model. You can delete these by pressing X.  44 00:04:38,200 --> 00:04:44,920 Once you’ve added more data and checked your  data set, click ‘Train model’ again. Then test   45 00:04:44,920 --> 00:04:50,003 the model again on the ‘Testing model’ page. 46 00:04:50,003 --> 00:04:57,120 Once you’re happy with how the ML model is behaving, you can use it with  the ready-made project code.  47 00:04:57,120 --> 00:05:06,120 Click on ‘Edit in MakeCode’ to see the code  blocks in a special version of Microsoft MakeCode.  48 00:05:06,120 --> 00:05:10,040 You can return to see your  data in CreateAI at any time   49 00:05:10,040 --> 00:05:19,720 using the arrow in the top left of the screen. These blocks use the model you’ve created in code.  50 00:05:19,720 --> 00:05:24,880 The ‘on ML… start’ blocks react  when the ML model decides your   51 00:05:24,880 --> 00:05:31,320 toy is making a particular movement, or action. Depending on the action, the code shows different   52 00:05:31,320 --> 00:05:38,600 icons on the micro:bit’s LED display output  and plays different sounds on its speaker.  53 00:05:38,600 --> 00:05:46,360 If it’s not sure what action your toy is doing –  if the action is ‘unknown’ – it clears the screen.  54 00:05:46,360 --> 00:05:53,320 And when each action stops, the code  stops the micro:bit making any sound.  55 00:05:53,320 --> 00:05:56,640 To make the code and the ML  model run on your micro:bit,   56 00:05:56,640 --> 00:05:59,640 you just need to download it to a micro:bit.  57 00:06:00,280 --> 00:06:06,320 Press ‘Download’ and follow  the instructions on screen.  58 00:06:06,320 --> 00:06:10,640 Now test the finished project on  a micro:bit attached to your toy. 59 00:06:10,640 --> 00:06:16,200 Do the correct sounds play and icons display  when your toy makes different movements? 60 00:06:16,200 --> 00:06:19,800 Does it work equally well when  someone else moves the toy?  61 00:06:19,800 --> 00:06:26,880 If not, you can go back and collect more  data from them and re-train the model.  62 00:06:26,880 --> 00:06:30,960 Congratulations, you’ve trained your toy  to react to different kinds of movement   63 00:06:30,960 --> 00:06:36,600 using data you have collected, training an AI  machine learning model, and combining it with   64 00:06:36,600 --> 00:06:43,480 code to make an interactive storytelling toy! What other actions, or movements might your toy   65 00:06:43,480 --> 00:06:51,795 make, perhaps as part of telling a story? Can  you add them using the micro:bit and CreateAI?