Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

Pages Menu
TwitterRssFacebook

Posted by on Apr 23, 2018 in Bot Framework, Development

Writing Smarter Bots: adding AI-level natural language processing of text entities

Writing Smarter Bots: adding AI-level natural language processing of text entities

Yesterday, I was doing some work writing a new Teams bot (details out soon). I needed to parse a fuzzy, natural language date time string, for example “in 3 days time, next Wednesday, tomorrow at 7 in the evening.”

This is the sort of thing which LUIS does really well. However, creating a stub LUIS instance purely to use the datetime-parsing features seemed like overkill and the wrong solution: it would introduce latency as the request would have to go to LUIS and back. Also, it would attract an extra cost at scale. I’m not sure how well-used my new bot will be; but it’s worth planning on being frugal in the cloud wherever possible.

I started looking around to see if anyone had packaged a .NET library to encompass this and found Microsoft.Recognisers.Text. As the name suggests, this is a GitHub project that’s written and maintained by Microsoft. This is actually the same code that goes into LUIS, open-sourced and made available for everyone to use. I love this new Microsoft approach of working in the open and making building blocks available to everyone. This means I can embed the same functionality, but processed locally, at a fraction of the speed and cost.

There are actually several sub-projects here, focused on different entities: numbers, numbers with units, date/times, sequences (like phone numbers or IP addresses), choices, and TIMEX expressions.  Each one has its own NuGet package (or NPM package if you’re using Node) and the GitHub page describes nicely how to use them.

For me, the process of parsing a possible date-time value came down to passing in the string, and then looking at the returned List<ModelResult> to see what sort of object (date, time, datetime, range) was returned and what the value was, and then processing from there.

1
2
3
var recognizer = new DateTimeRecognizer(Culture.English);
var model = recognizer.GetDateTimeModel();
var result = model.Parse("Tomorrow at 3pm");

or

1
var result = NumberRecognizer.RecognizeDateTime("next tuesday 9am", Culture.English);

Thanks to these packages, I’m now doing the same type of AI magic that LUIS does, using the same tooling that powers LUIS, offline and in my own application. Which ultimately means I don’t have to try and write my own date-time natural language parser, which is probably in everyone’s interest. Abstracting on the shoulders of giants!

Written by Tom Morgan

Tom is a Microsoft Teams Platform developer and Microsoft MVP who has been blogging for over a decade. Find out more.
Buy the book: Building and Developing Apps & Bots for Microsoft Teams. Now available to purchase online with free updates.

Post a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share to Microsoft Teams