top of page
  • Writer's pictureAlibek Jakupov

Azure Custom Question Answering : Personal Experience

Azure question answering is a cloud-based solution that uses Natural Language Processing (NLP) to enable a conversational layer over your data. Its purpose is to identify suitable answers from customer input or project data. This technology is often employed in the development of conversational client applications such as chatbots, speech-enabled desktop applications, and social media apps. It offers several features, including deep learning ranker for enhanced relevance, precise answers, and comprehensive region support.

Question answering is composed of two distinct capabilities:

  • Custom question answering: This allows users to tailor various aspects of their content source, such as editing question and answer pairs, defining synonyms and metadata, accepting question suggestions, among others.

  • Prebuilt question answering: This capability permits users to obtain responses by querying a text passage without having to oversee knowledgebases.

I've recently created a law bot and published it to Telegram. Even thought there is a lot of room for improvement, I find it important to share my experience of setting my very first bot up and running. Up we go!

Get the Data

  • Question answering is ideal when you have static information in your custom project, which may be in the form of PDFs or URLs.

  • If you need to provide the same answer to multiple requests, question answering is an effective solution.

  • When you want to filter static information based on metadata tags, question answering can provide additional filtering options such as content type, purpose, and freshness.

  • If you need to manage a bot conversation that includes static information, question answering can take a user's text or command and provide relevant answers based on pre-determined conversation flows, represented in your project with multi-turn context.

So the Kazakhstan Labor Code seemed as a perfect match. Which is great about this data source is the fact that it is mostly static, and doesn't change every day.

Moreover, as the bot may be of a great help to lawyers and other users I decided to add the Criminal and Tax codes, as well as the Constitution. Fortunately, these are publicly available data sources.

Enable the Question Answering feature

When you start a new Custom Question answering project, you will need to access a language resource that has the custom question answering feature enabled. Please ensure that you have your Azure Active Directory ID, Subscription, and the name of the language resource you selected when you created it.

Don't forget to create a Cognitive Search service beforehand, as the Custom Question Answering will store its knowledge base as a search index.

Creating your knowledge base

Here are the steps you should follow:

  1. Log in to the Language Studio using your Azure credentials.

  2. Scroll down to the "Answer questions" section and click on "Open custom question answering".

  3. If your resource is not yet connected to Azure Search, click on "Connect to Azure Search". This will open a new browser tab to the Features pane of your resource in the Azure portal.

  4. Choose "Enable custom question answering", select the Azure Search resource you want to link to, and then click on "Apply".

  5. Go back to the Language Studio tab. You may need to refresh the page for the changes to register. Finally, click on "Create new project".

  6. Select the option "I want to set the language for all projects created in this resource," then choose the language you want and click "Next".

  7. Enter "Sample-project" as the project name, "My first question answering project" as the description, and leave the default answer setting as "No answer found".

  8. Review your choices and click on "Create project".

  9. On the "Manage sources" page, click on "Add source" and select "File".

Some notes

  • Unfortunately, there's no kazakh language support

  • For all the resources you create, you will need to keep them in the same region, otherwise you will have an error deploying your bot (at the final step)

Here's what my knowledge base looks like. Let's start with the Constitution:

Only 5 question-answer pairs generated...

Let's have a look on the Tax code:

365 questions generated, not too shabby!

Labor Code

53 question-answers. Okay...

And the Criminal Code

3(!) questions. Well, maybe the Criminal Code is this simple.

Now you can test your knowledge base.

  1. Select the link to the source you added, which will open the "Edit project" page.

  2. Click on "Test" from the menu bar.

  3. Type in the question concerning some law issue in the search bar and hit enter.

  4. An answer will be generated based on the question-answer pairs that were automatically identified and extracted from your source URL.

Deploy the project

Here are the steps you should follow:

  1. Click on the "Deploy project" icon to enter the "Deploy project" menu.

  2. Click on "Deploy".

  3. When prompted, click on "Deploy" again.

  4. This will move the contents of your project from the test index to a production index in Azure Search.

Your project is now successfully deployed. You can use the endpoint to answer questions in your own custom application to answer or in a bot. Simply click on the deploy bot, and it will create an App Service, Service Plan and Bot service for you. Note, that you'll need to manually copy the Language API key into the App service. It's supposed to be populated automatically, but it didn't work out on my tenant.

Once the bot service is created, you can give it a try using the web chat. Firstly check whether your web app is healthy, only after that you can go creating your Telegram bot.

Now follow these steps to create a telegram bot

  1. Open Telegram and search for BotFather in the search bar.

  2. Click on the "Start" button to begin chatting with BotFather.

  3. Type "/newbot" to create a new bot.

  4. BotFather will ask you to choose a name for your bot. This name will be displayed in contacts and in the chat list.

  5. After selecting a name, BotFather will ask you to choose a username for your bot. This username must end in "bot" and must be unique.

  6. Once you have selected a username, BotFather will give you an API token. This token is used to authenticate your bot to the Telegram API.

  7. Save the API token in a safe place, as you will need it later to integrate your bot with Telegram.

And this is it. Go to channels, and then simply select Telegram from the list and paste your API token. As my documents are too large, so are the answers, this is why I keep having a short response, and then an error message "The bot encountered an error or bug. To continue to run this bot, please fix the bot source code". My guess is that it is due to the message size, which is not well suited to the Telegram format.

What are Azure Resources created?

  • Language

  • Azure Bot

  • Managed Identity

  • App Service

  • App Service plan

  • Search service


I hope you found the tutorial useful. To sum up, I would like to mention, that Azure Custom Question answering is not like a generative language model. It will break your document into question-answer pairs. Whenever you enter your prompt it will simply look for the most similar questions in the knowledge base, nothing more.

423 views0 comments


bottom of page