From the course: Advanced Python Projects: Build AI Applications
Displaying automated chatbot responses based on sentiment - Python Tutorial
From the course: Advanced Python Projects: Build AI Applications
Displaying automated chatbot responses based on sentiment
- [Instructor] So now what if none of the keywords match? Well, that's when things get interesting. The bot uses text blob to analyze the sentiment of the message. Let's see how to do that. Type, "sentiment = TextBlob", open parentheses, and write "message.sentiment.polarity." This is where the chatbot try to understand if the user is happy, frustrated, or neutral. Text blob gives us a score between negative one and positive one where negative values mean the message is unhappy and positive values mean it's happy. Based on that score, the bot adjusts its response. Now let's return specific messages to output based on the sentiment score. Now, let's type in "return." "That's so great to hear!" If it is a positive message. So we're going to say, "if sentiment is greater than zero, else." Let's go to the next line. "I'm so sorry to hear that. How can I help?" "If sentiment is less than zero, else." "I see. Can you tell me more about that?" If it is neither positive nor negative, meaning if it's more of a neutral response. Close the parentheses. Next we're going to see how to get the chatbot to talk to the user.