Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,199 +1,263 @@
|
|
| 1 |
-
---
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
-
|
| 22 |
-
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
**
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language: en
|
| 3 |
+
license: apache-2.0
|
| 4 |
+
tags:
|
| 5 |
+
- toxicity-detection
|
| 6 |
+
- text-classification
|
| 7 |
+
- dendritic-optimization
|
| 8 |
+
- perforated-backpropagation
|
| 9 |
+
- bert-tiny
|
| 10 |
+
- efficient-ml
|
| 11 |
+
datasets:
|
| 12 |
+
- jigsaw-toxic-comment-classification-challenge
|
| 13 |
+
metrics:
|
| 14 |
+
- f1
|
| 15 |
+
- accuracy
|
| 16 |
+
- precision
|
| 17 |
+
- recall
|
| 18 |
+
model-index:
|
| 19 |
+
- name: dendritic-bert-tiny-toxicity
|
| 20 |
+
results:
|
| 21 |
+
- task:
|
| 22 |
+
type: text-classification
|
| 23 |
+
name: Toxicity Detection
|
| 24 |
+
dataset:
|
| 25 |
+
name: Civil Comments
|
| 26 |
+
type: jigsaw_toxicity_pred
|
| 27 |
+
metrics:
|
| 28 |
+
- type: f1
|
| 29 |
+
value: 0.358
|
| 30 |
+
name: F1 Score (Toxic Class)
|
| 31 |
+
- type: accuracy
|
| 32 |
+
value: 0.918
|
| 33 |
+
name: Accuracy
|
| 34 |
+
- type: inference_time
|
| 35 |
+
value: 2.25
|
| 36 |
+
name: Inference Latency (ms)
|
| 37 |
+
---
|
| 38 |
+
|
| 39 |
+
# Dendritic BERT-Tiny for Toxicity Detection
|
| 40 |
+
|
| 41 |
+
## Model Description
|
| 42 |
+
|
| 43 |
+
This model applies **Perforated Backpropagation with Dendritic Optimization** to enhance a compact BERT-Tiny model (4.8M parameters) for toxicity classification. It achieves performance comparable to BERT-Base (109M parameters) while maintaining **17.8x faster inference speed**.
|
| 44 |
+
|
| 45 |
+
**Key Features:**
|
| 46 |
+
- **22.8x smaller** than BERT-Base (4.8M vs 109M parameters)
|
| 47 |
+
- **17.8x faster** inference (2.25ms vs 40ms)
|
| 48 |
+
- **Superior toxic detection** (F1=0.358 vs BERT-Base F1=0.05)
|
| 49 |
+
- **Dendritic optimization** using PerforatedAI
|
| 50 |
+
- **Edge-ready** for real-time deployment
|
| 51 |
+
|
| 52 |
+
## Model Details
|
| 53 |
+
|
| 54 |
+
- **Model Type:** BERT-Tiny with Dendritic Optimization
|
| 55 |
+
- **Language:** English
|
| 56 |
+
- **Task:** Binary Text Classification (Toxic/Non-Toxic)
|
| 57 |
+
- **Base Model:** [prajjwal1/bert-tiny](https://huggingface.co/prajjwal1/bert-tiny)
|
| 58 |
+
- **Framework:** PyTorch 2.9.1 + PerforatedAI 3.0.7
|
| 59 |
+
- **Parameters:** 4,798,468
|
| 60 |
+
- **Model Size:** 19.3 MB
|
| 61 |
+
|
| 62 |
+
## Performance Metrics
|
| 63 |
+
|
| 64 |
+
| Metric | Dendritic BERT-Tiny | BERT-Base | Improvement |
|
| 65 |
+
|--------|---------------------|-----------|-------------|
|
| 66 |
+
| **Parameters** | 4.8M | 109M | 22.8x smaller |
|
| 67 |
+
| **F1 Score (Toxic)** | 0.358 | 0.050 | 7.16x better |
|
| 68 |
+
| **Accuracy** | 91.8% | 91.0% | +0.8% |
|
| 69 |
+
| **Inference Time** | 2.25ms | 40.1ms | 17.8x faster |
|
| 70 |
+
| **Throughput** | 444 samples/s | 25 samples/s | 17.8x higher |
|
| 71 |
+
|
| 72 |
+
## Intended Use
|
| 73 |
+
|
| 74 |
+
### Primary Use Cases
|
| 75 |
+
- Real-time content moderation in online forums and social media
|
| 76 |
+
- Edge device deployment for resource-constrained environments
|
| 77 |
+
- High-throughput toxicity screening systems
|
| 78 |
+
- Research in efficient NLP and dendritic optimization
|
| 79 |
+
|
| 80 |
+
### Limitations
|
| 81 |
+
- Trained on Civil Comments dataset (English only)
|
| 82 |
+
- May not generalize to all forms of toxicity or cultural contexts
|
| 83 |
+
- Class imbalance handling (94% non-toxic samples)
|
| 84 |
+
- Best suited for binary toxicity detection
|
| 85 |
+
|
| 86 |
+
## How to Use
|
| 87 |
+
|
| 88 |
+
### Installation
|
| 89 |
+
|
| 90 |
+
```bash
|
| 91 |
+
pip install transformers torch perforatedai
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
### Quick Start
|
| 95 |
+
|
| 96 |
+
```python
|
| 97 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 98 |
+
import torch
|
| 99 |
+
|
| 100 |
+
# Load model and tokenizer
|
| 101 |
+
model_name = "your-username/dendritic-bert-tiny-toxicity"
|
| 102 |
+
tokenizer = AutoTokenizer.from_pretrained("prajjwal1/bert-tiny")
|
| 103 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 104 |
+
|
| 105 |
+
# Prepare input
|
| 106 |
+
text = "This is a sample comment to classify"
|
| 107 |
+
inputs = tokenizer(text, return_tensors="pt", max_length=128, truncation=True, padding=True)
|
| 108 |
+
|
| 109 |
+
# Inference
|
| 110 |
+
model.eval()
|
| 111 |
+
with torch.no_grad():
|
| 112 |
+
outputs = model(**inputs)
|
| 113 |
+
logits = outputs.logits
|
| 114 |
+
prediction = torch.argmax(logits, dim=-1)
|
| 115 |
+
|
| 116 |
+
# Get result
|
| 117 |
+
label = "toxic" if prediction.item() == 1 else "non-toxic"
|
| 118 |
+
confidence = torch.softmax(logits, dim=-1)[0][prediction].item()
|
| 119 |
+
print(f"Prediction: {label} (confidence: {confidence:.2%})")
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
### Batch Processing for High Throughput
|
| 123 |
+
|
| 124 |
+
```python
|
| 125 |
+
import torch
|
| 126 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 127 |
+
|
| 128 |
+
model_name = "your-username/dendritic-bert-tiny-toxicity"
|
| 129 |
+
tokenizer = AutoTokenizer.from_pretrained("prajjwal1/bert-tiny")
|
| 130 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 131 |
+
|
| 132 |
+
# Example batch of comments
|
| 133 |
+
comments = [
|
| 134 |
+
"This is a great discussion!",
|
| 135 |
+
"You are absolutely terrible",
|
| 136 |
+
"I disagree but respect your opinion",
|
| 137 |
+
]
|
| 138 |
+
|
| 139 |
+
# Tokenize batch
|
| 140 |
+
inputs = tokenizer(comments, return_tensors="pt", max_length=128,
|
| 141 |
+
truncation=True, padding=True)
|
| 142 |
+
|
| 143 |
+
# Batch inference
|
| 144 |
+
model.eval()
|
| 145 |
+
with torch.no_grad():
|
| 146 |
+
outputs = model(**inputs)
|
| 147 |
+
predictions = torch.argmax(outputs.logits, dim=-1)
|
| 148 |
+
probabilities = torch.softmax(outputs.logits, dim=-1)
|
| 149 |
+
|
| 150 |
+
# Display results
|
| 151 |
+
for comment, pred, probs in zip(comments, predictions, probabilities):
|
| 152 |
+
label = "toxic" if pred.item() == 1 else "non-toxic"
|
| 153 |
+
confidence = probs[pred].item()
|
| 154 |
+
print(f"'{comment}' -> {label} ({confidence:.2%})")
|
| 155 |
+
```
|
| 156 |
+
|
| 157 |
+
### Edge Deployment with Quantization
|
| 158 |
+
|
| 159 |
+
```python
|
| 160 |
+
import torch
|
| 161 |
+
from transformers import AutoModelForSequenceClassification
|
| 162 |
+
|
| 163 |
+
model = AutoModelForSequenceClassification.from_pretrained(
|
| 164 |
+
"your-username/dendritic-bert-tiny-toxicity"
|
| 165 |
+
)
|
| 166 |
+
|
| 167 |
+
# Dynamic quantization for edge devices
|
| 168 |
+
quantized_model = torch.quantization.quantize_dynamic(
|
| 169 |
+
model, {torch.nn.Linear}, dtype=torch.qint8
|
| 170 |
+
)
|
| 171 |
+
|
| 172 |
+
# Model is now ~75% smaller and faster on CPU
|
| 173 |
+
```
|
| 174 |
+
|
| 175 |
+
## Training Details
|
| 176 |
+
|
| 177 |
+
### Training Dataset
|
| 178 |
+
- **Source:** Civil Comments / Jigsaw Toxicity Dataset
|
| 179 |
+
- **Train samples:** 5,000 (4.54% toxic)
|
| 180 |
+
- **Validation samples:** 1,000 (6.60% toxic)
|
| 181 |
+
- **Test samples:** 1,000 (9.00% toxic)
|
| 182 |
+
|
| 183 |
+
### Training Procedure
|
| 184 |
+
- **Optimizer:** AdamW (lr=2e-5, weight_decay=0.01)
|
| 185 |
+
- **Epochs:** 10
|
| 186 |
+
- **Batch size:** 32
|
| 187 |
+
- **Max sequence length:** 128 tokens
|
| 188 |
+
- **Loss function:** Cross-entropy with class weights (1.0, 21.0)
|
| 189 |
+
- **Warmup steps:** 500
|
| 190 |
+
- **Early stopping:** Patience 3 epochs
|
| 191 |
+
|
| 192 |
+
### Dendritic Optimization
|
| 193 |
+
This model uses **Perforated Backpropagation** with dendritic nodes to enhance learning capacity:
|
| 194 |
+
- Correlation threshold: 0.95
|
| 195 |
+
- Perforated AI version: 3.0.7
|
| 196 |
+
- Configuration: 3D tensor output dimensions for transformer layers
|
| 197 |
+
|
| 198 |
+
## Technical Architecture
|
| 199 |
+
|
| 200 |
+
```
|
| 201 |
+
Input Text (max 128 tokens)
|
| 202 |
+
↓
|
| 203 |
+
BERT-Tiny Tokenizer
|
| 204 |
+
↓
|
| 205 |
+
Embedding Layer (vocab_size: 30522, hidden: 128)
|
| 206 |
+
↓
|
| 207 |
+
Transformer Layer 1 (2 attention heads) + Dendritic Nodes
|
| 208 |
+
↓
|
| 209 |
+
Transformer Layer 2 (2 attention heads) + Dendritic Nodes
|
| 210 |
+
↓
|
| 211 |
+
Pooler Layer (CLS token)
|
| 212 |
+
↓
|
| 213 |
+
Classification Head (128 → 2)
|
| 214 |
+
↓
|
| 215 |
+
Output: [non-toxic_logit, toxic_logit]
|
| 216 |
+
```
|
| 217 |
+
|
| 218 |
+
## Ethical Considerations
|
| 219 |
+
|
| 220 |
+
### Bias and Fairness
|
| 221 |
+
- Model may inherit biases from the Civil Comments dataset
|
| 222 |
+
- Performance may vary across demographic groups and cultural contexts
|
| 223 |
+
- Should not be the sole decision-maker in content moderation
|
| 224 |
+
|
| 225 |
+
### Recommended Practices
|
| 226 |
+
- Use as part of a human-in-the-loop moderation system
|
| 227 |
+
- Regularly evaluate for fairness across user demographics
|
| 228 |
+
- Combine with other signals for critical decisions
|
| 229 |
+
- Provide appeal mechanisms for users
|
| 230 |
+
|
| 231 |
+
## Citation
|
| 232 |
+
|
| 233 |
+
If you use this model in your research, please cite:
|
| 234 |
+
|
| 235 |
+
```bibtex
|
| 236 |
+
@misc{dendritic-bert-tiny-2026,
|
| 237 |
+
title={Giant-Killer NLP: Dendritic Optimization for Toxicity Classification},
|
| 238 |
+
author={PROJECT-Z Team},
|
| 239 |
+
year={2026},
|
| 240 |
+
publisher={HuggingFace Hub},
|
| 241 |
+
howpublished={\url{https://huggingface.co/your-username/dendritic-bert-tiny-toxicity}},
|
| 242 |
+
note={PyTorch Dendritic Optimization Hackathon}
|
| 243 |
+
}
|
| 244 |
+
```
|
| 245 |
+
|
| 246 |
+
## Acknowledgments
|
| 247 |
+
|
| 248 |
+
- **Base Model:** BERT-Tiny by [prajjwal1](https://huggingface.co/prajjwal1)
|
| 249 |
+
- **Optimization Framework:** [PerforatedAI](https://perforatedai.com/)
|
| 250 |
+
- **Dataset:** Jigsaw/Google Civil Comments
|
| 251 |
+
- **Hackathon:** PyTorch Dendritic Optimization Challenge
|
| 252 |
+
|
| 253 |
+
## License
|
| 254 |
+
|
| 255 |
+
Apache 2.0
|
| 256 |
+
|
| 257 |
+
## Contact
|
| 258 |
+
|
| 259 |
+
For questions, issues, or collaboration opportunities, please open an issue on the [GitHub repository](https://github.com/your-username/dendritic-bert-tiny-toxicity).
|
| 260 |
+
|
| 261 |
+
---
|
| 262 |
+
|
| 263 |
+
**Developed for the PyTorch Dendritic Optimization Hackathon - January 2026**
|