Upload folder using huggingface_hub
Browse files- .gitattributes +4 -0
- README.md +233 -0
- TRAINING_SUMMARY.md +162 -0
- added_tokens.json +3 -0
- calibration.png +3 -0
- config.json +53 -0
- confusion_matrix.png +3 -0
- improved_classification_report.txt +40 -0
- inference_example.py +86 -0
- label_mapping.json +21 -0
- model.safetensors +3 -0
- model_card.md +48 -0
- pr_curves.png +3 -0
- recommended_thresholds.json +44 -0
- roc_curves.png +3 -0
- special_tokens_map.json +15 -0
- spm.model +3 -0
- tokenizer.json +0 -0
- tokenizer_config.json +59 -0
- training_args.bin +3 -0
- verify_model.py +181 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,7 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
calibration.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
confusion_matrix.png filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
pr_curves.png filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
roc_curves.png filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
license: apache-2.0
|
| 5 |
+
base_model: microsoft/deberta-v3-small
|
| 6 |
+
tags:
|
| 7 |
+
- text-classification
|
| 8 |
+
- literary-analysis
|
| 9 |
+
- content-moderation
|
| 10 |
+
- explicitness-detection
|
| 11 |
+
- deberta-v3
|
| 12 |
+
- pytorch
|
| 13 |
+
- focal-loss
|
| 14 |
+
pipeline_tag: text-classification
|
| 15 |
+
model-index:
|
| 16 |
+
- name: deberta-v3-small-explicit-classifier-v2
|
| 17 |
+
results:
|
| 18 |
+
- task:
|
| 19 |
+
type: text-classification
|
| 20 |
+
name: Literary Explicitness Classification
|
| 21 |
+
dataset:
|
| 22 |
+
name: Custom Literary Dataset (Deduplicated)
|
| 23 |
+
type: custom
|
| 24 |
+
metrics:
|
| 25 |
+
- type: accuracy
|
| 26 |
+
value: 0.818
|
| 27 |
+
name: Accuracy
|
| 28 |
+
- type: f1
|
| 29 |
+
value: 0.754
|
| 30 |
+
name: Macro F1
|
| 31 |
+
- type: f1
|
| 32 |
+
value: 0.816
|
| 33 |
+
name: Weighted F1
|
| 34 |
+
widget:
|
| 35 |
+
- text: "Content warning: This story contains mature themes including explicit sexual content and violence."
|
| 36 |
+
example_title: "Content Disclaimer"
|
| 37 |
+
- text: "His hand lingered on hers as he helped her from the carriage, their fingers intertwining despite propriety."
|
| 38 |
+
example_title: "Suggestive Romance"
|
| 39 |
+
- text: "She gasped as he traced kisses down her neck, his hands exploring the curves of her body with growing urgency."
|
| 40 |
+
example_title: "Explicit Sexual"
|
| 41 |
+
- text: "The morning mist drifted across the Yorkshire moors as Elizabeth walked the familiar path to the village."
|
| 42 |
+
example_title: "Non-Explicit Literary"
|
| 43 |
+
---
|
| 44 |
+
|
| 45 |
+
# Literary Content Classifier - DeBERTa v3 Small (v2.0)
|
| 46 |
+
|
| 47 |
+
An improved fine-tuned DeBERTa-v3-small model for sophisticated literary content analysis across 7 categories of explicitness. This v2.0 model features **significant improvements** over the original, including focal loss training, extended epochs, and data quality enhancements.
|
| 48 |
+
|
| 49 |
+
## π Key Improvements in v2.0
|
| 50 |
+
|
| 51 |
+
- **+4.5% accuracy improvement** (81.8% vs 77.3%)
|
| 52 |
+
- **+6.4% macro F1 improvement** (0.754 vs 0.709)
|
| 53 |
+
- **+21% improvement on violent content** (F1: 0.581 vs 0.478)
|
| 54 |
+
- **+19% improvement on suggestive content** (F1: 0.476 vs 0.400)
|
| 55 |
+
- **Focal loss training** for better minority class performance
|
| 56 |
+
- **Clean dataset** with cross-split contamination resolved
|
| 57 |
+
- **Extended training** (4.79 epochs vs 1.1 epochs)
|
| 58 |
+
|
| 59 |
+
## Model Description
|
| 60 |
+
|
| 61 |
+
This model provides nuanced classification of textual content across 7 categories, enabling sophisticated analysis for digital humanities, content curation, and literary research applications.
|
| 62 |
+
|
| 63 |
+
### Categories
|
| 64 |
+
|
| 65 |
+
| ID | Category | Description | F1 Score |
|
| 66 |
+
|----|----------|-------------|----------|
|
| 67 |
+
| 0 | EXPLICIT-DISCLAIMER | Content warnings and age restriction notices | **0.977** |
|
| 68 |
+
| 1 | EXPLICIT-OFFENSIVE | Profanity, crude language, offensive content | **0.813** |
|
| 69 |
+
| 2 | EXPLICIT-SEXUAL | Graphic sexual content and detailed intimate scenes | **0.930** |
|
| 70 |
+
| 3 | EXPLICIT-VIOLENT | Violent or disturbing content | **0.581** |
|
| 71 |
+
| 4 | NON-EXPLICIT | Clean, family-friendly content | **0.851** |
|
| 72 |
+
| 5 | SEXUAL-REFERENCE | Mentions of sexual topics without graphic description | **0.652** |
|
| 73 |
+
| 6 | SUGGESTIVE | Mild innuendo or romantic themes without explicit detail | **0.476** |
|
| 74 |
+
|
| 75 |
+
## Performance Metrics
|
| 76 |
+
|
| 77 |
+
### Overall Performance
|
| 78 |
+
- **Accuracy**: 81.8%
|
| 79 |
+
- **Macro F1**: 0.754
|
| 80 |
+
- **Weighted F1**: 0.816
|
| 81 |
+
|
| 82 |
+
### Detailed Results (Test Set - Clean Data)
|
| 83 |
+
```
|
| 84 |
+
precision recall f1-score support
|
| 85 |
+
EXPLICIT-DISCLAIMER 0.95 1.00 0.98 19
|
| 86 |
+
EXPLICIT-OFFENSIVE 0.82 0.88 0.81 414
|
| 87 |
+
EXPLICIT-SEXUAL 0.93 0.91 0.93 514
|
| 88 |
+
EXPLICIT-VIOLENT 0.44 0.62 0.58 24
|
| 89 |
+
NON-EXPLICIT 0.77 0.87 0.85 683
|
| 90 |
+
SEXUAL-REFERENCE 0.63 0.73 0.65 212
|
| 91 |
+
SUGGESTIVE 0.37 0.46 0.48 134
|
| 92 |
+
|
| 93 |
+
accuracy 0.82 2000
|
| 94 |
+
macro avg 0.65 0.78 0.75 2000
|
| 95 |
+
weighted avg 0.75 0.82 0.82 2000
|
| 96 |
+
```
|
| 97 |
+
|
| 98 |
+
## Training Details
|
| 99 |
+
|
| 100 |
+
### Model Architecture
|
| 101 |
+
- **Base Model**: microsoft/deberta-v3-small
|
| 102 |
+
- **Parameters**: 141.9M (6 layers, 768 hidden, 12 attention heads)
|
| 103 |
+
- **Vocabulary**: 128,100 tokens
|
| 104 |
+
- **Max Sequence Length**: 512 tokens
|
| 105 |
+
|
| 106 |
+
### Training Configuration
|
| 107 |
+
- **Training Method**: Focal Loss (Ξ³=2.0) for class imbalance
|
| 108 |
+
- **Epochs**: 4.79 (early stopped)
|
| 109 |
+
- **Learning Rate**: 5e-5 with cosine schedule
|
| 110 |
+
- **Batch Size**: 16 (effective 32 with gradient accumulation)
|
| 111 |
+
- **Warmup Steps**: 1,000
|
| 112 |
+
- **Weight Decay**: 0.01
|
| 113 |
+
- **Early Stopping**: Patience 5 on macro F1
|
| 114 |
+
|
| 115 |
+
### Dataset
|
| 116 |
+
- **Total Samples**: 119,023 (after deduplication)
|
| 117 |
+
- **Training**: 83,316 samples
|
| 118 |
+
- **Validation**: 17,853 samples
|
| 119 |
+
- **Test**: 17,854 samples
|
| 120 |
+
- **Data Quality**: Cross-split contamination eliminated (2,127 duplicates removed)
|
| 121 |
+
|
| 122 |
+
### Training Environment
|
| 123 |
+
- **Framework**: PyTorch + Transformers
|
| 124 |
+
- **Hardware**: Apple Silicon (MPS)
|
| 125 |
+
- **Training Time**: ~13.7 hours
|
| 126 |
+
|
| 127 |
+
## Usage
|
| 128 |
+
|
| 129 |
+
```python
|
| 130 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
| 131 |
+
|
| 132 |
+
# Load model and tokenizer
|
| 133 |
+
model_id = "your-username/deberta-v3-small-explicit-classifier-v2"
|
| 134 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_id)
|
| 135 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 136 |
+
|
| 137 |
+
# Create classification pipeline
|
| 138 |
+
classifier = pipeline(
|
| 139 |
+
"text-classification",
|
| 140 |
+
model=model,
|
| 141 |
+
tokenizer=tokenizer,
|
| 142 |
+
return_all_scores=True,
|
| 143 |
+
truncation=True
|
| 144 |
+
)
|
| 145 |
+
|
| 146 |
+
# Single classification
|
| 147 |
+
text = "His hand lingered on hers as he helped her from the carriage."
|
| 148 |
+
result = classifier(text)
|
| 149 |
+
print(f"Top prediction: {result[0]['label']} ({result[0]['score']:.3f})")
|
| 150 |
+
|
| 151 |
+
# All class probabilities
|
| 152 |
+
for class_result in result:
|
| 153 |
+
print(f"{class_result['label']}: {class_result['score']:.3f}")
|
| 154 |
+
```
|
| 155 |
+
|
| 156 |
+
### Recommended Thresholds (F1-Optimized)
|
| 157 |
+
|
| 158 |
+
For applications requiring specific precision/recall trade-offs:
|
| 159 |
+
|
| 160 |
+
| Class | Optimal Threshold | Precision | Recall | F1 |
|
| 161 |
+
|-------|------------------|-----------|--------|-----|
|
| 162 |
+
| EXPLICIT-DISCLAIMER | 0.995 | 0.950 | 1.000 | 0.974 |
|
| 163 |
+
| EXPLICIT-OFFENSIVE | 0.626 | 0.819 | 0.829 | 0.824 |
|
| 164 |
+
| EXPLICIT-SEXUAL | 0.456 | 0.927 | 0.911 | 0.919 |
|
| 165 |
+
| EXPLICIT-VIOLENT | 0.105 | 0.441 | 0.625 | 0.517 |
|
| 166 |
+
| NON-EXPLICIT | 0.103 | 0.768 | 0.874 | 0.818 |
|
| 167 |
+
| SEXUAL-REFERENCE | 0.355 | 0.629 | 0.726 | 0.674 |
|
| 168 |
+
| SUGGESTIVE | 0.530 | 0.370 | 0.455 | 0.408 |
|
| 169 |
+
|
| 170 |
+
## Model Files
|
| 171 |
+
|
| 172 |
+
- `model.safetensors`: Model weights in SafeTensors format
|
| 173 |
+
- `config.json`: Model configuration with proper label mappings
|
| 174 |
+
- `tokenizer.json`, `spm.model`: SentencePiece tokenizer files
|
| 175 |
+
- `label_mapping.json`: Label ID to name mapping reference
|
| 176 |
+
|
| 177 |
+
## Limitations & Considerations
|
| 178 |
+
|
| 179 |
+
1. **Challenging Distinctions**: SUGGESTIVE vs SEXUAL-REFERENCE categories remain difficult to distinguish due to conceptual overlap
|
| 180 |
+
2. **Minority Classes**: EXPLICIT-VIOLENT and SUGGESTIVE classes have lower F1 scores due to limited training data
|
| 181 |
+
3. **Context Dependency**: Short text snippets may lack sufficient context for accurate classification
|
| 182 |
+
4. **Domain Specificity**: Optimized for literary and review content; performance may vary on other text types
|
| 183 |
+
5. **Language**: English text only
|
| 184 |
+
|
| 185 |
+
## Evaluation Artifacts
|
| 186 |
+
|
| 187 |
+
The model includes comprehensive evaluation materials:
|
| 188 |
+
- Confusion matrix visualization
|
| 189 |
+
- Per-class precision-recall curves
|
| 190 |
+
- ROC curves for all categories
|
| 191 |
+
- Calibration analysis
|
| 192 |
+
- Recommended decision thresholds
|
| 193 |
+
|
| 194 |
+
## Ethical Use
|
| 195 |
+
|
| 196 |
+
This model is designed for:
|
| 197 |
+
- Academic research and digital humanities
|
| 198 |
+
- Content curation and library science applications
|
| 199 |
+
- Literary analysis and publishing workflows
|
| 200 |
+
- Educational content assessment
|
| 201 |
+
|
| 202 |
+
**Important**: This model should be used responsibly with human oversight for content moderation decisions.
|
| 203 |
+
|
| 204 |
+
## Technical Details
|
| 205 |
+
|
| 206 |
+
### Improvements Over v1.0
|
| 207 |
+
- **Data Quality**: Eliminated 2,127 cross-split contaminated samples
|
| 208 |
+
- **Training Strategy**: Focal loss with Ξ³=2.0 for class imbalance
|
| 209 |
+
- **Architecture**: Same DeBERTa-v3-small base with optimized training
|
| 210 |
+
- **Evaluation**: More rigorous testing on clean, independent test set
|
| 211 |
+
|
| 212 |
+
### Performance Comparison
|
| 213 |
+
| Metric | v1.0 | v2.0 | Improvement |
|
| 214 |
+
|---------|------|------|-------------|
|
| 215 |
+
| Accuracy | 77.3% | **81.8%** | +4.5% |
|
| 216 |
+
| Macro F1 | 0.709 | **0.754** | +6.4% |
|
| 217 |
+
| EXPLICIT-VIOLENT F1 | 0.478 | **0.581** | +21.5% |
|
| 218 |
+
| SUGGESTIVE F1 | 0.400 | **0.476** | +19.0% |
|
| 219 |
+
|
| 220 |
+
## Citation
|
| 221 |
+
|
| 222 |
+
```bibtex
|
| 223 |
+
@misc{literary-explicit-classifier-v2-2025,
|
| 224 |
+
title={Literary Content Analysis: Improved Multi-Class Classification with Focal Loss},
|
| 225 |
+
author={Explicit Content Research Team},
|
| 226 |
+
year={2025},
|
| 227 |
+
note={DeBERTa-v3-small fine-tuned for literary explicitness detection}
|
| 228 |
+
}
|
| 229 |
+
```
|
| 230 |
+
|
| 231 |
+
## License
|
| 232 |
+
|
| 233 |
+
This model is released under the Apache 2.0 license.
|
TRAINING_SUMMARY.md
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Training Summary - DeBERTa v3 Small Explicit Classifier v2.0
|
| 2 |
+
|
| 3 |
+
## Overview
|
| 4 |
+
This document summarizes the training process and improvements made in v2.0 of the explicit content classifier.
|
| 5 |
+
|
| 6 |
+
## Key Improvements
|
| 7 |
+
|
| 8 |
+
### 1. Data Quality Enhancement
|
| 9 |
+
- **Problem**: Cross-split contamination (2,127 duplicate texts across train/val/test)
|
| 10 |
+
- **Solution**: Comprehensive deduplication removing 5,121 duplicate samples
|
| 11 |
+
- **Result**: Clean dataset with 119,023 unique samples
|
| 12 |
+
|
| 13 |
+
### 2. Advanced Training Strategy
|
| 14 |
+
- **Focal Loss**: Implemented with Ξ³=2.0 to address class imbalance
|
| 15 |
+
- **Extended Training**: 4.79 epochs vs 1.1 epochs in v1.0
|
| 16 |
+
- **Learning Rate Schedule**: Cosine annealing for better convergence
|
| 17 |
+
- **Early Stopping**: Patience of 5 on macro F1 metric
|
| 18 |
+
|
| 19 |
+
### 3. Architecture Optimizations
|
| 20 |
+
- **Gradient Accumulation**: Effective batch size of 32
|
| 21 |
+
- **Warmup Steps**: 1,000 steps for stable training
|
| 22 |
+
- **Weight Decay**: 0.01 for regularization
|
| 23 |
+
|
| 24 |
+
## Training Configuration
|
| 25 |
+
|
| 26 |
+
```yaml
|
| 27 |
+
Model: microsoft/deberta-v3-small (141.9M parameters)
|
| 28 |
+
Training Method: Focal Loss (Ξ³=2.0)
|
| 29 |
+
Epochs: 4.79 (early stopped)
|
| 30 |
+
Learning Rate: 5e-5 with cosine schedule
|
| 31 |
+
Batch Size: 16 (effective 32 with accumulation)
|
| 32 |
+
Warmup Steps: 1,000
|
| 33 |
+
Weight Decay: 0.01
|
| 34 |
+
Hardware: Apple Silicon (MPS)
|
| 35 |
+
Training Time: ~13.7 hours
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
## Dataset Statistics
|
| 39 |
+
|
| 40 |
+
### Final Clean Dataset
|
| 41 |
+
- **Total Samples**: 119,023 (vs 124,144 original)
|
| 42 |
+
- **Duplicates Removed**: 5,121
|
| 43 |
+
- **Cross-split Contamination**: Eliminated completely
|
| 44 |
+
|
| 45 |
+
### Split Distribution
|
| 46 |
+
- **Training**: 83,316 samples (70.0%)
|
| 47 |
+
- **Validation**: 17,853 samples (15.0%)
|
| 48 |
+
- **Test**: 17,854 samples (15.0%)
|
| 49 |
+
|
| 50 |
+
### Class Distribution (Training Set)
|
| 51 |
+
| Class ID | Name | Count | Percentage |
|
| 52 |
+
|----------|------|-------|------------|
|
| 53 |
+
| 0 | EXPLICIT-DISCLAIMER | 758 | 0.9% |
|
| 54 |
+
| 1 | EXPLICIT-OFFENSIVE | 16,845 | 20.2% |
|
| 55 |
+
| 2 | EXPLICIT-SEXUAL | 21,526 | 25.8% |
|
| 56 |
+
| 3 | EXPLICIT-VIOLENT | 1,032 | 1.2% |
|
| 57 |
+
| 4 | NON-EXPLICIT | 29,090 | 34.9% |
|
| 58 |
+
| 5 | SEXUAL-REFERENCE | 8,410 | 10.1% |
|
| 59 |
+
| 6 | SUGGESTIVE | 5,655 | 6.8% |
|
| 60 |
+
|
| 61 |
+
## Performance Comparison
|
| 62 |
+
|
| 63 |
+
### Overall Metrics
|
| 64 |
+
| Metric | v1.0 | v2.0 | Improvement |
|
| 65 |
+
|---------|------|------|-------------|
|
| 66 |
+
| Accuracy | 77.3% | **81.8%** | **+4.5%** |
|
| 67 |
+
| Macro F1 | 0.709 | **0.754** | **+6.4%** |
|
| 68 |
+
| Weighted F1 | 0.779 | **0.816** | **+4.7%** |
|
| 69 |
+
|
| 70 |
+
### Per-Class F1 Improvements
|
| 71 |
+
| Class | v1.0 F1 | v2.0 F1 | Improvement |
|
| 72 |
+
|-------|---------|---------|-------------|
|
| 73 |
+
| EXPLICIT-DISCLAIMER | 0.927 | **0.977** | +5.4% |
|
| 74 |
+
| EXPLICIT-OFFENSIVE | 0.808 | **0.813** | +0.6% |
|
| 75 |
+
| EXPLICIT-SEXUAL | 0.918 | **0.930** | +1.3% |
|
| 76 |
+
| EXPLICIT-VIOLENT | 0.478 | **0.581** | **+21.5%** π |
|
| 77 |
+
| NON-EXPLICIT | 0.777 | **0.851** | +9.5% |
|
| 78 |
+
| SEXUAL-REFERENCE | 0.658 | **0.652** | -0.9% |
|
| 79 |
+
| SUGGESTIVE | 0.400 | **0.476** | **+19.0%** π |
|
| 80 |
+
|
| 81 |
+
## Training Progress
|
| 82 |
+
|
| 83 |
+
### Key Milestones
|
| 84 |
+
- **Epoch 0.37**: Initial eval - Macro F1: 0.603
|
| 85 |
+
- **Epoch 1.47**: Significant improvement - Macro F1: 0.732
|
| 86 |
+
- **Epoch 2.95**: Peak performance - Macro F1: 0.758
|
| 87 |
+
- **Epoch 4.79**: Final model (early stopped)
|
| 88 |
+
|
| 89 |
+
### Loss Evolution
|
| 90 |
+
- **Initial Loss**: 0.6945
|
| 91 |
+
- **Final Loss**: 0.0581
|
| 92 |
+
- **Total Reduction**: 91.6%
|
| 93 |
+
|
| 94 |
+
## Technical Achievements
|
| 95 |
+
|
| 96 |
+
### 1. Minority Class Performance
|
| 97 |
+
The focal loss successfully addressed the class imbalance:
|
| 98 |
+
- **EXPLICIT-VIOLENT**: +21.5% F1 improvement
|
| 99 |
+
- **SUGGESTIVE**: +19.0% F1 improvement
|
| 100 |
+
- **EXPLICIT-DISCLAIMER**: Near-perfect performance (0.977 F1)
|
| 101 |
+
|
| 102 |
+
### 2. Data Quality
|
| 103 |
+
- Eliminated all cross-split contamination
|
| 104 |
+
- Proper train/val/test independence
|
| 105 |
+
- More reliable evaluation metrics
|
| 106 |
+
|
| 107 |
+
### 3. Training Stability
|
| 108 |
+
- Consistent improvement across epochs
|
| 109 |
+
- Proper early stopping prevented overfitting
|
| 110 |
+
- Stable convergence with cosine learning rate schedule
|
| 111 |
+
|
| 112 |
+
## Limitations Addressed
|
| 113 |
+
|
| 114 |
+
### v1.0 Issues Fixed
|
| 115 |
+
- β
Cross-split data contamination eliminated
|
| 116 |
+
- β
Minority class performance significantly improved
|
| 117 |
+
- β
Extended training for better convergence
|
| 118 |
+
- β
More rigorous evaluation on clean data
|
| 119 |
+
|
| 120 |
+
### Remaining Challenges
|
| 121 |
+
- SUGGESTIVE vs SEXUAL-REFERENCE distinction remains difficult
|
| 122 |
+
- Limited training data for EXPLICIT-VIOLENT class
|
| 123 |
+
- Context dependency for short texts
|
| 124 |
+
|
| 125 |
+
## Files Generated
|
| 126 |
+
|
| 127 |
+
### Model Files
|
| 128 |
+
- `model.safetensors` - Model weights (567MB)
|
| 129 |
+
- `config.json` - Model configuration with proper labels
|
| 130 |
+
- `tokenizer.json`, `spm.model` - Tokenization files
|
| 131 |
+
- `label_mapping.json` - Label reference
|
| 132 |
+
|
| 133 |
+
### Evaluation Results
|
| 134 |
+
- `improved_classification_report.txt` - Detailed performance metrics
|
| 135 |
+
- `recommended_thresholds.json` - Optimal decision thresholds
|
| 136 |
+
- `confusion_matrix.png` - Classification confusion matrix
|
| 137 |
+
- `pr_curves.png` - Precision-recall curves per class
|
| 138 |
+
- `roc_curves.png` - ROC curves per class
|
| 139 |
+
- `calibration.png` - Model calibration analysis
|
| 140 |
+
|
| 141 |
+
### Documentation
|
| 142 |
+
- `README.md` - Comprehensive model documentation
|
| 143 |
+
- `model_card.md` - Model card summary
|
| 144 |
+
- `inference_example.py` - Usage example script
|
| 145 |
+
- `TRAINING_SUMMARY.md` - This training summary
|
| 146 |
+
|
| 147 |
+
## Next Steps
|
| 148 |
+
|
| 149 |
+
### Potential Future Improvements
|
| 150 |
+
1. **Larger Model**: Scale to DeBERTa-large for even better performance
|
| 151 |
+
2. **Data Augmentation**: Generate more minority class samples
|
| 152 |
+
3. **Ensemble Methods**: Combine multiple models for robust predictions
|
| 153 |
+
4. **Domain Adaptation**: Fine-tune for specific content types
|
| 154 |
+
|
| 155 |
+
### Production Readiness
|
| 156 |
+
- β
SafeTensors format for secure deployment
|
| 157 |
+
- β
Comprehensive documentation
|
| 158 |
+
- β
Example inference code
|
| 159 |
+
- β
Evaluation artifacts included
|
| 160 |
+
- β
Proper label mappings in config
|
| 161 |
+
|
| 162 |
+
The v2.0 model represents a significant improvement over v1.0 and is ready for production deployment in literary analysis and content curation applications.
|
added_tokens.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"[MASK]": 128000
|
| 3 |
+
}
|
calibration.png
ADDED
|
Git LFS Details
|
config.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"DebertaV2ForSequenceClassification"
|
| 4 |
+
],
|
| 5 |
+
"attention_probs_dropout_prob": 0.1,
|
| 6 |
+
"hidden_act": "gelu",
|
| 7 |
+
"hidden_dropout_prob": 0.1,
|
| 8 |
+
"hidden_size": 768,
|
| 9 |
+
"id2label": {
|
| 10 |
+
"0": "EXPLICIT-DISCLAIMER",
|
| 11 |
+
"1": "EXPLICIT-OFFENSIVE",
|
| 12 |
+
"2": "EXPLICIT-SEXUAL",
|
| 13 |
+
"3": "EXPLICIT-VIOLENT",
|
| 14 |
+
"4": "NON-EXPLICIT",
|
| 15 |
+
"5": "SEXUAL-REFERENCE",
|
| 16 |
+
"6": "SUGGESTIVE"
|
| 17 |
+
},
|
| 18 |
+
"initializer_range": 0.02,
|
| 19 |
+
"intermediate_size": 3072,
|
| 20 |
+
"label2id": {
|
| 21 |
+
"EXPLICIT-DISCLAIMER": 0,
|
| 22 |
+
"EXPLICIT-OFFENSIVE": 1,
|
| 23 |
+
"EXPLICIT-SEXUAL": 2,
|
| 24 |
+
"EXPLICIT-VIOLENT": 3,
|
| 25 |
+
"NON-EXPLICIT": 4,
|
| 26 |
+
"SEXUAL-REFERENCE": 5,
|
| 27 |
+
"SUGGESTIVE": 6
|
| 28 |
+
},
|
| 29 |
+
"layer_norm_eps": 1e-07,
|
| 30 |
+
"legacy": true,
|
| 31 |
+
"max_position_embeddings": 512,
|
| 32 |
+
"max_relative_positions": -1,
|
| 33 |
+
"model_type": "deberta-v2",
|
| 34 |
+
"norm_rel_ebd": "layer_norm",
|
| 35 |
+
"num_attention_heads": 12,
|
| 36 |
+
"num_hidden_layers": 6,
|
| 37 |
+
"pad_token_id": 0,
|
| 38 |
+
"pooler_dropout": 0,
|
| 39 |
+
"pooler_hidden_act": "gelu",
|
| 40 |
+
"pooler_hidden_size": 768,
|
| 41 |
+
"pos_att_type": [
|
| 42 |
+
"p2c",
|
| 43 |
+
"c2p"
|
| 44 |
+
],
|
| 45 |
+
"position_biased_input": false,
|
| 46 |
+
"position_buckets": 256,
|
| 47 |
+
"relative_attention": true,
|
| 48 |
+
"share_att_key": true,
|
| 49 |
+
"torch_dtype": "float32",
|
| 50 |
+
"transformers_version": "4.53.3",
|
| 51 |
+
"type_vocab_size": 0,
|
| 52 |
+
"vocab_size": 128100
|
| 53 |
+
}
|
confusion_matrix.png
ADDED
|
Git LFS Details
|
improved_classification_report.txt
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Improved Model Training Results
|
| 2 |
+
==================================================
|
| 3 |
+
Improvements applied:
|
| 4 |
+
- Focal loss (gamma=2.0) for class imbalance
|
| 5 |
+
- Longer training (up to 5 epochs)
|
| 6 |
+
- Cosine LR schedule
|
| 7 |
+
- Gradient accumulation
|
| 8 |
+
- Increased early stopping patience
|
| 9 |
+
|
| 10 |
+
Final Results:
|
| 11 |
+
eval_loss: 0.2538
|
| 12 |
+
eval_accuracy: 0.8226
|
| 13 |
+
eval_macro_f1: 0.7582
|
| 14 |
+
eval_weighted_f1: 0.8192
|
| 15 |
+
eval_f1_EXPLICIT-DISCLAIMER: 0.9803
|
| 16 |
+
eval_f1_EXPLICIT-OFFENSIVE: 0.8111
|
| 17 |
+
eval_f1_EXPLICIT-SEXUAL: 0.9254
|
| 18 |
+
eval_f1_EXPLICIT-VIOLENT: 0.5830
|
| 19 |
+
eval_f1_NON-EXPLICIT: 0.8569
|
| 20 |
+
eval_f1_SEXUAL-REFERENCE: 0.6803
|
| 21 |
+
eval_f1_SUGGESTIVE: 0.4703
|
| 22 |
+
eval_runtime: 1079.3255
|
| 23 |
+
eval_samples_per_second: 17.2530
|
| 24 |
+
eval_steps_per_second: 0.5390
|
| 25 |
+
epoch: 4.7865
|
| 26 |
+
|
| 27 |
+
Detailed Classification Report:
|
| 28 |
+
precision recall f1-score support
|
| 29 |
+
|
| 30 |
+
EXPLICIT-DISCLAIMER 0.9721 0.9886 0.9803 176
|
| 31 |
+
EXPLICIT-OFFENSIVE 0.8296 0.7934 0.8111 3834
|
| 32 |
+
EXPLICIT-SEXUAL 0.9226 0.9281 0.9254 4755
|
| 33 |
+
EXPLICIT-VIOLENT 0.5781 0.5880 0.5830 233
|
| 34 |
+
NON-EXPLICIT 0.8350 0.8801 0.8569 6520
|
| 35 |
+
SEXUAL-REFERENCE 0.6546 0.7081 0.6803 1857
|
| 36 |
+
SUGGESTIVE 0.5703 0.4002 0.4703 1247
|
| 37 |
+
|
| 38 |
+
accuracy 0.8226 18622
|
| 39 |
+
macro avg 0.7660 0.7552 0.7582 18622
|
| 40 |
+
weighted avg 0.8186 0.8226 0.8192 18622
|
inference_example.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Example inference script for DeBERTa v3 Small Explicit Content Classifier v2.0
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
| 7 |
+
import torch
|
| 8 |
+
|
| 9 |
+
def load_classifier(model_path="."):
|
| 10 |
+
"""Load the model and create classification pipeline"""
|
| 11 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_path)
|
| 12 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 13 |
+
|
| 14 |
+
classifier = pipeline(
|
| 15 |
+
"text-classification",
|
| 16 |
+
model=model,
|
| 17 |
+
tokenizer=tokenizer,
|
| 18 |
+
return_all_scores=True,
|
| 19 |
+
truncation=True
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
return classifier
|
| 23 |
+
|
| 24 |
+
def classify_text(classifier, text, show_all_scores=True, threshold=None):
|
| 25 |
+
"""Classify text and optionally show all class probabilities"""
|
| 26 |
+
results = classifier(text)
|
| 27 |
+
|
| 28 |
+
print(f"\nText: \"{text[:100]}{'...' if len(text) > 100 else ''}\"")
|
| 29 |
+
print("-" * 60)
|
| 30 |
+
|
| 31 |
+
# Top prediction
|
| 32 |
+
top_prediction = results[0]
|
| 33 |
+
print(f"π― Prediction: {top_prediction['label']} ({top_prediction['score']:.3f})")
|
| 34 |
+
|
| 35 |
+
if show_all_scores:
|
| 36 |
+
print("\nπ All Class Probabilities:")
|
| 37 |
+
for result in results:
|
| 38 |
+
confidence = "π₯" if result['score'] > 0.7 else "β
" if result['score'] > 0.5 else "βͺ"
|
| 39 |
+
print(f" {confidence} {result['label']:<20}: {result['score']:.3f}")
|
| 40 |
+
|
| 41 |
+
if threshold:
|
| 42 |
+
print(f"\nβ οΈ Above threshold ({threshold}):")
|
| 43 |
+
above_threshold = [r for r in results if r['score'] > threshold]
|
| 44 |
+
for result in above_threshold:
|
| 45 |
+
print(f" {result['label']}: {result['score']:.3f}")
|
| 46 |
+
|
| 47 |
+
return results
|
| 48 |
+
|
| 49 |
+
def main():
|
| 50 |
+
print("π DeBERTa v3 Small Explicit Content Classifier v2.0")
|
| 51 |
+
print("=" * 60)
|
| 52 |
+
|
| 53 |
+
# Load model
|
| 54 |
+
print("Loading model...")
|
| 55 |
+
classifier = load_classifier()
|
| 56 |
+
|
| 57 |
+
# Test examples
|
| 58 |
+
test_examples = [
|
| 59 |
+
"The morning sun cast long shadows across the peaceful meadow where children played.",
|
| 60 |
+
"His fingers traced gentle patterns on her skin as she whispered his name.",
|
| 61 |
+
"Content warning: This story contains mature themes including violence and sexual content.",
|
| 62 |
+
"She gasped as he pulled her close, their bodies pressed together in desperate passion.",
|
| 63 |
+
"The detective found the victim's body in a pool of blood, throat slashed.",
|
| 64 |
+
"'Damn it,' he muttered, frustration evident in his voice.",
|
| 65 |
+
"They shared a tender kiss under the starlit sky, hearts beating as one."
|
| 66 |
+
]
|
| 67 |
+
|
| 68 |
+
for text in test_examples:
|
| 69 |
+
classify_text(classifier, text, show_all_scores=False)
|
| 70 |
+
print()
|
| 71 |
+
|
| 72 |
+
# Interactive mode
|
| 73 |
+
print("\n" + "="*60)
|
| 74 |
+
print("Interactive Mode - Enter text to classify (or 'quit' to exit):")
|
| 75 |
+
|
| 76 |
+
while True:
|
| 77 |
+
user_text = input("\nπ Enter text: ").strip()
|
| 78 |
+
|
| 79 |
+
if user_text.lower() in ['quit', 'exit', 'q']:
|
| 80 |
+
break
|
| 81 |
+
|
| 82 |
+
if user_text:
|
| 83 |
+
classify_text(classifier, user_text, show_all_scores=True, threshold=0.3)
|
| 84 |
+
|
| 85 |
+
if __name__ == "__main__":
|
| 86 |
+
main()
|
label_mapping.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"label_to_id": {
|
| 3 |
+
"EXPLICIT-DISCLAIMER": 0,
|
| 4 |
+
"EXPLICIT-OFFENSIVE": 1,
|
| 5 |
+
"EXPLICIT-SEXUAL": 2,
|
| 6 |
+
"EXPLICIT-VIOLENT": 3,
|
| 7 |
+
"NON-EXPLICIT": 4,
|
| 8 |
+
"SEXUAL-REFERENCE": 5,
|
| 9 |
+
"SUGGESTIVE": 6
|
| 10 |
+
},
|
| 11 |
+
"id_to_label": {
|
| 12 |
+
"0": "EXPLICIT-DISCLAIMER",
|
| 13 |
+
"1": "EXPLICIT-OFFENSIVE",
|
| 14 |
+
"2": "EXPLICIT-SEXUAL",
|
| 15 |
+
"3": "EXPLICIT-VIOLENT",
|
| 16 |
+
"4": "NON-EXPLICIT",
|
| 17 |
+
"5": "SEXUAL-REFERENCE",
|
| 18 |
+
"6": "SUGGESTIVE"
|
| 19 |
+
},
|
| 20 |
+
"num_labels": 7
|
| 21 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:37210dd587200aa1bd12f660887c1b02442391a9aba15a18b1e1baafcaa781f4
|
| 3 |
+
size 567613932
|
model_card.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Model Card: DeBERTa v3 Small Explicit Content Classifier v2.0
|
| 2 |
+
|
| 3 |
+
## Model Summary
|
| 4 |
+
|
| 5 |
+
A fine-tuned DeBERTa-v3-small model for classifying literary content explicitness across 7 categories with significant improvements over v1.0.
|
| 6 |
+
|
| 7 |
+
## Intended Use
|
| 8 |
+
|
| 9 |
+
**Primary Use Cases:**
|
| 10 |
+
- Literary content analysis and research
|
| 11 |
+
- Digital humanities applications
|
| 12 |
+
- Content curation for libraries and educational institutions
|
| 13 |
+
- Publishing workflow assistance
|
| 14 |
+
|
| 15 |
+
**Out of Scope:**
|
| 16 |
+
- Real-time content moderation without human oversight
|
| 17 |
+
- Legal content filtering decisions
|
| 18 |
+
- Content outside of literary/educational domains
|
| 19 |
+
|
| 20 |
+
## Performance Summary
|
| 21 |
+
|
| 22 |
+
| Metric | Value |
|
| 23 |
+
|--------|-------|
|
| 24 |
+
| Overall Accuracy | 81.8% |
|
| 25 |
+
| Macro F1 | 0.754 |
|
| 26 |
+
| Best Performing Class | EXPLICIT-DISCLAIMER (F1: 0.977) |
|
| 27 |
+
| Most Challenging Class | SUGGESTIVE (F1: 0.476) |
|
| 28 |
+
|
| 29 |
+
## Training Data
|
| 30 |
+
|
| 31 |
+
- **Size**: 119,023 samples (deduplicated)
|
| 32 |
+
- **Sources**: Literary texts, reviews, academic content
|
| 33 |
+
- **Quality**: Cross-split contamination eliminated
|
| 34 |
+
- **Balance**: Class weights applied during training
|
| 35 |
+
|
| 36 |
+
## Ethical Considerations
|
| 37 |
+
|
| 38 |
+
- Designed for academic and educational use
|
| 39 |
+
- Requires human oversight for sensitive applications
|
| 40 |
+
- May reflect biases present in training data
|
| 41 |
+
- Not suitable for automated content blocking
|
| 42 |
+
|
| 43 |
+
## Technical Specifications
|
| 44 |
+
|
| 45 |
+
- **Architecture**: DeBERTa-v3-small (141.9M parameters)
|
| 46 |
+
- **Training**: Focal loss, 4.79 epochs, cosine LR schedule
|
| 47 |
+
- **Input**: Text sequences up to 512 tokens
|
| 48 |
+
- **Output**: 7-class probability distribution
|
pr_curves.png
ADDED
|
Git LFS Details
|
recommended_thresholds.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"EXPLICIT-DISCLAIMER": {
|
| 3 |
+
"threshold": 0.9952024221420288,
|
| 4 |
+
"f1_score": 0.9743589693622617,
|
| 5 |
+
"precision": 0.95,
|
| 6 |
+
"recall": 1.0
|
| 7 |
+
},
|
| 8 |
+
"EXPLICIT-OFFENSIVE": {
|
| 9 |
+
"threshold": 0.6258187890052795,
|
| 10 |
+
"f1_score": 0.8235294067648862,
|
| 11 |
+
"precision": 0.8186157517899761,
|
| 12 |
+
"recall": 0.8285024154589372
|
| 13 |
+
},
|
| 14 |
+
"EXPLICIT-SEXUAL": {
|
| 15 |
+
"threshold": 0.45611345767974854,
|
| 16 |
+
"f1_score": 0.9185475906824314,
|
| 17 |
+
"precision": 0.9267326732673268,
|
| 18 |
+
"recall": 0.9105058365758755
|
| 19 |
+
},
|
| 20 |
+
"EXPLICIT-VIOLENT": {
|
| 21 |
+
"threshold": 0.10532726347446442,
|
| 22 |
+
"f1_score": 0.5172413744589776,
|
| 23 |
+
"precision": 0.4411764705882353,
|
| 24 |
+
"recall": 0.625
|
| 25 |
+
},
|
| 26 |
+
"NON-EXPLICIT": {
|
| 27 |
+
"threshold": 0.10281168669462204,
|
| 28 |
+
"f1_score": 0.8178082141988086,
|
| 29 |
+
"precision": 0.7683397683397684,
|
| 30 |
+
"recall": 0.8740849194729137
|
| 31 |
+
},
|
| 32 |
+
"SEXUAL-REFERENCE": {
|
| 33 |
+
"threshold": 0.35498443245887756,
|
| 34 |
+
"f1_score": 0.6739606077175376,
|
| 35 |
+
"precision": 0.6285714285714286,
|
| 36 |
+
"recall": 0.7264150943396226
|
| 37 |
+
},
|
| 38 |
+
"SUGGESTIVE": {
|
| 39 |
+
"threshold": 0.530241072177887,
|
| 40 |
+
"f1_score": 0.4080267509065894,
|
| 41 |
+
"precision": 0.3696969696969697,
|
| 42 |
+
"recall": 0.4552238805970149
|
| 43 |
+
}
|
| 44 |
+
}
|
roc_curves.png
ADDED
|
Git LFS Details
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": "[CLS]",
|
| 3 |
+
"cls_token": "[CLS]",
|
| 4 |
+
"eos_token": "[SEP]",
|
| 5 |
+
"mask_token": "[MASK]",
|
| 6 |
+
"pad_token": "[PAD]",
|
| 7 |
+
"sep_token": "[SEP]",
|
| 8 |
+
"unk_token": {
|
| 9 |
+
"content": "[UNK]",
|
| 10 |
+
"lstrip": false,
|
| 11 |
+
"normalized": true,
|
| 12 |
+
"rstrip": false,
|
| 13 |
+
"single_word": false
|
| 14 |
+
}
|
| 15 |
+
}
|
spm.model
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c679fbf93643d19aab7ee10c0b99e460bdbc02fedf34b92b05af343b4af586fd
|
| 3 |
+
size 2464616
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"added_tokens_decoder": {
|
| 3 |
+
"0": {
|
| 4 |
+
"content": "[PAD]",
|
| 5 |
+
"lstrip": false,
|
| 6 |
+
"normalized": false,
|
| 7 |
+
"rstrip": false,
|
| 8 |
+
"single_word": false,
|
| 9 |
+
"special": true
|
| 10 |
+
},
|
| 11 |
+
"1": {
|
| 12 |
+
"content": "[CLS]",
|
| 13 |
+
"lstrip": false,
|
| 14 |
+
"normalized": false,
|
| 15 |
+
"rstrip": false,
|
| 16 |
+
"single_word": false,
|
| 17 |
+
"special": true
|
| 18 |
+
},
|
| 19 |
+
"2": {
|
| 20 |
+
"content": "[SEP]",
|
| 21 |
+
"lstrip": false,
|
| 22 |
+
"normalized": false,
|
| 23 |
+
"rstrip": false,
|
| 24 |
+
"single_word": false,
|
| 25 |
+
"special": true
|
| 26 |
+
},
|
| 27 |
+
"3": {
|
| 28 |
+
"content": "[UNK]",
|
| 29 |
+
"lstrip": false,
|
| 30 |
+
"normalized": true,
|
| 31 |
+
"rstrip": false,
|
| 32 |
+
"single_word": false,
|
| 33 |
+
"special": true
|
| 34 |
+
},
|
| 35 |
+
"128000": {
|
| 36 |
+
"content": "[MASK]",
|
| 37 |
+
"lstrip": false,
|
| 38 |
+
"normalized": false,
|
| 39 |
+
"rstrip": false,
|
| 40 |
+
"single_word": false,
|
| 41 |
+
"special": true
|
| 42 |
+
}
|
| 43 |
+
},
|
| 44 |
+
"bos_token": "[CLS]",
|
| 45 |
+
"clean_up_tokenization_spaces": false,
|
| 46 |
+
"cls_token": "[CLS]",
|
| 47 |
+
"do_lower_case": false,
|
| 48 |
+
"eos_token": "[SEP]",
|
| 49 |
+
"extra_special_tokens": {},
|
| 50 |
+
"mask_token": "[MASK]",
|
| 51 |
+
"model_max_length": 1000000000000000019884624838656,
|
| 52 |
+
"pad_token": "[PAD]",
|
| 53 |
+
"sep_token": "[SEP]",
|
| 54 |
+
"sp_model_kwargs": {},
|
| 55 |
+
"split_by_punct": false,
|
| 56 |
+
"tokenizer_class": "DebertaV2Tokenizer",
|
| 57 |
+
"unk_token": "[UNK]",
|
| 58 |
+
"vocab_type": "spm"
|
| 59 |
+
}
|
training_args.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8be3a1f87fad7cf785f293332454e518ddf28a5b95bc2d604a6d7b06f1d6e8ce
|
| 3 |
+
size 5713
|
verify_model.py
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Model verification script for DeBERTa v3 Small Explicit Classifier v2.0
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import json
|
| 7 |
+
import torch
|
| 8 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
|
| 11 |
+
def verify_model_integrity():
|
| 12 |
+
"""Verify all model files and configurations"""
|
| 13 |
+
print("π Verifying DeBERTa v3 Small Explicit Classifier v2.0")
|
| 14 |
+
print("=" * 60)
|
| 15 |
+
|
| 16 |
+
model_path = Path(".")
|
| 17 |
+
|
| 18 |
+
# Check required files
|
| 19 |
+
required_files = [
|
| 20 |
+
"model.safetensors",
|
| 21 |
+
"config.json",
|
| 22 |
+
"tokenizer.json",
|
| 23 |
+
"spm.model",
|
| 24 |
+
"label_mapping.json",
|
| 25 |
+
"README.md"
|
| 26 |
+
]
|
| 27 |
+
|
| 28 |
+
print("π Checking required files...")
|
| 29 |
+
missing_files = []
|
| 30 |
+
for file_name in required_files:
|
| 31 |
+
if (model_path / file_name).exists():
|
| 32 |
+
print(f" β
{file_name}")
|
| 33 |
+
else:
|
| 34 |
+
print(f" β {file_name} - MISSING")
|
| 35 |
+
missing_files.append(file_name)
|
| 36 |
+
|
| 37 |
+
if missing_files:
|
| 38 |
+
print(f"\nβ οΈ Missing files: {missing_files}")
|
| 39 |
+
return False
|
| 40 |
+
|
| 41 |
+
# Load and verify model
|
| 42 |
+
print("\nπ€ Loading model...")
|
| 43 |
+
try:
|
| 44 |
+
model = AutoModelForSequenceClassification.from_pretrained(".")
|
| 45 |
+
tokenizer = AutoTokenizer.from_pretrained(".")
|
| 46 |
+
print(" β
Model loaded successfully")
|
| 47 |
+
except Exception as e:
|
| 48 |
+
print(f" β Model loading failed: {e}")
|
| 49 |
+
return False
|
| 50 |
+
|
| 51 |
+
# Verify configuration
|
| 52 |
+
print("\nβοΈ Verifying configuration...")
|
| 53 |
+
config = model.config
|
| 54 |
+
|
| 55 |
+
expected_labels = {
|
| 56 |
+
0: "EXPLICIT-DISCLAIMER",
|
| 57 |
+
1: "EXPLICIT-OFFENSIVE",
|
| 58 |
+
2: "EXPLICIT-SEXUAL",
|
| 59 |
+
3: "EXPLICIT-VIOLENT",
|
| 60 |
+
4: "NON-EXPLICIT",
|
| 61 |
+
5: "SEXUAL-REFERENCE",
|
| 62 |
+
6: "SUGGESTIVE"
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
# Check label mappings
|
| 66 |
+
config_labels = {int(k): v for k, v in config.id2label.items()}
|
| 67 |
+
if config_labels == expected_labels:
|
| 68 |
+
print(" β
Label mappings correct")
|
| 69 |
+
else:
|
| 70 |
+
print(" β Label mappings incorrect")
|
| 71 |
+
print(f" Expected: {expected_labels}")
|
| 72 |
+
print(f" Got: {config_labels}")
|
| 73 |
+
return False
|
| 74 |
+
|
| 75 |
+
# Verify model parameters
|
| 76 |
+
total_params = sum(p.numel() for p in model.parameters())
|
| 77 |
+
expected_params = 141_900_000 # Approximately 141.9M
|
| 78 |
+
|
| 79 |
+
if abs(total_params - expected_params) < 1_000_000: # Within 1M tolerance
|
| 80 |
+
print(f" β
Parameter count: {total_params:,} (~{total_params/1_000_000:.1f}M)")
|
| 81 |
+
else:
|
| 82 |
+
print(f" β οΈ Unexpected parameter count: {total_params:,}")
|
| 83 |
+
|
| 84 |
+
# Test inference
|
| 85 |
+
print("\nπ§ͺ Testing inference...")
|
| 86 |
+
try:
|
| 87 |
+
test_text = "This is a test sentence for classification."
|
| 88 |
+
inputs = tokenizer(test_text, return_tensors="pt", truncation=True, max_length=512)
|
| 89 |
+
|
| 90 |
+
with torch.no_grad():
|
| 91 |
+
outputs = model(**inputs)
|
| 92 |
+
logits = outputs.logits
|
| 93 |
+
probabilities = torch.softmax(logits, dim=-1)
|
| 94 |
+
|
| 95 |
+
# Check output shape
|
| 96 |
+
if probabilities.shape == (1, 7): # Batch size 1, 7 classes
|
| 97 |
+
print(" β
Inference successful")
|
| 98 |
+
|
| 99 |
+
# Show predictions
|
| 100 |
+
predicted_class = torch.argmax(probabilities, dim=-1).item()
|
| 101 |
+
confidence = probabilities[0][predicted_class].item()
|
| 102 |
+
predicted_label = config.id2label[predicted_class]
|
| 103 |
+
|
| 104 |
+
print(f" Test prediction: {predicted_label} ({confidence:.3f})")
|
| 105 |
+
else:
|
| 106 |
+
print(f" β Unexpected output shape: {probabilities.shape}")
|
| 107 |
+
return False
|
| 108 |
+
|
| 109 |
+
except Exception as e:
|
| 110 |
+
print(f" β Inference failed: {e}")
|
| 111 |
+
return False
|
| 112 |
+
|
| 113 |
+
# Check evaluation files
|
| 114 |
+
print("\nπ Checking evaluation files...")
|
| 115 |
+
eval_files = [
|
| 116 |
+
"improved_classification_report.txt",
|
| 117 |
+
"recommended_thresholds.json",
|
| 118 |
+
"confusion_matrix.png",
|
| 119 |
+
"pr_curves.png",
|
| 120 |
+
"roc_curves.png",
|
| 121 |
+
"calibration.png"
|
| 122 |
+
]
|
| 123 |
+
|
| 124 |
+
for file_name in eval_files:
|
| 125 |
+
if (model_path / file_name).exists():
|
| 126 |
+
print(f" β
{file_name}")
|
| 127 |
+
else:
|
| 128 |
+
print(f" βͺ {file_name} - Optional")
|
| 129 |
+
|
| 130 |
+
# Verify thresholds file
|
| 131 |
+
try:
|
| 132 |
+
with open("recommended_thresholds.json", "r") as f:
|
| 133 |
+
thresholds = json.load(f)
|
| 134 |
+
|
| 135 |
+
if len(thresholds) == 7: # 7 classes
|
| 136 |
+
print(" β
Thresholds file valid")
|
| 137 |
+
else:
|
| 138 |
+
print(f" β οΈ Unexpected threshold count: {len(thresholds)}")
|
| 139 |
+
except Exception as e:
|
| 140 |
+
print(f" β οΈ Could not verify thresholds: {e}")
|
| 141 |
+
|
| 142 |
+
print("\nπ Model verification complete!")
|
| 143 |
+
print("β
All core components verified and working correctly")
|
| 144 |
+
print("\nπ¦ Ready for deployment!")
|
| 145 |
+
|
| 146 |
+
return True
|
| 147 |
+
|
| 148 |
+
def show_model_info():
|
| 149 |
+
"""Display model information summary"""
|
| 150 |
+
print("\nπ Model Information Summary")
|
| 151 |
+
print("-" * 40)
|
| 152 |
+
|
| 153 |
+
try:
|
| 154 |
+
model = AutoModelForSequenceClassification.from_pretrained(".")
|
| 155 |
+
config = model.config
|
| 156 |
+
|
| 157 |
+
print(f"Model Type: {config.model_type}")
|
| 158 |
+
print(f"Architecture: {config.architectures[0]}")
|
| 159 |
+
print(f"Parameters: {sum(p.numel() for p in model.parameters()):,}")
|
| 160 |
+
print(f"Layers: {config.num_hidden_layers}")
|
| 161 |
+
print(f"Hidden Size: {config.hidden_size}")
|
| 162 |
+
print(f"Attention Heads: {config.num_attention_heads}")
|
| 163 |
+
print(f"Max Length: {config.max_position_embeddings}")
|
| 164 |
+
print(f"Vocabulary Size: {config.vocab_size:,}")
|
| 165 |
+
print(f"Classes: {len(config.id2label)}")
|
| 166 |
+
|
| 167 |
+
print(f"\nClass Labels:")
|
| 168 |
+
for id_str, label in config.id2label.items():
|
| 169 |
+
print(f" {id_str}: {label}")
|
| 170 |
+
|
| 171 |
+
except Exception as e:
|
| 172 |
+
print(f"Error loading model info: {e}")
|
| 173 |
+
|
| 174 |
+
if __name__ == "__main__":
|
| 175 |
+
success = verify_model_integrity()
|
| 176 |
+
|
| 177 |
+
if success:
|
| 178 |
+
show_model_info()
|
| 179 |
+
else:
|
| 180 |
+
print("\nβ Verification failed - please check the issues above")
|
| 181 |
+
exit(1)
|