เรียกใช้ไปป์ไลน์ QA
ดึงคำตอบจากข้อความตอนหนึ่ง
เรียกใช้ไปป์ไลน์ QA เป็นบทเรียน NLP Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน NLP Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส NLP Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
What a Pipeline Gives You
A Hugging Face pipeline wraps a model and tokenizer into one easy call. You hand it a question and context, it hands back an answer. 🚀
Import the Helper
Everything starts with one import. The pipeline function from the transformers library builds the whole QA stack for you.
from transformers import pipelineCreate a QA Pipeline
Pass the task name question-answering to pipeline. With no model named, it downloads a sensible default for you.
qa = pipeline("question-answering")Give It a Context
The pipeline needs a context: the passage that contains the answer. Think of it as the text the model is allowed to read.
context = "The Eiffel Tower is located in Paris and was completed in 1889."Ask Your Question
Now call the pipeline with both a question and the context. It scans the passage and returns the best matching span.
result = qa(question="Where is the Eiffel Tower?", context=context)Read the Result
The result is a dictionary. The answer text lives under the answer key, ready to print or store.
print(result["answer"]) # ParisThe Confidence Score
Each result also carries a score between 0 and 1. Higher means the model is more sure about its chosen span.
print(result["score"]) # e.g. 0.98Start and End Positions
The result includes start and end character indexes. They tell you exactly where in the context the answer was found.
print(result["start"], result["end"])Choosing a Model
You can pin a specific model by name. A popular small QA model is distilbert fine-tuned on the SQuAD dataset.
qa = pipeline("question-answering",
model="distilbert-base-cased-distilled-squad")Reuse the Same Context
One context can answer many questions. Build the pipeline once, then call it repeatedly with new questions on the same passage.
It Only Reads the Context
Remember: this extractive pipeline answers only from the context you give. Ask about something not in the text and you get a poor span.
Quick Check
Recall how the QA pipeline returns its result.
Recap
One pipeline call takes a question plus context and returns a dict with answer, score, start, and end. You ran extractive QA in three lines. ✅
คำถามที่พบบ่อย
บทเรียน “เรียกใช้ไปป์ไลน์ QA” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “เรียกใช้ไปป์ไลน์ QA” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส NLP Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส NLP Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “เรียกใช้ไปป์ไลน์ QA”
ดึงคำตอบจากข้อความตอนหนึ่ง คุณปฏิบัติ NLP Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน NLP Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน NLP Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน
บทเรียน “เรียกใช้ไปป์ไลน์ QA” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน NLP Academy นี้ได้ไหม
ได้ บทเรียน NLP Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- QA แบบดึงข้อมูลเทียบกับแบบสร้างคำตอบ
- เรียกใช้ไปป์ไลน์ QA
- ค้นหาช่วงคำตอบในบริบท
- จัดการกรณีไม่มีคำตอบและเอกสารยาว