Table of Contents
Example Description
The example shows how to use a text classifier in PictoBlox to make the Twitter Sentiment Analysis Bot using Text Classifier.

Introduction

In this example project, we are going to create a machine learning model that can classify the nature of a comment based on the typed comment input by the user.

Text Classifier in Machine Learning Environment

The Text Classifier is the extension of the ML Environment used for classifying nature of a comment or message which typed by user.

Text Classifier Workflow

  1. Open PictoBlox and create a new file.
  2. You can click on “Machine Learning Environment” to open it.
  3. Click on “Create New Project“.
  4. A window will open. Type in a project name of your choice and select the “Text Classifier” extension. Click the “Create Project” button to open the Text Classifier window.
  5. You shall see the Text Classifier workflow with two classes already made for you. Your environment is all set. Now it’s time to upload the data.

Class in Text Classifier

Class is the category in which the Machine Learning model classifies the text. Similar texts are put in one class.

 

Adding Data to Class

You can perform the following operations to manipulate the data into a class.

  1. Naming the Class: You can rename the class by clicking on the edit button.
  2. Adding Data to the Class: You can add the data writing the text or by Uploading the files from the local folder.
    1. Uploading Dataset:

Training the Model

After data is added, it’s fit to be used in model training. In order to do this, we have to train the model. By training the model, we extract meaningful information from the texts, and that in turn updates the weights. Once these weights are saved, we can use our model to make predictions on data previously unseen.

 

Testing the Model

To test the model, simply enter the input values in the “Testing” panel.

The model will return the probability of the input belonging to the classes.

Export in Block Coding

Click on the “Export Model” button on the top right of the Testing box, and PictoBlox will load your model into the Block Coding Environment if you have opened the ML Environment in the Block Coding.

Script

The idea is simple: the user has to write text in the input panel, and Tobi will tell about the nature of the text.

  1. We’ll start by adding a when flag clicked block from the Events palette.
  2. Add an “forever” block from the Control palette.
  3. Add an “ask () and wait” block from the Sensing palette. Write an appropriate statement in an empty place.
  4. Add an “say ()” block from the Looks palette block.
  5. Inside the say block add join () () block from operator palette.
  6. Inside the join block write statement at first empty place and at second empty place add get class of () block from the Machine Learning palette and at the empty place of get class of () block select an “answer” block from the Sensing palette.
  7. Add an “wait () seconds” block from the Control palette block.
  8. Final code of “Tobi” sprite is 

Final Output