Built to order

Extractive Question Answering using BERT (SQuAD)

This project builds a machine-reading system: give it a passage and a question, and it finds the exact text span that answers the question — the SQuAD formulation of question answering. A pretrained BERT model is fine-tuned on SQuAD 1.1's 107,785 question–answer pairs to predict answer start and end positions, evaluated with Exact Match and F1. A live demo lets you pick a passage, ask anything about it, and watch the predicted span light up in the text with its supporting sentence. Suitable for B.E./B.Tech final-year projects in AI & Machine Learning, Computer Science and IT.

Chat on WhatsApp — get a quotation

AI & Machine Learning Jupyter notebookHugging Face DatasetsGitPython 3BERT-baseHTML5 · JavaScript demoPyTorch · TransformersSQuAD 1.1Software
Extractive Question Answering using BERT (SQuAD) — project thumbnail preview
More project photos (3)

The problem

Search engines return documents; question-answering systems return answers. The extractive QA formulation — pioneered by the Stanford Question Answering Dataset (SQuAD) — is beautifully precise: given a passage and a question, predict the exact span of text that answers it. Answering "when was the tower completed?" means finding "March 1889" in the passage, not generating prose. This project fine-tunes BERT-base on SQuAD 1.1 (107,785 question–answer pairs over 536 Wikipedia articles) to predict start- and end-position logits over the passage tokens, the canonical span-prediction setup. The project covers the full modern NLP pipeline — WordPiece tokenization, question–passage packing with segment embeddings, span loss, and the Exact Match / F1 evaluation that the field actually uses — and the demo makes the model's reading visible by highlighting predicted spans in context.

SYSTEM FLOW

4 components 5 connections

Live flow
Drag to explore
100%
userUser

Types a question and provides a passage in the demo.

Follow the working sequence

How it works

  1. SQuAD 1.1 (107,785 QA pairs, 536 Wikipedia articles) is loaded; each example packs as [CLS] question [SEP] passage [SEP] with WordPiece tokens.
  2. Character-level answer spans are aligned to token positions to create start/end training labels.
  3. BERT-base with two classification heads (start logits, end logits) fine-tunes for 2–3 epochs with AdamW and linear warmup.
  4. On the dev set, predicted spans are scored with Exact Match (string equality after normalization) and token-level F1.
  5. Per-question-type analysis (who/when/where/what) shows where the model is strong and where it struggles, for the report.
  6. In the demo, a question and passage are tokenized and run through the saved model; the top-scoring span is highlighted in the passage text.

Tech stack:

  • Python 3, PyTorch, Hugging Face Transformers
  • BERT-base (fine-tuned)
  • SQuAD 1.1 (Stanford)
  • Datasets / tokenizers libraries
  • scikit-learn-style metrics (custom EM/F1)
  • Jupyter Notebook (fine-tuning & evaluation)
  • HTML5 + JavaScript (live demo)

Dataset & model details

  • Dataset: SQuAD 1.1 (Stanford Question Answering Dataset, Rajpurkar et al.) — 107,785 question–answer pairs written by crowdworkers on 536 Wikipedia articles; every answer is an exact span of the passage. Evaluation uses the official dev split.
  • Task: Extractive span prediction; input = (question, passage) token sequence, output = start and end token positions of the answer span.
  • Model: BERT-base-uncased fine-tuned with start/end span heads (2–3 epochs, AdamW, learning rate 3e-5, linear warmup); max sequence length 384, doc stride 128.
  • Metrics: Token-F1 ≥ 0.85 and Exact Match ≥ 0.75 on the dev set (design targets for the built-to-order fine-tuning run). BERT-base on SQuAD 1.1 reports F1 ≈ 0.885 / EM ≈ 0.808 in the original paper; no figure is claimed as measured until the fine-tuning run is executed for the order.
Parameter Value
Input Question + passage (≤ 384 tokens)
Output Answer span (start/end positions)
Training pairs 107,785 (SQuAD 1.1)
Dev F1 ≥ 0.85 (design target, not a measured claim)
Dev Exact Match ≥ 0.75 (design target, not a measured claim)
Fine-tuning time Approximately 1–2 h on a free GPU (expected)
Inference Approximately 80 ms per question on CPU (expected)
Model files Approximately 440 MB (BERT-base weights + tokenizer, expected)
Demo Single-file web app, runs offline after download

Project features

  • [BERT span predictor] BERT-base fine-tuned on SQuAD 1.1 with start/end classification heads over passage tokens.
  • [Live reading demo] Choose a passage, ask a question, and see the predicted answer span highlighted in the text with confidence and the supporting sentence.
  • [Question-type handling] The demo and report cover who/when/where/quantity questions and how span prediction adapts to each.
  • [Full fine-tuning notebook] Tokenization, question–passage packing, span-label alignment, training loop, dev-set evaluation in one reproducible notebook.
  • [EM & F1 evaluation] Exact Match and token-F1 computed exactly as the SQuAD leaderboard does, with per-question-type breakdowns.
  • [Attention visualization notes] Which passage tokens the model attends to when answering, documented qualitatively for the report.
  • [Exported model] Fine-tuned BERT weights plus tokenizer, so new passages and questions work without retraining.

What is included

  • Complete fine-tuning & evaluation Jupyter notebook
  • Fine-tuned BERT weights and tokenizer
  • Live question-answering web demo
  • EM/F1 tables, per-question-type analysis, attention notes
  • Project report PDF (background, transformer/QA theory, methodology, results)
  • PPT presentation for final review
  • Viva Q&A preparation document (self-attention, WordPiece, span loss, EM vs F1, SQuAD 2.0 unanswerable questions)

Limitations & prerequisites

  • Extractive only — the model cannot answer questions whose answer is not literally in the passage; SQuAD 2.0's unanswerable questions are discussed as future scope, not implemented.
  • English Wikipedia-style passages; other domains and languages are out of scope.
  • F1/EM targets are design targets for the fine-tuning run, stated honestly — the report documents actual achieved figures after training.
  • The demo's in-browser extractor is a compact illustration of the pipeline; the full fine-tuned BERT ships separately.
  • Long documents need chunking (doc stride), which can split answers across chunks — noted as a limitation.

Frequently Asked Questions

Which dataset is used and why?

SQuAD 1.1 — 107,785 question–answer pairs on Wikipedia articles, created at Stanford. It defined extractive QA as a field, and its Exact Match / F1 metrics are the standard everyone reports.

How does span prediction work?

BERT reads the packed question+passage and outputs two scores per token: "answer starts here" and "answer ends here." The best-scoring valid span wins — no text generation involved.

What is Exact Match vs F1?

Exact Match requires the predicted span to equal the gold answer exactly (after normalization); F1 gives partial credit for token overlap. Both are reported, as the leaderboard does.

How does the demo find answers without BERT?

The in-browser demo uses a compact span-extraction heuristic (sentence scoring + entity-type priors) to illustrate the pipeline interactively; the shipped deliverable contains the real fine-tuned BERT.

What about unanswerable questions?

SQuAD 2.0 added 50,000 questions with no answer in the passage. This project implements SQuAD 1.1; extending to 2.0's no-answer handling is listed as future scope.

Is this project suitable for a final-year project?

Yes — for AI & Machine Learning, Computer Science and IT programs. It covers transformers end to end — tokenization, fine-tuning, span loss, EM/F1 evaluation — with a demo that makes the model visibly read. Suitable for B.E./B.Tech final-year projects in AI & Machine Learning, Computer Science and IT.

Components & software requirements
  • Python 3, PyTorch, Hugging Face Transformers
  • BERT-base (fine-tuned)
  • SQuAD 1.1 (Stanford)
  • Datasets / tokenizers libraries
  • scikit-learn-style metrics (custom EM/F1)
  • Jupyter Notebook (fine-tuning & evaluation)
  • HTML5 + JavaScript (live demo)

Dataset & model details

  • Dataset: SQuAD 1.1 (Stanford Question Answering Dataset, Rajpurkar et al.) — 107,785 question–answer pairs written by crowdworkers on 536 Wikipedia articles; every answer is an exact span of the passage. Evaluation uses the official dev split.
  • Task: Extractive span prediction; input = (question, passage) token sequence, output = start and end token positions of the answer span.
  • Model: BERT-base-uncased fine-tuned with start/end span heads (2–3 epochs, AdamW, learning rate 3e-5, linear warmup); max sequence length 384, doc stride 128.
  • Metrics: Token-F1 ≥ 0.85 and Exact Match ≥ 0.75 on the dev set (design targets for the built-to-order fine-tuning run). BERT-base on SQuAD 1.1 reports F1 ≈ 0.885 / EM ≈ 0.808 in the original paper; no figure is claimed as measured until the fine-tuning run is executed for the order.
Delivery information

Built-to-order project. Delivery timeline is shared after order confirmation based on current queue.

Support terms

Complete documentation, setup guide, and viva preparation included. Support for setup and explanation provided.

Download free synopsis (PDF)

Enter your name and WhatsApp number — the synopsis PDF downloads immediately. We may send occasional project updates on WhatsApp; no spam.

Get a quotation