0Pricing
NLP Academy · Lesson

Running a QA Pipeline

Pull answers from a passage.

Running a QA Pipeline is a free NLP Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the NLP Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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 pipeline

Create 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"])  # Paris

The 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.98

Start 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. ✅

Frequently asked questions

Is the “Running a QA Pipeline” lesson free?

Yes — the full text of “Running a QA Pipeline” is free to read here on the web, and the NLP Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the NLP Academy course, upgrade to CoddyKit PRO.

What will I learn in “Running a QA Pipeline”?

Pull answers from a passage. You practise NLP Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start NLP Academy?

No prior experience is required. NLP Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Running a QA Pipeline” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this NLP Academy lesson?

Yes. Every NLP Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Extractive vs Generative QA
  2. Running a QA Pipeline
  3. Finding Answer Spans in Context
  4. Handling No-Answer and Long Docs
← Back to NLP Academy