Using Scratch to Teach Undergraduate Students' Skills on Artificial Intelligence

This paper presents a educational workshop in Scratch that is proposed for the active participation of undergraduate students in contexts of Artificial Intelligence. The main objective of the activity is to demystify the complexity of Artificial Intelligence and its algorithms. For this purpose, students must realize simple exercises of clustering and two neural networks, in Scratch. The detailed methodology to get that is presented in the article.


I. INTRODUCTION
Scientific Method is key in the development of technologically advanced communities [6], and it is of great importance that our students include it in their curricula. As many other competences, it is convenient that some knowledge of scientific method is learned at the undergraduate stage, and any effort done in the Educational System to foster the learning of it undoubtedly pays.
For a better understanding of scientific method, the Educational Community widely recognizes that school curricula must move on from traditional expositive classes to more informal and collaborative contexts. The fact is, however, that active participation of the students is difficult to achieve at the classroom. One of the reasons should appeal to the interests of the students themselves; in order to achieve active involvement, the classes should make use of more attractive resources, such as fun, games, social interaction, observation of real problems, novelty, etc. This is specially clear in the case of undergraduate students. Surprisingly, there is a quite widespread mistrust of science in the post-truth era where we live. This makes it necessary to insist on a bigger effort to spread the benefits of science among younger students [1], [2].
The present article presents the design and development of several simple educational exercises to promote understanding and learning of Artificial Intelligence (AI) at schools with the usage of Scratch, which is a graphic programming environment. By allowing novices to build programs by snapping together graphical blocks that control the actions of different actors and algorithms make programming fairly easy for beginners.
AI is one of the technologies that will transform our society, economy and jobs in a greater extent along the next decades. Some of the most known examples of AI are driverless cars, chatbots, voice assistants, internet search engines, robot traders, etc. These systems can be embedded in physical machines or in software, and the promising capacities of both architectures makes it necessary for society and politicians to regulate the functions and limits of these devices [8]. Despite the myth of destructive AI represented in films such as Terminator or I, Robot, the truth is that nowadays most usual smart algorithms consist of a series of simple rules applied to large series of numbers, and the result of that is called Artificial Intelligence.
British Parliament and other institutions recommend the education from high school of Artificial Intelligence [28], regardless of the pace of development of this technology, in order to cope future technological and social challenges.
The main reason is to improve technological understanding, enabling people to navigate an increasingly digital world, and inform the debate around how AI should, and should not, be used.
Computational thinking is a problem-solving method that uses techniques typically practiced by computer-scientists and is increasingly being viewed as an important ingredient of STEM learning in primary and secondary education [13]. On the other hand, several studies in higher education research report on the low student pass rate in mathematics. Therefore, research into mathematics education has been greatly emphasized in the last decade [20]. Though education reform efforts have been made around the world, the trouble lies on the fact that most of schools are trying to prepare students for the future by continuing what was done in the past [13].
Thus, in this paper an educational proposal for teaching the basic mathematics behind simple AI algorithms is presented. The solution is developed in an open source platform, Scratch, and the main objective for the students is to be aware of the rules behind intelligent systems rather than learning or memorizing anything. The specific tasks to understand are automatic clustering, learning and prediction with AI. The software is designed for students of 16-18 years. The algorithms chosen for teaching are specifically designed or adapted to the mathematical background of the students. Moreover, the article will be publicly available in a web repository 1 .
The present article is divided in the following sections. In section II a background for teaching AI is presented. In Section III the mathematics that will be used in the software are described. In Section IV the methodology that teachers will use with the students is detailed. Finally, in Section V, conclusions of the experiment are analyzed.

II. BACKGROUND
There is a wide consensus among computer scientist that it is quite difficult to teach the basics of AI [11]. This is due to the lack of a unified methodology and to the blend of many other disciplines which involve a wide range of skills, ranging from very applied to quite formal [12]. AI modeling, algorithms and applications may be taught using tools as simple as paper and pencil, traditional computer programming or hands-on-computer programming [10]. Several papers discuss the prerequisites needed to understand machine learning [19].
Some experts suggest that high school education reforms should encompass a drive on STEM skills and coding in schools; others support the idea of focusing on digital understanding, rather than in skills.
Nowadays, however, the tendency is to teach coding to students, mostly framed in robotics workshops [13], [16], [17]. Seymour Papert [14] laid much of the groundwork for using robots in the classroom in the 1970s. An argument for teaching to children and students using robots is that they see these machines as toys [18]. Studies show that robotics generates a high degree of student interest and engagement and promotes interest in maths and science careers.
[12] uses a Lego robot to make the students build the hardware and control the software that manages the sensors and the environment. [10] uses a low-cost robot platform to teach students how a neural network is trained and built for a navigation robotic problem. There is the possibility that students pay attention to the robotic exercise rather than to the AI learning fundamentals, and this is what [15] tries to settle down in another robotic navigation problem. Both authors specify which are the premises to be transmitted to the students about the objective of the activity. These premises are, first, underlining that the exercise is about Artificial Intelligence and not robotics; second, emphasizing that they are clearly defined open projects, with specific start and end points.
However, although robotics is recognized as a proper way for teaching computational-thinking (CT) skills to students [22], in this article we present a wider approach to AI, based on the teaching of some mathematics with the help of Scratch [21], which will let us introduce the students into more than one algorithm.
CT can be defined as the process of recognizing aspects of computation in the world that surrounds us and applying tools and techniques from Computer Science to understand and reason about both natural and artificial systems and processes [22], [23].
The software used to enhance CT on students should be easy for a beginner to overcome the difficulty of creating working programs, but it should also be powerful and extensive enough to satisfy the needs of more advanced programmers. Several programming tools fit these criteria in varying degrees: Scratch, Crickets, Karel the Robot, Alice, Game Maker, Kodu, Greenfoot and Agentcubes. All those tools are based on the Logo philosophy [14]. Graphical programming environments are relatively easy to use and allow early experiences to focus on designing and creating, avoiding issues of programming syntax.
From a pedagogical perspective, computational tools are capable of deepening the learning of mathematics and science contents [24], [25], and the reverse is also true [26]. Scratch is today one of the most popular of these programming environments, and it has proved to be very effective for the engagement and motivation of young students with no experience at programming [27].

III. CONTENT
This article will depict algorithms that can be practiced using Scratch in a workshop with students 16-18 years old. After the workshop, the students should be able to understand, play and eventually code these algorithms.
Specific algorithms are: And the exercises that students will have to do are described next.

K-means
The algorithm K-means, developed in 1967 by MacQueen [3], is one of the simplest unsupervised learning algorithms that solve the well known clustering problem. K-means is a clustering algorithm which tries to show the students how items in a big dataset are automatically classified, even while new items are being added. The adopted technique for creating as many clusters as we want, is the minimum square error rule.
Starting from a given cloud of N points and a smaller cloud of K mass centers, the aim of this activity is that the student learns how to cluster the points into K groups, by programming an application in Scratch. In order to do the clustering, each point will belong to the cluster defined by the closest mass center. Finally, each of the K clusters will be colored with a different color (see Figure 1).

Neural network
The basic idea behind a neural network is to simulate lots of densely interconnected brain cells inside a computer so you can get it to learn things, recognize patterns, and make decisions in a human-like way. The main characteristic of this tool is that a neural network learns all by itself. The programmer just needs to design the physical structure (number of outputs, inputs, hidden layers) and set some very simple rules involving additions, multiplications and derivatives. They are based on perceptrons, which were developed in the 1950s and 1960s by the scientist Frank Rosenblatt [7], inspired by earlier work by Warren McCulloch and Walter Pitts [4]. It is important to note that neural networks are (generally) software simulations: they are made by programming very ordinary computers. Computer simulations are just collections of algebraic variables and mathematical equations linking.
Habitually, neural networks use backpropagation type algorithms which require the usage of derivatives. However, Figure 1. Initial and final clouds of points the target students of this exercise (16-18 years old) do not have this mathematical operation in their curricula yet. As a consequence, the neural networks have been created with a logic activation function, which are understandable by the students. Necessary formulas are presented to them without any previous mathematical demonstration.
Different exercises are developed with neural networks. First, a simple neural network with two inputs and an output neuron, is trained with an AND logic gate (see Figure 2). In each iteration, students will see the different weights that the neural network gets. Next, and OR logic gate will be used, and as a consequence, students will observe how adjusting parameters change with this new data. The mathematical description of this neural network is described in Subsection III-1.
As a second exercise of this type, a more complex neural network exercise is presented (Figure 3. Considering a 3-2-1 neural network (three inputs, a hidden layer with two neurons and an output) the students will train the neural network with AND and OR logic gates again. The detailed operations of this exercise appear in Subsection III-2.
1) Simple Neural Network operation: The neuron obtains an output Y 1 from the two inputs Input 1 and Input 2 using the corresponding weights.
The activation function at N 1 defined as shown next: where Y 1 is the output of the neural network. The error is defined as the difference between the desired output Desired output and the obtained output.
Each time the function is executed, the algorithm updates the weights using backpropagation and gradient descent rule, until output Y 1 converges to the desired output Desired output.
The new value of the first weight will be the sum of its previous value and the product of the first input, the learning rate (LR) and the error.
Similarly, the new value of the second weight will be: 2) Complex Neural Network operation: There are three neurons: two at the hidden layer (N 1 and N 2 ) and one at the output (N 3 ). Their calculus depend on the inputs (X 1 , X 2 and X 3 ) and weights (W 1 , W 2 , W 3 , W 4 , W 5 ) following next expressions: There is an activation function at N 3 defined as shown next: where N 3 is the output of the neural network.
Error is defined as: Employing again the backpropagation and gradient descent rule, the calculus for updating the weights result in next equations: Once the values of the error and weights are calculated, the student has to store them on the corresponding neurons.

IV. METHODOLOGY
The workshop of Artificial Intelligence will be based on the usage of the educational tool Scratch [21]. Scratch is a visual programming language, and its online community is targeted primarily at children and young students. Using Scratch, users can create online projects and develop them into almost anything by using a simple block-like interface. When they are finished, students can share their projects and discuss their creations with each other. Before the students start the exercises here proposed, it is convenient that they acquire some knowledge of this language.
In all algorithms presented in Section III, the first task of the student is to fill in the white gaps left to him/her among the lines of code, marked with a comment. That is, the students do not need to create the algorithm or write the whole code themselves; the code will be provided for the most part.
Students will work in pairs and the workshop will be structured in the following steps: • At the beginning, the teachers will give a short explanation of 15-20 minutes about AI and the objective of the workshop, with a twofold aim: first, to demystify Artificial Intelligence; second, to understand some simple mathematics underneath the computations.
• The students will work in couples. Teachers will provide them with some written theoretical background about the algorithms and the instructions for the exercises (K-means and neural networks). Moreover, teachers will explain in another 10 minutes of presentation the basics of the algorithms. • Students will have one hour to finish the codes (20 minutes for K-means and 40 minutes for both parts of the neural networks) and eventually execute the applications to see whether they work properly. During this personal tasks teachers will be at hand ready to assist whenever necessary. • Finally, at the end of the session, the teachers will provide the students with the finished proposed answers in Scratch software for the students to check them.

A. K-Means
The algorithm is developed using one main block and three function blocks of Scratch code. The function blocks are called NewDataSet, KMeans and ColourPoints.
The student must finish up the three function blocks: the block NewDataSet, block KMeans and block ColourPoints.
The main block will create the mass centers and the cloud of points. The set of mass centers contains K random points with X coordinates between (−230, 230) and Y coordinates between (−170, 170). These K points will be the mass centers of the clusters (see Figure 4). The first task is to finish the programming of the block NewDataSet that will create the cloud of N points. The cloud must contain N points with X coordinates between (−230, 230) and Y coordinates between (−170, 170) (see Figure 5). Block KMeans stores the number of the mass center that will be assigned to each point. To do that, the student must code the calculation of the Euclidean distance from each of the points to each the mass centers in variable A. The program will then find the minimum distance of them all and fill up vector Clusters, which contains the numbers of the cluster to which each point belongs.
Finally, block ColourPoints graphs the clouds of points and the cloud of centers of mass, each in a colour given by vector Clusters.
The algorithm here presented just tries to show automatic clustering, and not getting equivalent size clusters.

B. Neural Network: AND/OR logic gate
The algorithm is developed using a main block, which initializes the data, and two blocks, Neuron and ExecuteButton.
The interface used is described in Figure 2. The student must code the equations that define the function that performs the only neuron of the network. The equations to calculate is the update of W 2 , as can be seen in Figure 7.
The students must train the neuron using two sets of data: one set for the AND logic gate and another for the OR logic gate.

C. Complex Neural Network Operation
This exercise is based on training a three inputs neural network with AND and OR logic gates. As an additional complexity comparing to previous exercise, this neural network is multilayered. It uses three neurons, Neuron1, Neuron2 and Neuron3, and ExecuteButton.
The exercise is planned to fill the gaps of the following operations: • Net calculus of N 3 • Update of W 2 and W 5

V. CONCLUSIONS
The paper presents teacher-guided, easy to implant activities that can be performed at schools using Scratch. Moreover, the operations have been adapted for [16][17][18] year-old students' mathematical background.
The tasks presented are scalable; students can delve into the maths involved in the mathematical iterations or into the Scratch code itself, or even propose new neural networks to deal with other problems.
The work can be extensible to students of different ages and more AI algorithms can be added to the system.
The easiness of the equations of K-means and neural networks permit their implementation in other formats, such as MS Excel, which in some occasions could be more familiar to students than Scratch.
Moreover, the students will realize that the mathematical knowledge acquired throughout the year will help them finishing the programming of automatic clustering and neuron networks, being able to train AND and OR logic gates.
As a future work, first, the authors should organize the AI workshop several times and measure the grade of the objective achievement in collaboration with pedagogical researchers. Secondly, more programming languages should be explored (GeoGebra, HTML, ShynnyApps) in order to implement more exercises, such as the usage of neural networks for data prediction.

VI. ACKNOWLEDGEMENTS
This project has received funding from the European Union's Horizon 2020 research and innovation programme under the Marie Sklodowska-Curie grant agreement No 777720.