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.
Questo esercizio fa parte del corso
Natural Language Processing (NLP) in Python
Istruzioni dell'esercizio
- Create a
qa_pipelineusing the"fangyuan/hotpotqa_abstractive"model with the"text2text-generation"task. - Use the provided
contextandquestionto generate an abstractiveanswer.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
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)