0Pricing
NLP Academy · Lesson

Handling No-Answer and Long Docs

Chunking and confidence checks.

Handling No-Answer and Long Docs is a free NLP Academy lesson on CoddyKit — lesson 4 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.

Sometimes There Is No Answer

Real questions often have no answer in the passage. A robust QA system should admit that instead of forcing a wrong guess. 🤔

The Null Answer Idea

Models trained for this learn a null answer option. When no span fits, they point to an empty answer rather than inventing one.

Allowing Empty Answers

In the pipeline, set handle_impossible_answer to true so it can return an empty string when nothing in the context matches.

qa(question=q, context=c,
   handle_impossible_answer=True)

Use the Score as a Gate

The confidence score is your safety gate. If it falls below a threshold you trust, treat the reply as no answer.

if result["score"] < 0.2:
    answer = "I do not know."

Long Documents Break the Limit

Transformers have a fixed max length, often 512 tokens. A long document simply will not fit in one pass.

Chunk the Context

The fix is chunking: split a long document into overlapping windows, then run QA on each window separately.

Why Windows Overlap

Chunks should overlap a little. Otherwise an answer sitting on a chunk boundary could be split and lost between two windows.

Built-In Sliding Window

The QA pipeline can do this for you. Set doc_stride to control how much each window overlaps the previous one.

qa(question=q, context=long_text,
   max_seq_len=384, doc_stride=128)

Combining Chunk Answers

Each chunk yields its own answer and score. You keep the candidate with the highest score across all chunks as the final reply.

Retrieve Before You Read

For huge collections, first retrieve the few most relevant passages, then run QA only on those. This is the heart of larger QA systems.

Honesty Builds Trust

Returning no answer when unsure is a feature, not a flaw. Honest QA earns user trust far more than a confident wrong guess. 🛡️

Quick Check

How do we feed a very long document to a QA model?

Recap

Allow null answers and gate on score for honesty; chunk long docs with overlap, then keep the best-scoring span. You can now ship robust QA. 🎉

Frequently asked questions

Is the “Handling No-Answer and Long Docs” lesson free?

Yes — the full text of “Handling No-Answer and Long Docs” 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 “Handling No-Answer and Long Docs”?

Chunking and confidence checks. 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 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Handling No-Answer and Long Docs” 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