Built to order

Question Answering System using BERT

A reading-comprehension system: paste a passage, ask a question, and get the exact answer span highlighted in the text. It fine-tunes bert-base-uncased (110M parameters, pretrained on BooksCorpus and Wikipedia) on SQuAD v1.1 — 107,785 question-answer pairs over 536 Wikipedia articles — replacing BERT's head with learned start/end span predictors, and evaluates with Exact Match and F1 on the dev split. The demo UI lets you switch passages, ask free-form questions and inspect span confidence. Suitable for B.E./B.Tech final-year projects in Computer Science, AI/ML and Data Science.

Question Answering System using BERT — project thumbnail preview
More project photos (2)

The problem

Search engines retrieve documents; they do not read them. A student researching a topic still opens ten tabs and hunts for the one sentence that answers their question. Reading comprehension — machine understanding of text well enough to answer questions about it — became a measurable science with SQuAD, the Stanford Question Answering Dataset: crowdworkers wrote 107,785 questions on Wikipedia passages and marked the exact span containing each answer. Then BERT showed that a transformer pretrained on raw text could be fine-tuned into a formidable reader: feed it "[CLS] question [SEP] passage [SEP]", and two learned vectors predict where the answer starts and ends. This project builds that complete transfer-learning workflow — SQuAD data pipeline with WordPiece tokenization and sliding windows for long passages, bert-base-uncased fine-tuning with the Hugging Face Transformers library, Exact Match and F1 evaluation on the dev split, and a demo UI where any passage becomes answerable. It is extractive QA: answers come verbatim from the passage, never invented.

How it works

  1. SQuAD v1.1 passages, questions and gold answer spans are loaded; long passages are split into overlapping 384-token windows.
  2. Each (question, passage-window) pair is WordPiece-tokenized into the BERT input format: [CLS] question [SEP] passage [SEP].
  3. bert-base-uncased encodes the sequence into a contextual embedding per token through its 12 transformer layers.
  4. Two learned vectors dot each token embedding to produce start-logits and end-logits — the model's belief about where the answer begins and ends.
  5. The decoder picks the highest-scoring valid span; its text is extracted verbatim from the passage.
  6. On the dev split, predictions are scored with Exact Match (character-perfect spans only) and token-overlap F1 — the notebook logs both.

Tech stack:

  • Python 3.10, PyTorch, Hugging Face Transformers (bert-base-uncased fine-tuning)
  • Hugging Face Datasets (SQuAD v1.1 loading)
  • NumPy, pandas (prediction tables, error analysis)
  • scikit-learn (supporting metrics)
  • Matplotlib, Seaborn (loss curves, span analysis plots)
  • Flask demo app with passage-QA interface
  • Jupyter notebook (buyer-run fine-tuning and evaluation)

Dataset & model

  • Dataset: SQuAD v1.1 — Stanford Question Answering Dataset (Rajpurkar et al., 2016): 107,785 question-answer pairs over 536 Wikipedia articles (~87k train / ~10k dev), every answer guaranteed to be an exact span of its passage; distributed under CC BY-SA 4.0.
  • Model: bert-base-uncased (12 layers, 110M parameters), fine-tuned for extractive QA. Input: ≤384 WordPiece tokens ([CLS] question [SEP] passage [SEP]). Output: start/end logits per token → best valid answer span.
  • Metrics: Exact Match and F1 on the dev split, computed by the notebook during your build. Design target: ~80%+ F1 — a target, not a measured claim.
Parameter Value
Model bert-base-uncased (110M params), fine-tuned for extractive QA
Input Passage (≤384 tokens per window) + free-form question
Dataset SQuAD v1.1 — 107,785 QA pairs, 536 Wikipedia articles
Prediction Start/end span logits → highest-scoring valid span
Evaluation Exact Match + F1 on the dev split — computed during your build
Output Verbatim answer span highlighted in the passage, with confidence
Demo Flask app: passage switcher, question box, span highlighting

Project features

  • Complete SQuAD v1.1 data pipeline: WordPiece tokenization, [CLS]/[SEP] formatting, 384-token sequences with stride-based sliding windows for long passages
  • bert-base-uncased fine-tuning (110M parameters) via Hugging Face Transformers, with the pretrained head replaced by learned start/end span predictors
  • Answer-span decoder that selects the highest-scoring valid span (end ≥ start, max 30 tokens) from the start/end logits
  • Demo QA UI: switch between sample passages or paste your own, ask free-form questions, and see the answer span highlighted with confidence
  • Evaluation notebook computing Exact Match and F1 on the SQuAD dev split, with per-question-length error analysis
  • Confidence-thresholded answering that withholds low-confidence spans instead of guessing blindly
  • Training diagnostics: loss curves, learning-rate schedule and span-length distribution plots for the report

What is included

  • Complete source code (SQuAD pipeline, tokenization, fine-tuning, span decoder, evaluation, demo app)
  • Jupyter fine-tuning and evaluation notebook (buyer-run procedure: fine-tune on SQuAD, evaluate EM/F1 on dev)
  • Project report PDF (QA background, transformer/BERT theory, methodology, results, error analysis)
  • PPT presentation for final review
  • Viva Q&A preparation document (attention, WordPiece, pretraining vs fine-tuning, EM vs F1, span prediction)
  • Setup guide (environment, GPU/CPU options, dataset download, running the demo)

Limitations & prerequisites

  • This is extractive QA: the answer must exist verbatim in the passage. It cannot answer from general knowledge, combine facts across passages, or reason beyond the text.
  • Passages longer than 384 tokens are split with a sliding window, which can cut context mid-answer and is a documented failure mode.
  • SQuAD v1.1 questions are all answerable by construction — the model never learned to say "I don't know"; SQuAD 2.0's unanswerable questions are a documented extension.
  • Adversarial or oddly phrased questions can produce confidently wrong spans; the report's error analysis studies these instead of hiding them.
  • Fine-tuning BERT properly wants a GPU; the notebook documents a CPU-feasible reduced schedule and states the tradeoff openly.
  • Reported EM/F1 are whatever your fine-tuning run measures on the dev split — the ~80% F1 figure is a design target, never a pre-claimed result.

Frequently Asked Questions

Which dataset is used?

SQuAD v1.1 (Rajpurkar et al., Stanford, 2016): 107,785 question-answer pairs over 536 Wikipedia articles, with every answer marked as an exact span of its passage. It is the standard reading-comprehension benchmark.

Why bert-base and not a larger model?

Base (110M parameters) fine-tunes on student-available GPUs in hours and is the canonical teaching setup from the original BERT paper's own SQuAD experiments. Large variants are documented as an optional extension.

Is the F1 score guaranteed?

No. The design target is ~80%+ F1 on the dev split, but your build's notebook measures the real Exact Match and F1 numbers — the report presents those measured results with the training configuration that produced them.

Can it answer questions it was not trained on?

Yes, within limits: fine-tuned BERT generalizes to new passages and questions in the same style. But it only extracts spans from the given passage — ask about something absent from the text and v1.1 training gives it no "no answer" option.

Can I use my own documents?

Yes — the demo accepts any pasted passage, and the report documents the chunking strategy for long documents (sliding windows with stride).

How is this different from a chatbot?

A chatbot generates free text and can hallucinate; this system extracts verbatim spans from a passage you provide, so every answer is traceable to its source sentence — a property the viva discussion can lean on. Suitable for B.E./B.Tech final-year projects in Computer Science, AI/ML and Data Science.

Components & software requirements
  • Python 3.10, PyTorch, Hugging Face Transformers (bert-base-uncased fine-tuning)
  • Hugging Face Datasets (SQuAD v1.1 loading)
  • NumPy, pandas (prediction tables, error analysis)
  • scikit-learn (supporting metrics)
  • Matplotlib, Seaborn (loss curves, span analysis plots)
  • Flask demo app with passage-QA interface
  • Jupyter notebook (buyer-run fine-tuning and evaluation)

Dataset & model

  • Dataset: SQuAD v1.1 — Stanford Question Answering Dataset (Rajpurkar et al., 2016): 107,785 question-answer pairs over 536 Wikipedia articles (~87k train / ~10k dev), every answer guaranteed to be an exact span of its passage; distributed under CC BY-SA 4.0.
  • Model: bert-base-uncased (12 layers, 110M parameters), fine-tuned for extractive QA. Input: ≤384 WordPiece tokens ([CLS] question [SEP] passage [SEP]). Output: start/end logits per token → best valid answer span.
  • Metrics: Exact Match and F1 on the dev split, computed by the notebook during your build. Design target: ~80%+ F1 — a target, not a measured claim.
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 abstract (PDF)

Related guides

All guides
Illustration of object tracking showing video frames with bounding boxes and persistent ID labels following people and vehicles, comparing motion prediction and appearance matching.B.E./B.Tech Computer Science and Electronics students building video analytics projects — people counting, vehicle tracking, sports analysis — who have detection working and need

Object Tracking: DeepSORT and ByteTrack Explained

Detection finds objects per frame; tracking keeps their identities across frames. This guide explains tracking-by-detection, Kalman motion models, DeepSORT's appearance embeddings vs ByteTrack's low-confidence box recovery, tracking metrics (HOTA, IDF1, ID switches), and the tuning parameters that determine real-world quality.

Read guide
Illustration of image segmentation showing U-Net's U-shaped encoder-decoder with skip connections producing pixel masks, alongside Mask R-CNN detecting instances with masks.B.E./B.Tech Computer Science and AI/ML students moving from image classification or detection to pixel-level understanding — medical imaging, defect detection, autonomous driving

Image Segmentation: U-Net and Mask R-CNN

When projects need pixel-level answers, segmentation delivers. This guide explains semantic vs instance vs panoptic segmentation, U-Net's encoder-decoder with skip connections, Mask R-CNN's parallel mask head, Dice and IoU evaluation, paired augmentation, and how to choose the right architecture for your data and question.

Read guide
Illustration of Whisper speech-to-text showing sound waves flowing into a neural network and emerging as transcribed text with timestamps and speaker labels.B.E./B.Tech Computer Science and AI/ML students adding speech-to-text to projects — voice assistants, meeting transcription, accessibility tools

Whisper for Speech-to-Text in Student Projects

Whisper transcribes speech in dozens of languages with no training required. This guide covers how it works, choosing among model sizes, running it locally with faster-whisper, handling hour-long audio, timestamps and speaker diarization, multilingual quirks, and honest evaluation with word error rate.

Read guide
Get a quotation