Smarter Conversations. Part 1 - Sentiment
This post starts a series of short articles on building smarter conversations with Microsoft Bot Framework. I will explore detecting sentiment (part 1), keeping the dialog open-ended (part 2), using a simple history engine to help the bot be context-aware (part 3), and recording a full transcript of a conversation to intelligently hand it off to a human operator.
Affirmation
Imagine the following dialog:
User >> I’m looking for screws used for printer assembly Bot >> Sure, I’m happy to help you. Bot >> Is the base material metal or plastic? User >> metal Bot >> [lists a few recommendations] Bot >> [mentions screws that can form their own threads] User >> Great! I think that's what I need Bot >> [recommends more information and an installation video]
It’s not hard to train an NLU service like LUIS to see a product lookup intent in the first sentence. A screw would be an extracted entity. Following a database lookup, the bot then clarifies an important attribute to narrow the search down to either plastic or metal screws and presents the results.
The highlighted sentence that follows is a positive affirmation. It is not an intent that needs to be fulfilled, not an answer to the question asked by the bot. And yet it presents an opportunity for a smarter bot to be more helpful, act as an advisor.
Sentiment
Text Analytics API is part of the Microsoft’s Cognitive Services offering. The /text/analytics/v2.0/sentiment
endpoint makes it a single HTTP request to score a text fragment or a sentence on a scale from 0
(negative) to 1
(positive).
I decided to make the expressed sentiment look like an intent for my bot and so I built a custom recognizer:
1 | const request = require('request-promise-native'); |
Context
Now I can attach a dialog that would be triggered when the bot detects an affirmation and no other intent scores higher. The default intent threshold is 0.1
and that’s why a detected sentiment is given 0.11
.
1 | const sentiment = require('./app/recognizer/sentiment'); |
Unlike other intents, however, a detected sentiment is not enough to properly react to on its own.
The bot needs to understand the context to properly react to an affirmation or discouragement expressed by a user. The bot also needs to be able to handle an interrupted dialog if an affirmation (or an expression of frustration) came in the middle of a waterfall, for example.
I will get to it in part 2. Stay tuned.
Smarter Conversations. Part 1 - Sentiment
https://www.pveller.com/smarter-conversations-part-1-sentiment/