🎯 Accuracy: 93.59% on Out-of-Domain Data
A deep learning system to detect fake product reviews using RoBERTa + Domain Adversarial Training
Features • Installation • Usage • API • Results •
- Features
- Results
- Dataset
- Model Architecture
- Installation
- Usage
- API Endpoints
- Project Structure
- Training
- TensorBoard
| Feature | Description |
|---|---|
| 🧠 RoBERTa Base | State-of-the-art transformer for text understanding |
| 🎯 Domain Adversarial Training | Generalizes to unseen product categories |
| 📊 Linguistic Features | 6 hand-crafted features for enhanced detection |
| 🌐 REST API | FastAPI-powered prediction service |
| 💻 Web Interface | Beautiful, responsive UI for testing |
| 📈 TensorBoard | Real-time training visualization |
| 🚀 Production Ready | Easy to deploy and scale |
Tested on Home & Kitchen category - never seen during training!
| Metric | Score |
|---|---|
| ✅ Accuracy | 93.59% |
| 🎯 Precision | 94% |
| 📈 Recall | 94% |
| ⚖️ F1-Score | 93.86% |
| Class | Precision | Recall | F1-Score | Support |
|---|---|---|---|---|
| Real | 0.98 | 0.89 | 0.93 | 609 |
| Fake | 0.90 | 0.98 | 0.94 | 608 |
| Avg | 0.94 | 0.94 | 0.94 | 1217 |
Predicted
Real Fake
Actual Real 543 66
Fake 12 596
| Property | Value |
|---|---|
| Source | Kaggle - Fake Reviews Dataset |
| Total Reviews | 40,526 |
| Real Reviews | ~20,000 |
| Fake Reviews | ~20,000 |
| Categories | Electronics, Home & Kitchen, etc. |
Input Review
│
▼
┌─────────────────────────────────────┐
│ RoBERTa Encoder │
│ (768-dim output) │
└─────────────────┬───────────────────┘
│
┌────────────┴────────────┐
▼ ▼
┌──────────┐ ┌─────────────┐
│ 768-dim │ │ 6 Ling. │
│ Features │ │ Features │
└────┬─────┘ └──────┬──────┘
│ │
└───────────┬─────────────┘
▼
┌─────────────┐
│ Combined │
│ 774-dim │
└──────┬──────┘
▼
┌───────────────────────┐
│ Label Classifier │
│ Real / Fake │
└───────────────────────┘
- Domain Adversarial Training (DANN) - Gradient Reversal Layer for domain-invariant features
- Linguistic Feature Extraction - 6 features: word count, unique ratio, exclamation ratio, caps ratio, avg word length, question ratio
- Text Preprocessing - URL removal, normalization, focus on content over style
- Python 3.8+
- CUDA (optional, for GPU acceleration)
# Clone the repository
git clone https://github.com/yourusername/fake-review-detection.git
cd fake-review-detection
# Create virtual environment (recommended)
python -m venv venv
source venv/bin/activate # Linux/Mac
# or
.\venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txtThe trained model weights (dann_fixed_best.pth, ~500MB) should be in the project root directory.
python app.pyServer starts at: http://127.0.0.1:8000
Open your browser and navigate to:
http://127.0.0.1:8000/home
from app import predict_review
# Single prediction
result = predict_review("This product is amazing! Best ever!")
print(result)
# Output:
# {
# 'prediction': 'Fake',
# 'confidence': '95.32%',
# 'confidence_value': 95.32,
# 'features': {
# 'exclamation_ratio': 0.05,
# 'caps_ratio': 0.02,
# 'unique_ratio': 0.85
# },
# 'probabilities': {
# 'real': 4.68,
# 'fake': 95.32
# }
# }GET /api/healthResponse:
{
"status": "healthy",
"service": "Review Authenticity Detector",
"version": "2.0",
"model_loaded": true
}POST /reviews
Content-Type: application/json
{
"review": "This product is amazing!"
}Response:
{
"review": "This product is amazing!",
"prediction": "Fake",
"confidence": "95.32%",
"confidence_value": 95.32,
"features": {...},
"probabilities": {...},
"timestamp": "2026-01-30T15:30:00"
}POST /reviews/batch
Content-Type: application/json
{
"reviews": [
"Great product!",
"Okay quality, nothing special",
"BEST PURCHASE EVER!!!"
]
}Response:
{
"results": [...],
"summary": {
"total": 3,
"fake_count": 2,
"real_count": 1,
"fake_percentage": 66.67,
"average_confidence": 87.5
}
}📦 fake-review-detection/
├── 📓 Fake_Review_Detection.ipynb # Training notebook
├── 🌐 app.py # FastAPI server + Web UI
├── 🏗️ models.py # Model architecture
├── 🔧 utils.py # Preprocessing utilities
├── 📋 requirements.txt # Python dependencies
├── 📄 project_report.pdf # PDF report
├── 📊 presentation_slides.pptx # PowerPoint presentation
├── 📖 README.md # This file
├── 📁 static/ # CSS files
│ └── style.css
└── 📁 .git/ # Git repository
- Upload the notebook to Kaggle
- Enable GPU (Tesla P100)
- Run all cells
- Download
dann_fixed_best.pth
| Parameter | Value |
|---|---|
| Max Length | 256 tokens |
| Batch Size | 16 |
| Epochs | 5 |
| Learning Rate | 2e-5 |
| Optimizer | AdamW |
| Scheduler | Linear Warmup |
| Dropout | 0.3 |
| Epoch | Task Loss | Domain Loss | Val Accuracy |
|---|---|---|---|
| 1 | 0.4175 | 1.3891 | 92.06% |
| 2 | 0.1899 | 1.6394 | 94.74% |
| 3 | 0.2067 | 2.0495 | 89.36% |
| 4 | 0.1741 | 2.2763 | 96.24% |
| 5 | 0.1483 | 2.2861 | 95.16% |
Monitor training in real-time:
tensorboard --logdir=./runsOpen: http://localhost:6006
- 📉 Task Loss
- 📉 Domain Loss
- 📈 Validation Accuracy
- 📊 Weight Distributions
| Category | Technologies |
|---|---|
| Deep Learning | PyTorch, HuggingFace Transformers |
| Model | RoBERTa-base (124M parameters) |
| API | FastAPI, Uvicorn, Pydantic |
| Frontend | HTML5, CSS3, JavaScript |
| Visualization | TensorBoard, Matplotlib, Seaborn |
| Data | Pandas, NumPy, Scikit-learn |
- 📊 Kaggle for the dataset
- 🤗 Hugging Face for Transformers library
- 🔥 PyTorch team
- ⚡ FastAPI team
- Liu, Y., et al. "RoBERTa: A Robustly Optimized BERT Pretraining Approach" (2019)
- Ganin, Y., et al. "Domain-Adversarial Training of Neural Networks" JMLR (2016)
⭐ Star this repo if you found it helpful!
Made with ❤️ for Deep Learning Course