Azure Cognitive Services

Questions & Answers

  • AZURE CS A&Q
  • 10 Nov 2024
  • blog

Azure Cognitive Services - Questions & Answers

As you know, here at AppGenie, we're a multi-cloud app dev practice. While we love working with Salesforce (obviously!), we’re all about diving into other technologies as well, and today, we’re turning our attention to Azure Cognitive Service for Language and the Question Answering capability (previously called LUIS or Language Understanding)

So, what is a Languages Services, Question Answering, LUIS?

In short, it’s a way of teaching machines how to understand human language. But it’s not just about tossing text into an algorithm and calling it a day. Question Answering takes input, like text or voice commands, and breaks it down into something the system can work with. It identifies things like user intent, key entities (names, dates, locations, etc.), and context, making interactions with machines feel a whole lot more human. And this matters because, let’s face it, nobody wants to chat with a bot that doesn’t get what they’re saying.
From here on out – Question Answering from Azure Cognitive Service for Language is going to get shortened significantly to ACLQA!

Let’s break down how ACLQA makes that happen and why it could be a game changer for your next app or bot project. Our example is arbitrarily simple – were adding the ability to find a song title based on some search parameters using ACLQA, to do this we'll set up a webpage where users can type in partial song lyrics, an album name, or artist name. Then we will process this input, identify the user's intent (like finding a song or artist), and then call the Genius API to retrieve the matching song title and lyrics.
To keep this example short Ill focus on the first part of the problem and leave the actuall coding solution for another post. So lets focus on setting up Azure Question Answering.

Setting Up Azure Question Answering

The Question Answering service allows you to upload documents or provide content that the AI can refer to in order to answer user questions. We’ll use this service to enable the AI to understand and respond to queries like:

  • "What are the lyrics to [song title]?
  • "Who sings [song name]?
  • "Give me the lyrics for the song [partial lyric]?
This service takes care of understanding user queries without needing to train your own model, as you would with LUIS.

Lets get started with our step by step.

  • Create an Azure Account and Set Up Question Answering:
    Head to the Azure Portal, and create an Azure Cognitive Services resource.
  • Select Custom Question Answering as the service:
  • Continue through the Wizard:
    Follow your nose for the rest of the selections – if youre just starting out use the Free Tier and 3 Indexes as this will get you up and running at a minimal cost.
  • On Completion:
    On completion of the deployment go to your new “Language” service, | Overview as you will need the Keys and the endpoint.
You can now define your knowledge base, in our example were not using the actual knwoledge features - were after the Qamp;A part of the service. If youre actually interested in setting up your own knowledge base and Q&A content you would now "Connect your data" or go to "Search" service and do the same. The data sources available are focused on the Microsoft stack but that’s to be expected, fortunately Azure blob storage is supported so if you’re like us and have Terra-bytes of data in S3 you can expose this – it takes a little work but AWS Lambda triggers are your friend when it comes to this kind of heavy lifting.

To use Azure Question & Answering, you need to provide it with relevant information for us this is the Questions & Answers so Go to the “Language service you just created open "Language Studio"".

Setting Up Azure Question Answering

Language Studio is a stand alone application that allows you to create your Language content, at this point its an emergent product and Language Studio feels a little less like a unified experience and more like an add on so if you want to avoid the mire of helpful marketing just open this link https://language.cognitive.azure.com/home

The first thing you have to do is connect your new Cognitive Service, fortunately your prompted to do this in the in App guidance but for those who never read this or cant manage the 4 pages …. Under your account (top right corener) information there’s an option to Select a resource.

Setting up the Resource is quick and easy, just make sure you choose Language resource type
Once you’re hooked up – Create a new Project, for this one you should use a Custom question answering project.
From there thigs start getting real, follow the prompts but for brevity here are the questions you need to answer. How many languages do you want to support, were doing a simple PoC style here so I just selected English
Then your basic information – Name, Description and a No answer prompt – just use the defaults, you can always change these later
At this stage you’re prompted to start adding your knowledge base, as per the data sources in the “Search service” this is all about analysing large volumes of data – we actually don’t want this in our example.
What we DO want to do is provide a set of question and answers that we can use – that’s because were going to get our Answer service to work out what our users are asking for!

How does ACLQA Work?

Were using a subset of capabilities heres so how is ACLQA supposed to work, to generate automated answers with flexibility to handle variations in how questions are asked?

  • Ask a Question:
    You send a question to the Answer Services API, let’s say, “What are the business hours?”.
  • Knowledge Lookup:
    The service searches your knowledge base: This knowledge base is a collection of question-answer (Q&A) pairs that you’ve already set up. You’ve likely uploaded FAQs or documents containing relevant info.
  • Question Match:
    It matches your question with a response: Using AI-driven natural language processing,
  • Finds match Response:
    ACL finds the most relevant answer in your Q&A pairs, even if your question is worded differently than the original (e.g., you ask “When are you open?” but the knowledge base answer is for “business hours”).
  • Returns Response:
    It returns the response that best matches, “We’re open from 9 AM to 5 PM on weekdays.”
  • Optionally:
    You can set a confidence score threshold so responses only return if they’re confident enough and customise Q&A pairs to improve accuracy.
What were going to do is only utilise the Question and Answer capabilties:
  • Ask a Question:
    You send a question to the Answer Services API, let’s say, “What are the lyrics for that Beers song from that band from NZ?”.
  • Question Match:
    The searches will be interpreted by the A to match a Q&A pair – when it does this there will be no matching content so it will only return the QA response.
Why are we doing this? Because we want the QA engine to resolve our question for us – we can sort the response next.

Adding Questions

Lets add our questions and test the responses. Firstly lyrics

Ive only added a couple of questions to illustrate some important points.
Once you’ve saved them you can test out the accuracy by clicking the beaker option.
After testing we discover that our propms arent so usefull
Before we start adding hundreds of question variations lets first give our QA service some more data to work with – when we use natural language we use a significant number of similes – for example the word singer according to merriam-webster https://www.merriam-webster.com/thesaurus/singer has 23 of them.
Lets see what adding these Synonyms does in terms of our success rates, to do this click Synonyms
Click Add then start adding your synonyms, you can import and export these options as well this make you’re life a little easier.
Given that no one asks who warbles a song – lets go for a more modern idiom
This time our test returns something more meaningful
Awesome lets just add more variations, you can go crazy and add every option you can think of – there’s even import and export options to allow this – just keep testing until you get the response you are after.

Limitations?

Okay so now the bad news – Cognitive Services is NOT machine learning, so it does not out of the box learn from answers that are correct or not. However, there are ways to improve and fine-tune the system over time. Here’s how you can manage and enhance its accuracy:

  • Manual Training:
    Azure Answer Services requires some manual tuning. You can use the feedback and analytics tools in the Azure portal to see which questions received inaccurate or lower-confidence answers. Based on this, you can refine your Q&A pairs or add variations to existing questions that might better capture common phrasings users might use.
  • Alternate Questions and Variations:
    : If you see a recurring issue where users phrase questions differently, you can add these variations directly into your knowledge base under each Q&A pair. This helps the service better understand different phrasings for the same intent.
  • Active Learning (Semi-Automated Improvement):
    Azure does offer an “Active Learning” feature. This doesn’t directly learn from correct answers, but it collects usage patterns and highlights questions that often receive low-confidence responses or are marked incorrect by users. It then suggests modifications, such as adding alternative phrasings or clarifying ambiguous Q&A pairs.
  • Regular Retraining:
    Periodically retraining and updating your Q&A pairs helps. Even though it doesn’t learn autonomously, updating based on insights you gather (like common low-confidence questions) can help make it more accurate over time.
If you need fully automated, adaptive learning without frequent manual intervention, you might look at adding a layer of custom AI or machine learning models to complement the Azure Answer Service.

Summary

Using the ACLQA approach, provides us with a Question and Answer. However, it does not identify intent (unlike LUIS which it has replaced). This is a serious problem, given that with the current approach, significant text manipulation is required to resolve this.
If youre after intent resolution - theres easier ways to do this – Ill save that post for next month.
And if youre interested in the Answer - then Beers by Deja Voodoo https://www.youtube.com/watch?v=FfNIOlX-K0s
As always thanks for reading and reach out if you need any help.