Introduction
You feel a little unwell, who do you tell your symptoms first? (Except for mom.) Google! Yes, you google the symptoms, find what is the thing that has made you unwell, and then you move on to find a remedy for the same.
In this project, we are going to make a virtual doctor using the NLP extension. You need to tell your symptoms to him and he will tell you what caught you and what shall you do next.
Wonder how will the virtual doctor figure out the disease as many have a couple of symptoms same. Using NLP!
So let’s begin by understanding what NLP is.
What is NLP?
NLP stands for Natural Language Processing.
This is the area of AI concerned with the interaction between computers and humans in natural language. The aim of this extension is to help computers understand language as well as we do.
Along with the NLP Extension, there are a lot of new features added to the latest version of PictoBlox. You may need to download PictoBlox or update it to use the latest features.
Setting the Stage for the Virtual Doctor
Open PictoBlox.
Let’s begin by setting up the stage.
- Delete Tobi’s Sprite.
- Click on Upload Sprite Button and upload the Doctor Sprite.
- Go to the Backdrop Palette, add the Blue Sky backdrop from the library.
- To get the hospital on the stage, Upload the image of hospital as the backdrop.
- You may find the one backdrop of Blue Sky and one of the hospital. Copy the hospital image and then paste it into the backdrop of Blue Sky.
- Adjust the placement of the hospital and doctor according to your choice.
- The final stage will look like this:
You can download the sprites of doctor and hospital from here.
Training the Text Classifier
Now that we have set the stage. Let’s begin by training the text data for diseases. We need to train PictoBlox to analyze the text and perform the corresponding action.
Add text data in classes
We will first add data i.e the symptoms for three diseases, COVID-19, Malaria, and Diabetes one-by-one.
- Go to the My Blocks palette and create a block named Data for COVID-19.
- To make the text classifier, we need the Natural Language Processing extension. Add the Natural Language Processing extension from the extension library.
- Take the Data for COVID-19 hat block and drop an add () as () block below it.
- In place of text in the add () as () block, write the first command, “Dry Cough”. In place of class, write “COVID-19”. COVID-19 will be the name of the class.
- We’re going to give the classifier three more symptoms to add to our class. You can add many as you may find. Duplicate the add () as () block and write the rest of the symptoms in them.
- Now, we similarly need to add text training blocks for the other two diseases too.
Training the Classifier
Now that we have added data in classes, we need to train our classifier.
- Create a block named Train Data.
- Take the Train Data hat block and add a reset text classifier block below it from the Natural Language Processing palette.
- Add the Data for COVID-19, Data for Malaria, and Data for Diabetes stack blocks one after the other.
- Add a train text classifier block.
- The script will look like this:
With this our text classifier for our virtual doctor is trained, it’s time to bring it into action.
Final Script for the Virtual Doctor Using NLP
Let’s begin to write the script that to make the virtual doctor say the name of the disease we have after we tell him our symptoms.
- Add a when flag clicked hat block to run the script when the green flag is clicked.
- Drop the Train Data stack block below it.
- Let’s make the doctor greet us. Add a say () for () seconds block from the Looks palette. Write “Hello! Welcome to the virtual hospital” in the first space given.
- Next, we’ll want the doctor to ask the symptoms, thus from the Operators palette, add a ask () and wait block. Write “How are you feeling today? Please tell me your symptoms.” in the space given.
- Here is when we will write the symptoms and the doctor will tell us the remedies for the same. Place an if () block into the scripting area.
- Add an () = () block from the Operator palette.
- Inside the first space of the () = () block, drop a get class of () block. In the second space, write “COVID-19”.
- Inside the get class of () block, drop a answer block from the Sensing palette.
- This will check the symptoms you enter with the text data, and if they match with COVID class, the doctor will say out the disease as COVID-19.
- Into the if () arm place a say () for () seconds block.
- Place join () () block from the Operator palette.
- Write “You are infected with ” in the first space. Add another join block in the second space. Drop a get class of () block into the first space of the second join block and write “.” to complete the statement in the second space. Inside the get class of () block, drop an answer block from the Sensing palette.
- Now that we got to know the disease, doctor will say the remedy for the same. Place a say () for () seconds block from the Looks Palette and write the remedies into it. If you need to write more remedies, you can use another say block too.
- With this diagnosis of COVID is done, we will now follow similar steps for Malaria and Diabetes. Duplicate the if block and make the changes respectively.
- With this our script is complete.
Press the green flag to start the script.
Conclusion
This project demonstrated how to create a virtual doctor using the NLP extension in PictoBlox. We used the Natural Language Processing (NLP) extension to train the text classifier by creating a data set of symptoms and the corresponding diseases. After training, we wrote the script that interacts with the user and gives them the diagnosis of their symptomatic input. The script facilitates the interaction between the user and the virtual doctor.