Does the text answer the question?
A content moderation team in a large tech company needs to automatically validate whether a passage from a knowledge base answers a customer query. They want to speed up the process using a pre-trained QNLI model to assess the relevance of each response. Your goal is to implement a solution that can classify whether a given passage contains the answer to a specific question.
This exercise is part of the course
Natural Language Processing (NLP) in Python
Exercise instructions
- Initialize a
classifier
pipeline with a suitable QNLI model, such as"cross-encoder/qnli-electra-base"
. - Use this pipeline to evaluate whether the given
passage
answers thequestion
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
from transformers import pipeline
# Initialize the QNLI pipeline
classifier = ____
passage = "Our refund policy allows customers to return any item within 30 days of purchase, provided the item is in its original condition and accompanied by the receipt. Refunds are issued to the original payment method within 5–7 business days."
question = "Can I get a refund if I return a product after 20 days?"
# Get the result
result = ____
print(result)