Lesson 16: Natural Language Processing

Lesson Description

In this lesson, you will learn about Natural Language Processing and its applications. You will also learn how to create a text classifier using PictoBlox and the Natural Language Processing Extension.

Natural Language Processing

Natural Language Processing, abbreviated as NLP, is a branch of artificial intelligence that deals with the interaction between computers and humans using natural language.

Natural language refers to language that is spoken and written by people, and natural language processing (NLP) attempts to extract information from the spoken and written word using algorithms.

The ultimate objective of NLP is to read, decipher, understand, and make sense of human languages in a manner that is valuable.

Examples of NLP

  1. Email Filters: Email filters are one of the most basic and initial applications of NLP online. It started out with spam filters, uncovering certain words or phrases that signal a spam message.
  2. Smart Assistants: Smart assistants like Apple’s Siri and Amazon’s Alexa recognize patterns in speech, then infer meaning, and provide a useful response.

NLP in PictoBlox

To make the text classifier, we have the Natural Language Processing extension. Let’s see how we can use it to make real-life applications.

Activity: Text Classifier with NLP

Let’s train PictoBlox to classify a message as turning ON lights or turning OFF lights.

Coding Steps

Follow the steps below:

  1. Create a New file in PictoBlox App.
  2. Click the Add extension button and add the Natural Language Processing extension.
  3. Go to the My Blocks palette and create two blocks named Data for Lights On & Data for Lights Off.
  4. You will find two hat blocks with the same name and blocks in the My Blocks palette.
  5. Drag and drop an add () as () block from NLP below Data for Lights On hat block.
  6. In place of text in the add () as () block, write the first command, “Lights On”. In place of class, write “Lights On”. Lights On will be the name of the class. We’re going to give the classifier 9 more commands to add to our class.
  7. Repeat steps 5 & 6 nine more times for different commands as shown in the image below.
  8. Follow the same steps as those for Data for Lights Off. Only the commands and the class name will be different as shown in the image below.
  9. Now, we need to train our classifier. Follow the steps below to make the script:
    1. Create a block named Train Data following the same steps as earlier.
    2. Take the Train Data hat block and add a reset text classifier block below it from the Natural Language Processing extension.
    3. Add the Data for Lights On and Data for Lights Off stack blocks below the reset text classifier block as shown.
    4. Add a train text classifier block from the Natural Language Processing extension.
  10. Now, let’s check if our text classifier actually works.
    1. Add a when flag clicked block into the scripting area.
    2. Drop the Train Data stack block below the when flag clicked. Now, to test if the classifier is working, we’ll send two new commands for each class (one for Lights On and one for Lights Off) and see if the classifier analyzes them correctly.
    3. Add a say () for () seconds block from the Looks palette.
    4. Inside the say () for () seconds block, drop a get class of () block and the default time is 2 seconds.
    5. Inside the get class of () block, write “I am playing”.
    6. Repeat the above step and this time, write “I need to study” inside the get class of () block.
    7. Run the script to check it. Tobi should first say “Lights Off” and then “Lights On”.
  11. Save the file as NLP.

Activity: Output

Make sure you finish and submit the assignment, as well as take the quizbefore moving on to the next lesson.

Table of Contents