MulaiMulai sekarang secara gratis

Generating natural answers with abstractive QA

Customer support chatbots aim to provide helpful, conversational answers, not just exact text snippets. To achieve this, they use abstractive question answering, which generates concise and fluent responses based on the context. Your task is to apply Hugging Face's "text2text-generation" pipeline with a model trained for abstractive QA to create natural answers from product information.

Latihan ini adalah bagian dari kursus

Natural Language Processing (NLP) in Python

Lihat Kursus

Petunjuk latihan

  • Create a qa_pipeline using the "fangyuan/hotpotqa_abstractive" model with the "text2text-generation" task.
  • Use the provided context and question to generate an abstractive answer.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

from transformers import pipeline

# Create the abstractive 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?"

# Generate abstractive answer
result = qa_pipeline(f"____: {____} ____: {____}")
print(result)
Edit dan Jalankan Kode