MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Natural Language Processing (NLP) in Python

Lihat Kursus

Petunjuk latihan

  • 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.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

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 dan Jalankan Kode