π― 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