Q&A पाइपलाइन बनाना
पिछले अभ्यास में, हमने PyPDF का उपयोग करके एक मल्टी-पेज डॉक्यूमेंट से टेक्स्ट निकाला और उसे एक सिंगल स्ट्रिंग के रूप में तैयार किया था.
अब, आप Hugging Face की मदद से एक question-answering पाइपलाइन बनाएँगे ताकि डॉक्यूमेंट से विशिष्ट उत्तर निकाले जा सकें.
pipeline मॉड्यूल और document_text दोनों आपके लिए पहले से लोड किए गए हैं.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Hugging Face के साथ काम करना
अभ्यास निर्देश
- सही task और मॉडल के साथ एक question-answering पाइपलाइन इनिशियलाइज़ करें.
- प्रश्न और
document_textको पाइपलाइन में पास करें. - उत्तर देखने के लिए परिणाम प्रिंट करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# 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['____']}")