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
- 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.
- 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:
- Create a New file in PictoBlox App.
- Click the Add extension button and add the Natural Language Processing extension.
- Go to the My Blocks palette and create two blocks named Data for Lights On & Data for Lights Off.
- You will find two hat blocks with the same name and blocks in the My Blocks palette.
- Drag and drop an add () as () block from NLP below Data for Lights On hat block.
- 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.
- Repeat steps 5 & 6 nine more times for different commands as shown in the image below.
- 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.
- Now, we need to train our classifier. Follow the steps below to make the script:
- Create a block named Train Data following the same steps as earlier.
- Take the Train Data hat block and add a reset text classifier block below it from the Natural Language Processing extension.
- Add the Data for Lights On and Data for Lights Off stack blocks below the reset text classifier block as shown.
- Add a train text classifier block from the Natural Language Processing extension.
- Now, let’s check if our text classifier actually works.
- Add a when flag clicked block into the scripting area.
- 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.
- Add a say () for () seconds block from the Looks palette.
- Inside the say () for () seconds block, drop a get class of () block and the default time is 2 seconds.
- Inside the get class of () block, write “I am playing”.
- Repeat the above step and this time, write “I need to study” inside the get class of () block.
- Run the script to check it. Tobi should first say “Lights Off” and then “Lights On”.
- Save the file as NLP.
Activity: Output
Make sure you finish and submit the assignment, as well as take the quiz, before moving on to the next lesson.