Get startedGet started for free

Answering questions from product descriptions

An online retailer wants to improve its customer support by automatically answering common questions about products using their descriptions. Your task is to use a Hugging Face pipeline to extract precise answers from a product description based on customer queries.

This exercise is part of the course

Natural Language Processing (NLP) in Python

View Course

Exercise instructions

  • Create a qa_pipeline using the "distilbert/distilbert-base-cased-distilled-squad" model for question answering.
  • Use the provided context (product description) and question to get an answer.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

from transformers import pipeline

# Create the question-answering pipeline
qa_pipeline = pipeline(
    task="____",
    model="____"
)

context = """This smartphone features a 6.5-inch OLED display, 128GB of storage, and a 48MP camera with night mode. It supports 5G connectivity and has a battery life of up to 24 hours."""

question = "What is the size of the smartphone's display?"

# Get the answer
result = ____
print(result)
Edit and Run Code