Build Sentiment Classifier, Translator and a Flight Tracker with the Generative AI

Generative AI for Developers

Last week I received an email from the Microsoft Reactor team informing me that I had 360 RSVPs on the day of my talk. While I was super excited, I was a bit nervous because I wanted to ensure that I deliver the content responsibly. If you value your audience’s time, ensure your content is engaging, informative and well-organized. During my talk, I answered around 25 questions therefore I thought that I shouldn’t just deliver the session and upload my slide deck and demos. Instead, I should add some more value to it and make it more inclusive for most of the developers. As a result, I created not just one, but two Polyglot Notebooks (fully interoperable with Jupyter Notebooks) and decided to write about it.

At first, I considered developing simple console applications for the demos. Although these console apps would have sufficed, the getting started guide would have been somewhat cluttered, requiring multiple apps. Therefore, I decided to use a Polyglot Notebook, allowing us to consolidate everything into a single file.

The biggest benefit of Polyglot Notebooks is its interoperability with Jupyter Notebooks & multi-language .NET support.

Introducing Generative AI Notebooks

As a long time .NET developer, I always try my best to bring tech like Reinforcement Learning, Computer Vision and Generative AI to the developer community using the similar languages and frameworks.  Despite my personal interest in .NET, I also did not want to ignore the fact that many developers are also (and rightly so) using Python within this space. Therefore, I decided to create two notebooks, one for C# with .NET Interactive and the other one for Python. Both of the notebooks are identical in terms of the topics covered, so it depends on you which one you’d like to use.

Generative AI Notebook

I’ve created somewhat boilerplate code for a few use-cases, which is the topic of our blog post. Let’s dive into each of them.

 

Sentiment Classifier

Potential Use-cases: Customer Feedback Analysis, Client Satisfaction Index, Call Centre Real-time Insights

Traditionally, machine learning models are always trained on a bigger dataset for better accuracy along with the right choice of algorithm with some hyperparameters. For example, if you want to build an engine that’d classify a sentiment out of a sentence, you may want to train it on at least 1000 records with a mixture of negative and positive sentiments. This way, the model may achieve as 70-80% of accuracy. I’ve done it in the past with my SentimentAnalyzer package which has already been used 24k times by developers. However, this was a bit of a task for me to train and then integrate it within my applications.

Large language models have changed this all. Now, with the magic of few shot learning, you can easily build a sentiment classifier. This can easily be done using the Completion API with GPT-3.

Below is the syntax on how I did it. You can try it using the notebook.

Sentiment Classifier using Azure OpenAI Service

Remember to initialise a .NET or Python kernel before you run the subsequent steps of the notebook(s)

Summarisation and Translation

Potential Use-cases: Summary of the long emails, translating it from non-English to English and vice versa

Imagine you work in a hospitality services business, and you request your customers to fill a survey at the end of their service. Your customers are both native English speakers and those who speak other languages. You often receive around 100-200 words of feedback and due to the volume, it gets tricky for you to go through each of them. This is where you want to summarise the feedback with their appropriate sentiments and also get the proper translation of it.

Below example is a glimpse of how you’d like to do it.

Summary and Translation with GPT-3.5

Flight Tracker

Potential Use-cases: Flight tracking, postage tracking, food delivery

In 2020, I wrote two posts about how to build a Flight Tracker using Language Understanding Intelligent Service (aka LUIS), which is now upgraded as Language Understanding in the Azure Language Studio. The reason why I brought the similar use-case here is to show you how effective it is to use the power of generative AI to build a much better version of it with less code. 💯

Before we get there, imagine how you’d build it yourself? For this, you may need a source, destination or a flight number. If you do not have either of the locations or just the flight number, then you may not be able to track down the flight. This is at least required information for any flight for a simplest hypothetical use-case.

I have been working with Conversational AI since 2017 and pushed some useful solutions to production since then, I can confirm and you will also appreciate that this is not an easy problem. Your customer (who is an actual user of this bot) is a human. Humans are not naturally accustomed to following a pattern or sequence of the questions, all the time. That’s why there’s a good chance that humans may either provide a flight number, a destination or a source.

In order to solve this problem with Generative AI (Azure OpenAI Service), we just have to provide a good prompt, few shot examples and that’s it. You will be able to see that it works quite well.

Protip: You may get a response returned in JSON or any format you’d like for your use-case. 

Below is the syntax on how I did it. You can try it using the notebook.

Flight Tracker with the Generative AI

DALL-E (Bonus 🎁)

If you look at the last section of the notebook, you will see that I have also created a boilerplate code for you to work with the DALL-E model which is still in preview. This creates an image out of the natural language utterance. Try it out yourself.

Batman working from home. Image generated by DALL-E

The power of generative AI has revolutionised the way we approach problem-solving in various domains. By leveraging these Generative AI notebooks and the advancements in AI technology such as Azure OpenAI Service (GPT-3, GPT-4 and so on), developers can now create more efficient and effective solutions with less code and effort. This blog post highlights the potential of generative AI in use-cases such as sentiment classification, summarization and translation, and flight tracking. As AI continues to evolve, we can expect to see even more innovative applications and streamlined development processes, making it easier for developers to deliver cutting-edge solutions to their users. Embracing these advancements will not only enhance our ability to solve complex problems but also foster a more inclusive and accessible environment for developers across various programming languages and platforms.

Until next time.