Update README.md
Browse files
README.md
CHANGED
|
@@ -16,96 +16,196 @@ metrics:
|
|
| 16 |
- f1
|
| 17 |
- precision
|
| 18 |
- recall
|
|
|
|
|
|
|
| 19 |
---
|
| 20 |
|
| 21 |
-
# ParaDetect: AI vs Human Text Detection
|
| 22 |
|
| 23 |
## Model Description
|
| 24 |
|
| 25 |
-
ParaDetect is a fine-tuned DeBERTa-v3-large model using LoRA (Low-Rank Adaptation) for detecting AI-generated vs human-written text. This model achieves
|
| 26 |
|
| 27 |
## Model Details
|
| 28 |
|
| 29 |
-
- **Base Model**: microsoft/deberta-v3-large
|
| 30 |
-
- **Fine-tuning Method**: LoRA (Low-Rank Adaptation)
|
|
|
|
| 31 |
- **Task**: Binary text classification (Human: 0, AI: 1)
|
| 32 |
-
- **Dataset**: AI Text Detection Pile (100K samples)
|
| 33 |
-
- **
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
## Usage
|
| 36 |
|
|
|
|
|
|
|
| 37 |
```python
|
| 38 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 39 |
from peft import PeftModel
|
| 40 |
import torch
|
| 41 |
|
| 42 |
-
# Load
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
| 46 |
|
| 47 |
# Load LoRA adapter
|
| 48 |
-
model = PeftModel.from_pretrained(
|
| 49 |
|
| 50 |
-
#
|
| 51 |
def predict_text_origin(text):
|
| 52 |
-
inputs = tokenizer(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
with torch.no_grad():
|
| 54 |
outputs = model(**inputs)
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
| 59 |
|
| 60 |
return {
|
|
|
|
|
|
|
| 61 |
"human_probability": human_prob,
|
| 62 |
-
"ai_probability": ai_prob
|
| 63 |
-
"prediction": "AI" if ai_prob > human_prob else "Human"
|
| 64 |
}
|
| 65 |
|
| 66 |
# Example usage
|
| 67 |
text = "Your text here..."
|
| 68 |
result = predict_text_origin(text)
|
| 69 |
-
print(result)
|
| 70 |
-
```
|
| 71 |
|
| 72 |
-
|
| 73 |
|
| 74 |
-
|
| 75 |
-
- **Validation Split**: 20%
|
| 76 |
-
- **Training Strategy**: LoRA fine-tuning with r=16, alpha=32
|
| 77 |
-
- **Optimizer**: AdamW with learning rate 3e-4
|
| 78 |
-
- **Epochs**: 3
|
| 79 |
-
- **Batch Size**: 16
|
| 80 |
|
| 81 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
| Accuracy | 99.2% |
|
| 86 |
-
| Precision | 99.1% |
|
| 87 |
-
| Recall | 99.3% |
|
| 88 |
-
| F1-Score | 99.2% |
|
| 89 |
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
-
|
| 93 |
-
- Performance may vary on very short texts (<50 words)
|
| 94 |
-
- May not generalize to newer AI models not seen during training
|
| 95 |
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
-
|
| 99 |
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
@misc{paradetect2024,
|
| 102 |
-
title={ParaDetect: AI vs Human Text Detection},
|
| 103 |
author={Srikanth Gali},
|
| 104 |
year={2024},
|
| 105 |
-
url={https://github.com/srikanthgali/ParaDetect}
|
|
|
|
| 106 |
}
|
| 107 |
-
```
|
| 108 |
-
|
| 109 |
-
## Repository
|
| 110 |
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
- f1
|
| 17 |
- precision
|
| 18 |
- recall
|
| 19 |
+
base_model: microsoft/deberta-v3-large
|
| 20 |
+
model_name: paradetect-deberta-v3-lora
|
| 21 |
---
|
| 22 |
|
| 23 |
+
# ParaDetect: DeBERTa-v3-Large Fine-tuned for AI vs Human Text Detection
|
| 24 |
|
| 25 |
## Model Description
|
| 26 |
|
| 27 |
+
ParaDetect is a fine-tuned DeBERTa-v3-large model using LoRA (Low-Rank Adaptation) for detecting AI-generated vs human-written text. This model achieves ~99% accuracy in distinguishing between human and AI-generated content, making it highly effective for academic integrity, content verification, and research applications.
|
| 28 |
|
| 29 |
## Model Details
|
| 30 |
|
| 31 |
+
- **Base Model**: microsoft/deberta-v3-large (~435M parameters)
|
| 32 |
+
- **Fine-tuning Method**: LoRA (Low-Rank Adaptation)
|
| 33 |
+
- **Trainable Parameters**: ~28M parameters (6% of total)
|
| 34 |
- **Task**: Binary text classification (Human: 0, AI: 1)
|
| 35 |
+
- **Dataset**: AI Text Detection Pile (cleaned, 100K samples)
|
| 36 |
+
- **Training Framework**: Hugging Face Transformers + PEFT
|
| 37 |
+
|
| 38 |
+
## Performance Metrics
|
| 39 |
+
|
| 40 |
+
### Test Set Results
|
| 41 |
+
- **Accuracy**: 99.31%
|
| 42 |
+
- **Precision (Weighted)**: 99.31%
|
| 43 |
+
- **Recall (Weighted)**: 99.31%
|
| 44 |
+
- **F1-Score (Weighted)**: 99.31%
|
| 45 |
+
|
| 46 |
+
### Class-wise Performance
|
| 47 |
+
| Class | Precision | Recall | F1-Score | Support |
|
| 48 |
+
|-------|-----------|---------|----------|---------|
|
| 49 |
+
| **Human (0)** | 99.72% | 98.89% | 99.30% | 7,500 |
|
| 50 |
+
| **AI (1)** | 98.91% | 99.72% | 99.31% | 7,500 |
|
| 51 |
+
|
| 52 |
+
## Training Details
|
| 53 |
+
|
| 54 |
+
### LoRA Configuration
|
| 55 |
+
- **Rank (r)**: 64
|
| 56 |
+
- **Alpha**: 128
|
| 57 |
+
- **Dropout**: 0.1
|
| 58 |
+
- **Target Modules**: query_proj, key_proj, value_proj, dense, output.dense
|
| 59 |
+
- **Bias**: all
|
| 60 |
+
|
| 61 |
+
### Training Parameters
|
| 62 |
+
- **Epochs**: 3 (with early stopping)
|
| 63 |
+
- **Batch Size**: 32 (train/eval)
|
| 64 |
+
- **Learning Rate**: 2e-4
|
| 65 |
+
- **Optimizer**: AdamW
|
| 66 |
+
- **Weight Decay**: 0.01
|
| 67 |
+
- **Warmup Ratio**: 0.1
|
| 68 |
+
- **Max Gradient Norm**: 1.0
|
| 69 |
+
|
| 70 |
+
### Early Stopping
|
| 71 |
+
- **Patience**: 5 evaluation steps
|
| 72 |
+
- **Metric**: F1-score
|
| 73 |
+
- **Threshold**: 0.001
|
| 74 |
|
| 75 |
## Usage
|
| 76 |
|
| 77 |
+
### Quick Start
|
| 78 |
+
|
| 79 |
```python
|
| 80 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 81 |
from peft import PeftModel
|
| 82 |
import torch
|
| 83 |
|
| 84 |
+
# Load tokenizer and base model
|
| 85 |
+
tokenizer = AutoTokenizer.from_pretrained("srikanthgali/paradetect-deberta-v3-lora")
|
| 86 |
+
base_model = AutoModelForSequenceClassification.from_pretrained(
|
| 87 |
+
"microsoft/deberta-v3-large",
|
| 88 |
+
num_labels=2
|
| 89 |
+
)
|
| 90 |
|
| 91 |
# Load LoRA adapter
|
| 92 |
+
model = PeftModel.from_pretrained(base_model, "srikanthgali/paradetect-deberta-v3-lora")
|
| 93 |
|
| 94 |
+
# Prediction function
|
| 95 |
def predict_text_origin(text):
|
| 96 |
+
inputs = tokenizer(
|
| 97 |
+
text,
|
| 98 |
+
return_tensors="pt",
|
| 99 |
+
truncation=True,
|
| 100 |
+
max_length=512,
|
| 101 |
+
padding=True
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
with torch.no_grad():
|
| 105 |
outputs = model(**inputs)
|
| 106 |
+
probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
| 107 |
+
prediction = torch.argmax(probabilities, dim=-1)
|
| 108 |
+
|
| 109 |
+
human_prob = probabilities[0][0].item()
|
| 110 |
+
ai_prob = probabilities[0][1].item()
|
| 111 |
|
| 112 |
return {
|
| 113 |
+
"prediction": "AI" if prediction.item() == 1 else "Human",
|
| 114 |
+
"confidence": max(human_prob, ai_prob),
|
| 115 |
"human_probability": human_prob,
|
| 116 |
+
"ai_probability": ai_prob
|
|
|
|
| 117 |
}
|
| 118 |
|
| 119 |
# Example usage
|
| 120 |
text = "Your text here..."
|
| 121 |
result = predict_text_origin(text)
|
| 122 |
+
print(f"Prediction: {result['prediction']} (Confidence: {result['confidence']:.1%})")
|
|
|
|
| 123 |
|
| 124 |
+
Gradio Interface
|
| 125 |
|
| 126 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
+
# Create interface (see full notebook for complete implementation)
|
| 129 |
+
demo = gr.Interface(
|
| 130 |
+
fn=predict_text_origin,
|
| 131 |
+
inputs=gr.Textbox(lines=10, placeholder="Enter text to analyze..."),
|
| 132 |
+
outputs=[
|
| 133 |
+
gr.Textbox(label="Prediction"),
|
| 134 |
+
gr.Label(label="Confidence Scores")
|
| 135 |
+
],
|
| 136 |
+
title="ParaDetect - AI vs Human Text Detection",
|
| 137 |
+
description="Detect whether text is written by humans or generated by AI"
|
| 138 |
+
)
|
| 139 |
|
| 140 |
+
demo.launch()
|
| 141 |
+
## Technical Specifications
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
|
| 143 |
+
- **Input**: Text (up to 512 tokens)
|
| 144 |
+
- **Output**: Binary classification with confidence scores
|
| 145 |
+
- **Inference Speed**: ~100ms per text
|
| 146 |
+
- **Memory Usage**: Optimized with LoRA (reduced by ~94%)
|
| 147 |
+
- **GPU Support**: CUDA-enabled for faster inference
|
| 148 |
|
| 149 |
+
## Training Dataset
|
|
|
|
|
|
|
| 150 |
|
| 151 |
+
- **Source**: artem9k/ai-text-detection-pile (cleaned)
|
| 152 |
+
- **Size**: 100,000 samples (subset for efficient training)
|
| 153 |
+
- **Split**: 70% train, 15% validation, 15% test
|
| 154 |
+
- **Balance**: Equal distribution of human vs AI text
|
| 155 |
+
- **Text Length**: 10-512 tokens, optimized for 50-500 words
|
| 156 |
+
|
| 157 |
+
## Limitations and Considerations
|
| 158 |
+
|
| 159 |
+
- **Language**: Optimized for English text
|
| 160 |
+
- **Text Length**: Best performance on 50-500 word texts
|
| 161 |
+
- **Domain**: May not generalize to very recent AI models
|
| 162 |
+
- **Context**: Performance may vary on highly technical or domain-specific content
|
| 163 |
+
- **Updates**: Regular retraining recommended as AI models evolve
|
| 164 |
+
|
| 165 |
+
## Intended Use Cases
|
| 166 |
+
|
| 167 |
+
### Primary Applications
|
| 168 |
+
- Academic integrity verification
|
| 169 |
+
- Content authenticity checking
|
| 170 |
+
- Research and analysis
|
| 171 |
+
- Educational demonstrations
|
| 172 |
+
- Journalism and fact-checking
|
| 173 |
+
|
| 174 |
+
### Not Recommended For
|
| 175 |
+
- Legal evidence without human verification
|
| 176 |
+
- Automated content moderation decisions
|
| 177 |
+
- High-stakes authentication without additional validation
|
| 178 |
|
| 179 |
+
## Ethical Considerations
|
| 180 |
|
| 181 |
+
- **Bias**: Model trained on specific dataset; may not represent all text types
|
| 182 |
+
- **Fairness**: Regular evaluation across different demographics recommended
|
| 183 |
+
- **Transparency**: Predictions are probabilistic, not definitive
|
| 184 |
+
- **Human Oversight**: Critical decisions should involve human judgment
|
| 185 |
+
|
| 186 |
+
## Model Card Authors
|
| 187 |
+
|
| 188 |
+
- **Developer**: Srikanth Gali
|
| 189 |
+
- **Organization**: Independent Research
|
| 190 |
+
- **Contact**: [GitHub Repository](https://github.com/srikanthgali/ParaDetect)
|
| 191 |
+
|
| 192 |
+
## Citation
|
| 193 |
@misc{paradetect2024,
|
| 194 |
+
title={ParaDetect: AI vs Human Text Detection with DeBERTa-v3-Large},
|
| 195 |
author={Srikanth Gali},
|
| 196 |
year={2024},
|
| 197 |
+
url={https://github.com/srikanthgali/ParaDetect},
|
| 198 |
+
note={Fine-tuned using LoRA for efficient parameter adaptation}
|
| 199 |
}
|
|
|
|
|
|
|
|
|
|
| 200 |
|
| 201 |
+
## Additional Resources
|
| 202 |
+
- **๐ GitHub Repository**: ParaDetect
|
| 203 |
+
- **๐ Dataset**: AI Text Detection Pile - Cleaned
|
| 204 |
+
- **๐ฏ Demo:**: Gradio Interface
|
| 205 |
+
- **๐ Training Notebook**: Fine-tuning Details
|
| 206 |
+
- **๐ EDA**: Data Analysis
|
| 207 |
+
## Version History
|
| 208 |
+
- **v1.0**: Initial release with DeBERTa-v3-Large + LoRA
|
| 209 |
+
- **Training Date**: 2025-10-06
|
| 210 |
+
- **Model Size**: ~28M trainable parameters
|
| 211 |
+
- **Performance**: 99.31% test accuracy
|