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
- Both sentences are encoded by the same bert-base (siamese, shared weights).
- Mean pooling over token embeddings gives one 768-dim vector per sentence.
- Cosine similarity between the two vectors measures meaning overlap.
- Fine-tuning uses a contrastive-style objective: duplicates pulled together, non-duplicates pushed apart (QQP).
- The decision threshold is swept on the validation split to maximize F1 (≈0.75 expected).
- 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.