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.
This exercise is part of the course
Natural Language Processing (NLP) in Python
Exercise instructions
- Create a
qa_pipeline
using the"fangyuan/hotpotqa_abstractive"
model with the"text2text-generation"
task. - Use the provided
context
andquestion
to generate an abstractiveanswer
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
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)