ตอบคำถามจากคำอธิบายสินค้า
ผู้ค้าปลีกออนไลน์รายหนึ่งต้องการยกระดับการสนับสนุนลูกค้า ด้วยการตอบคำถามที่พบบ่อยเกี่ยวกับสินค้าโดยอัตโนมัติจากคำอธิบายสินค้า งานของคุณคือใช้ Hugging Face pipeline เพื่อดึงคำตอบที่แม่นยำจากคำอธิบายสินค้าตามคำถามของลูกค้า
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การประมวลผลภาษาธรรมชาติ (NLP) ด้วย Python
คำแนะนำการฝึกหัด
- สร้าง
qa_pipelineโดยใช้โมเดล"distilbert/distilbert-base-cased-distilled-squad"สำหรับการตอบคำถาม - ใช้
context(คำอธิบายสินค้า) และquestionที่กำหนดให้ เพื่อรับคำตอบ
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
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)