สร้าง pipeline สำหรับถาม-ตอบ
ในแบบฝึกหัดที่แล้ว เราดึงข้อความจากเอกสารหลายหน้าด้วย PyPDF และเตรียมไว้เป็น string เดียว
คราวนี้จะสร้าง pipeline สำหรับถาม-ตอบ ด้วย Hugging Face เพื่อค้นหาคำตอบจากเอกสาร
ทั้งโมดูล pipeline และตัวแปร document_text ถูกโหลดไว้ให้แล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การใช้งาน Hugging Face
คำแนะนำการฝึกหัด
- สร้าง pipeline สำหรับถาม-ตอบโดยระบุ task และโมเดลที่ถูกต้อง
- ส่ง question และ
document_textให้กับ pipeline - พิมพ์ผลลัพธ์เพื่อดูคำตอบ
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Load the question-answering pipeline
qa_pipeline = pipeline(task="____", model="distilbert-base-cased-distilled-squad")
question = "What is the notice period for resignation?"
# Get the answer from the QA pipeline
result = qa_pipeline(question=____, context=____)
# Print the answer
print(f"Answer: {result['____']}")