Built to order

Paraphrase Detection using Sentence Transformers

This project decides whether two sentences mean the same thing with a siamese Sentence-BERT encoder — both sentences pass through shared BERT weights, mean pooling gives one vector each, and cosine similarity is the verdict. Trained on Quora Question Pairs (404k labeled pairs) with MSRP cross-domain checks, it catches paraphrases that share almost no words, where keyword overlap fails. A validation-tuned threshold with an explicit "uncertain" band keeps borderline calls honest. Suitable for B.E./B.Tech final-year projects in Computer Science, Information Technology and AI/ML.

Paraphrase Detection using Sentence Transformers — project thumbnail preview
More project photos (2)

The problem

Keyword overlap fails at meaning: "How can I improve my English speaking skills?" and "What are the best ways to get better at spoken English?" share almost no words yet are clearly paraphrases. Sentence transformers solve this by embedding whole sentences into a space where paraphrases sit close together. The Quora Question Pairs dataset (404,290 labeled pairs from the duplicate-question challenge) is the large-scale benchmark; MSRP (Dolan and Brockett, Microsoft Research, 5,801 news pairs) is the classic small, carefully-annotated cross-domain check. This project fine-tunes a siamese bert-base encoder on QQP with a contrastive-style objective, tunes the cosine decision threshold on validation (expected optimum near 0.75), and evaluates accuracy/F1 on a held-out test split — with near-boundary scores flagged "uncertain" instead of forced.

How it works

  1. Both sentences are encoded by the same bert-base (siamese, shared weights).
  2. Mean pooling over token embeddings gives one 768-dim vector per sentence.
  3. Cosine similarity between the two vectors measures meaning overlap.
  4. Fine-tuning uses a contrastive-style objective: duplicates pulled together, non-duplicates pushed apart (QQP).
  5. The decision threshold is swept on the validation split to maximize F1 (≈0.75 expected).
  6. Final evaluation reports accuracy and F1 on the held-out QQP test split plus MSRP cross-domain accuracy.

Tech stack:

  • Python 3.10, PyTorch
  • sentence-transformers, Hugging Face transformers
  • Quora Question Pairs (404k pairs)
  • MSRP (Microsoft Research)
  • Cosine similarity + threshold tuning
  • FastAPI/Flask (inference API)
  • HTML/CSS/JavaScript (demo UI)
  • Git

Dataset & Model Details

  • Dataset: Quora Question Pairs — 404,290 labeled duplicate/not-duplicate pairs (~37% duplicates), from the Quora duplicate-question challenge; MSRP — Microsoft Research Paraphrase Corpus (Dolan & Brockett), 5,801 news-domain pairs, for cross-domain checks. Split: train / validation / held-out test.
  • Model input: two sentences. Output: cosine similarity score + paraphrase verdict.
  • Architecture: siamese bert-base (shared weights) → mean pooling → 768-dim vectors → cosine similarity; contrastive-style fine-tuning on QQP; threshold tuned on validation (≈0.75); 0.65-0.80 flagged uncertain.
  • Metric: accuracy + F1 on the held-out QQP test split; MSRP accuracy as cross-domain sanity check — measured after training. No figure is claimed before the fine-tuning run.
Parameter Value
Task Binary paraphrase / duplicate detection
Encoder Siamese bert-base, mean pooling
Embedding 768-dim per sentence
Threshold ≈0.75, validation-tuned
Uncertain band 0.65-0.80
Inference CPU-friendly
Demo Pair compare + gauge + API

Project features

  • [Siamese SBERT encoder] Shared-weight bert-base with mean pooling → 768-dim sentence vectors.
  • [Cosine decision rule] Similarity ≥ 0.75 (validation-tuned) → paraphrase; below → not.
  • [Uncertain band] Scores 0.65-0.80 flagged "uncertain" rather than forced into a class — a deliberate product decision.
  • [Overlap-vs-embedding contrast] Demo shows Jaccard word overlap next to embedding similarity on the same pair.
  • [Tricky-pair presets] Word-sense ambiguity ("bank") and clear negatives document honest failure modes.
  • [Threshold sweep] Validation F1 swept across thresholds; the chosen operating point is justified with a curve.
  • [Inference API] REST endpoint scoring arbitrary sentence pairs for integration.

What is included

  • Fine-tuning notebook (siamese training, threshold sweep, evaluation)
  • Threshold-tuning script with F1 curve
  • Trained encoder weights
  • Inference API (pair scoring as JSON)
  • Test-set evaluation: accuracy/F1 on QQP + MSRP numbers from the actual run
  • Web demo (compare UI, score gauge, tricky-pair presets)
  • Project report PDF (methodology, threshold analysis, measured results)
  • PPT presentation for final review
  • Viva Q&A preparation document

Limitations & prerequisites

  • Sentence-level only; paragraph/document similarity needs aggregation (future scope).
  • Word-sense traps ("bank" as river vs. institution) still fool it — documented with examples.
  • Negation and subtle scope differences ("all" vs. "some") are known weak spots.
  • QQP is question-domain; other domains need the MSRP-style cross-check the report includes.
  • GPU recommended for fine-tuning; inference runs on CPU.

Frequently Asked Questions

Why not just count common words?

Because paraphrases often share few words. The demo's canonical pair scores 0.18 on word overlap but 0.91 on embedding similarity — that gap is the project's entire motivation.

What is a siamese encoder?

One BERT whose weights are shared across both sentences, so both land in the same vector space and cosine similarity is meaningful. Mean pooling turns token vectors into one sentence vector.

What data does it train on?

Quora Question Pairs (404k labeled pairs) for training, with MSRP (5.8k news pairs) as the cross-domain sanity check.

How is the 0.75 threshold chosen?

By sweeping candidate thresholds on the validation split and picking the F1 maximum — the notebook plots the curve, so the operating point is justified, not guessed.

What does "uncertain" mean?

Scores in 0.65-0.80 sit near the decision boundary; the shipped system flags these for human review instead of forcing a class — the report justifies this product decision.

Is this project suitable for a final-year project?

Yes — for Computer Science, IT and AI/ML programs. It teaches representation learning, contrastive training, threshold methodology and cross-domain evaluation on real benchmarks. Suitable for B.E./B.Tech final-year projects in Computer Science, Information Technology and AI/ML.

Components & software requirements
  • Python 3.10, PyTorch
  • sentence-transformers, Hugging Face transformers
  • Quora Question Pairs (404k pairs)
  • MSRP (Microsoft Research)
  • Cosine similarity + threshold tuning
  • FastAPI/Flask (inference API)
  • HTML/CSS/JavaScript (demo UI)
  • Git

Dataset & Model Details

  • Dataset: Quora Question Pairs — 404,290 labeled duplicate/not-duplicate pairs (~37% duplicates), from the Quora duplicate-question challenge; MSRP — Microsoft Research Paraphrase Corpus (Dolan & Brockett), 5,801 news-domain pairs, for cross-domain checks. Split: train / validation / held-out test.
  • Model input: two sentences. Output: cosine similarity score + paraphrase verdict.
  • Architecture: siamese bert-base (shared weights) → mean pooling → 768-dim vectors → cosine similarity; contrastive-style fine-tuning on QQP; threshold tuned on validation (≈0.75); 0.65-0.80 flagged uncertain.
  • Metric: accuracy + F1 on the held-out QQP test split; MSRP accuracy as cross-domain sanity check — measured after training. No figure is claimed before the fine-tuning run.
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