Q&A Model

Pratima Rathore
5 min readJul 25, 2023

--

Unlocking the basics of Q&A Models

Question-answering (QA) models are a type of natural language processing (NLP) model that can answer questions posed in natural language. QA models are trained on a large corpus of text, and they can use this training data to understand the meaning of questions and to find the answers to those questions in the text.

The nature of the answer, whether it is directly extracted from the text or generated anew, depends on the type of model employed.

QA models are used in a wide variety of applications, including:

  • Search engines
  • Chatbots
  • Virtual assistants

QA models are a powerful tool that can be used to improve the way we access and interact with information.

Question Answering variants

QA systems vary in their answer creation methods:

  1. Extractive QA: In this approach, the model directly retrieves the answer from the provided context and presents it to the user. This type of QA is commonly solved using BERT-like models.
  2. Generative QA: Contrasting with extractive QA, generative QA involves the model generating free-form text as the answer, directly based on the given context. This method relies on Text Generation models.

Furthermore, QA systems differ in the source of their answers:

  1. Open QA: Here, the answer is extracted from a context, similar to extractive QA.
  2. Closed QA: In contrast, closed QA does not receive any context for answering. The model generates the entire answer autonomously without external context.

Various components of QA Model

Indexed data (document store/vector database) i.e. External Knowledge

Indexed data storage is a way to organize documents so that they can be quickly retrieved when a question is asked. This is done by creating indexes of the documents, which are essentially lists of the words and phrases that appear in the documents. When a question is asked, the model can use the indexes to quickly find documents that are likely to contain the answer to the question.Some popular indexed data storage systems include Elasticsearch, Solr, and MongoDB.

A vector database is a type of document store that stores documents as vectors. The vectors for different words and phrases are similar to each other if the words and phrases have similar meanings.Some popular vector databases include Pincone, Chrome, and Wiavate.

Retriever

A retriever is responsible for retrieving the most relevant documents from a knowledge base that are likely to contain the answer to a given question i.e. it retrieves a set of contexts for our QA model to extract answers.

Reader

A reader is responsible for extracting the answer from the retrieved documents/set of Contexts. Using the Reader’s model alone solves the reading comprehension (RC) QA task, but if it is used with the Retriever model, we have the Open-Domain QA model.

Generator

Generator does not extract the answer to a question from a context. Instead, it generates text directly to answer the question. This is done by using a language model, such as GPT-3. The language model is trained on a large dataset of text, and it can be used to generate text that is relevant to the question.The context can be optionally provided to the model. If the context is provided, the model will use the context to generate a more informative and accurate answer. However, the model can also generate an answer without the context.

This type of model is known as a generative question answering (QA) model. Generative QA models are a powerful approach to QA because they can generate answers to questions that are not explicitly mentioned in the context. This makes them well-suited for open-domain QA tasks.

Retriever — Reader (Open-book Extractive QA)

The retriever takes the question and context, which is indexed in the database. It creates a query vector(vector representation) that is compared against all indexed context vectors in the database and returns the (n) most similar contexts. The reader model then takes in the most similar contexts and the question to provide a span selection of the answer.

If using Huggingface Library for inference, it falls under -

question-answering

Retriever — Generator (Open-book Abstractive QA)

In this system, reader model is replaced with a generator model. The generator model utilizes the question, along with the provided contexts and knowledge, to produce answers. This approach is referred to as abstractive question-answering and is termed “open-book” because the data source is external.The system is employed to address more conceptual questions that do not demand precise responses. Consequently, the answers it provides are more in the form of suggestions or opinions rather than direct, verbatim answers.

If using Huggingface Library for inference, it falls under-

text2text-generation

Generator (Closed-book Abstractive QA)

This architecture is known as closed-book abstractive QA since it relies solely on the model’s internal knowledge to generate answers. The retriever and reader models are removed, and the generative model handles the answers.

If using Huggingface Library for inference, it falls under-

text-generation

Conclusion

I hope this article was a useful walkthrough around QA models basics.This article breaks down different types of question-answering (QA) models and how they are categorized. It also discusses different approaches to solving QA tasks.

If you liked the article, show your support by clapping for this article. Follow me and lets unravel the mysteries and unleash the potential of AI. Feel free to connect with me on LinkedIn as well!

Citations

https://www.pinecone.io/learn/series/nlp/question-answering/

https://mantiumai.com/blog/understanding-question-answering/

https://lilianweng.github.io/posts/2020-10-29-odqa/

--

--