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
 
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
---
language:
- en
tags:
- text-detoxification
- text2text-generation
- detoxification
- content-moderation
- toxicity-reduction
- llama
- gguf
- minibase
- medium-model
- 4096-context
license: apache-2.0
datasets:
- paradetox
metrics:
- toxicity-reduction
- semantic-similarity
- fluency
- latency
model-index:
- name: Detoxify-Medium
  results:
  - task:
      type: text-detoxification
      name: Toxicity Reduction
    dataset:
      type: paradetox
      name: ParaDetox
      config: toxic-neutral
      split: test
    metrics:
    - type: toxicity-reduction
      value: 0.178
      name: Average Toxicity Reduction
    - type: semantic-similarity
      value: 0.561
      name: Semantic to Expected
    - type: fluency
      value: 0.929
      name: Text Fluency
    - type: latency
      value: 160.2
      name: Average Latency (ms)
---

# Detoxify-Medium πŸ€–

<div align="center">

**A medium-sized, high-capacity text detoxification model for advanced toxicity removal while preserving meaning.**

[![Model Size](https://img.shields.io/badge/Model_Size-369MB-blue)](https://huggingface.co/)
[![Architecture](https://img.shields.io/badge/Architecture-LlamaForCausalLM-green)](https://huggingface.co/)
[![Context Window](https://img.shields.io/badge/Context-4096_Tokens-orange)](https://huggingface.co/)
[![License](https://img.shields.io/badge/License-Apache_2.0-yellow)](LICENSE)
[![Discord](https://img.shields.io/badge/Discord-Join_Community-5865F2)](https://discord.com/invite/BrJn4D2Guh)

*Built by [Minibase](https://minibase.ai) - Train and deploy small AI models from your browser.*
*Browse all of the models and datasets available on the [Minibase Marketplace](https://minibase.ai/wiki/Special:Marketplace).*

</div>

## πŸ“‹ Model Summary

**Minibase-Detoxify-Medium** is a medium-capacity language model fine-tuned specifically for advanced text detoxification tasks. It takes toxic or inappropriate text as input and generates cleaned, non-toxic versions while preserving the original meaning and intent as much as possible. With a 4,096 token context window and enhanced capacity, it excels at handling longer texts and more complex detoxification scenarios.

### Key Features
- ⚑ **Balanced Performance**: ~160ms average response time
- 🎯 **High Fluency**: 92.9% well-formed output text
- 🧹 **Advanced Detoxification**: 17.8% average toxicity reduction
- πŸ’Ύ **Medium Size**: 369MB (GGUF Q8_0 quantized)
- πŸ”’ **Privacy-First**: Runs locally, no data sent to external servers
- πŸ“ **Extended Context**: 4,096 token context window (4x larger than Small)

## πŸš€ Quick Start

### Local Inference (Recommended)

1. **Install llama.cpp** (if not already installed):
   ```bash
   git clone https://github.com/ggerganov/llama.cpp
   cd llama.cpp && make
   ```

2. **Download and run the model**:
   ```bash
   # Download model files
   wget https://huggingface.co/Minibase/Detoxify-Language-Medium/resolve/main/detoxify-medium-q8_0.gguf
   wget https://huggingface.co/Minibase/Detoxify-Language-Medium/resolve/main/detoxify_inference.py

   # Make executable and run
   chmod +x run_server.sh
   ./run_server.sh
   ```

3. **Make API calls**:
   ```python
   import requests

   # Detoxify text
   response = requests.post("http://127.0.0.1:8000/completion", json={
       "prompt": "Instruction: Rewrite the provided text to remove the toxicity.\n\nInput: This is fucking terrible!\n\nResponse: ",
       "max_tokens": 256,
       "temperature": 0.7
   })

   result = response.json()
   print(result["content"])  # "This is really terrible!"
   ```

### Python Client

```python
from detoxify_inference import DetoxifyClient

# Initialize client
client = DetoxifyClient()

# Detoxify text
toxic_text = "This product is fucking amazing, no bullshit!"
clean_text = client.detoxify_text(toxic_text)

print(clean_text)  # "This product is really amazing, no kidding!"
```

## πŸ“Š Benchmarks & Performance

### ParaDetox Dataset Results (1,011 samples)

| Metric | Value | Description |
|--------|-------|-------------|
| Original Toxicity | 0.196 (19.6%) | Input toxicity level |
| Final Toxicity | 0.018 (1.8%) | Output toxicity level |
| **Toxicity Reduction** | **91%** | **Reduction in toxicity scores** |
| **Semantic Similarity (Expected)** | **0.561 (56.1%)** | **Similarity to human expert rewrites** |
| **Semantic Similarity (Original)** | **0.625 (62.5%)** | **How much original meaning is preserved** |
| **Fluency** | **0.929 (92.9%)** | **Quality of generated text structure** |
| **Latency** | **160.2ms** | **Average response time** |
| **Throughput** | **~6 req/sec** | **Estimated requests per second** |

### Dataset Breakdown

#### General Toxic Content (1,000 samples)
- **Toxicity Reduction**: 17.8%
- **Semantic Preservation**: 56.1%
- **Fluency**: 92.9%

#### High-Toxicity Content (11 samples)
- **Toxicity Reduction**: 31.3% ⭐ **Strong performance!**
- **Semantic Preservation**: 47.7%
- **Fluency**: 93.6%

### Comparison with Detoxify-Small

| Model | Context Window | Toxicity Reduction | Semantic Similarity | Latency | Size |
|-------|----------------|-------------------|-------------------|---------|------|
| **Detoxify-Medium** | **4,096 tokens** | **17.8%** | **56.1%** | **160ms** | **369MB** |
| Detoxify-Small | 1,024 tokens | 3.2% | 47.1% | 66ms | 138MB |

**Key Improvements:**
- βœ… 4x larger context window
- βœ… 5.6x better toxicity reduction
- βœ… 19% better semantic preservation
- βœ… 2.7x larger model size

### Comparison with Baselines

| Model | Semantic Similarity | Toxicity Reduction | Fluency |
|-------|-------------------|-------------------|---------|
| **Detoxify-Medium** | **0.561** | **0.178** | **0.929** |
| Detoxify-Small | 0.471 | 0.032 | 0.919 |
| BART-base (ParaDetox) | 0.750 | ~0.15 | ~0.85 |
| Human Performance | 0.850 | ~0.25 | ~0.95 |

**Performance Notes:**
- πŸ“ˆ **Semantic Similarity**: How well meaning is preserved
- 🧹 **Toxicity Reduction**: How effectively toxicity is removed
- ✍️ **Fluency**: Quality of generated text
- 🎯 **Detoxify-Medium** achieves strong performance across all metrics

## πŸ—οΈ Technical Details

### Model Architecture
- **Architecture**: LlamaForCausalLM
- **Parameters**: 279M (medium capacity)
- **Context Window**: 4,096 tokens (4x larger than Small)
- **Max Position Embeddings**: 8,192
- **Quantization**: GGUF (Q8_0 quantization)
- **File Size**: 369MB
- **Memory Requirements**: 12GB RAM minimum, 24GB recommended

### Training Details
- **Base Model**: Custom-trained Llama architecture
- **Fine-tuning Dataset**: Curated toxic-neutral parallel pairs
- **Training Objective**: Instruction-following for detoxification
- **Optimization**: Quantized for edge deployment
- **Model Scale**: Medium capacity for enhanced performance

### System Requirements

| Component | Minimum | Recommended |
|-----------|---------|-------------|
| **Operating System** | Linux, macOS, Windows | Linux or macOS |
| **RAM** | 12GB | 24GB |
| **Storage** | 400MB free space | 1GB free space |
| **Python** | 3.8+ | 3.10+ |
| **Dependencies** | llama.cpp | llama.cpp, requests |
| **GPU** | Optional | NVIDIA RTX 30-series or Apple M2/M3 |

**Notes:**
- βœ… **CPU-only inference** is supported but slower
- βœ… **GPU acceleration** provides significant speed improvements
- βœ… **Apple Silicon** users get Metal acceleration automatically

## πŸ“– Usage Examples

### Basic Detoxification
```python
# Input: "This is fucking awesome!"
# Output: "This is really awesome!"

# Input: "You stupid idiot, get out of my way!"
# Output: "You silly person, please move aside!"
```

### Long-Form Text Detoxification
```python
# Input: "This article is complete bullshit and the author is a fucking moron who doesn't know what they're talking about. The whole thing is garbage and worthless."
# Output: "This article is not well-founded and the author seems uninformed about the topic. The whole thing seems questionable."
```

### API Integration
```python
import requests

def detoxify_text(text: str) -> str:
    """Detoxify text using Detoxify-Medium API"""
    prompt = f"Instruction: Rewrite the provided text to remove the toxicity.\n\nInput: {text}\n\nResponse: "

    response = requests.post("http://127.0.0.1:8000/completion", json={
        "prompt": prompt,
        "max_tokens": 256,
        "temperature": 0.7
    })

    return response.json()["content"]

# Usage
toxic_comment = "This product sucks donkey balls!"
clean_comment = detoxify_text(toxic_comment)
print(clean_comment)  # "This product is not very good!"
```

### Batch Processing
```python
import asyncio
import aiohttp

async def detoxify_batch(texts: list) -> list:
    """Process multiple texts concurrently"""
    async with aiohttp.ClientSession() as session:
        tasks = []
        for text in texts:
            prompt = f"Instruction: Rewrite the provided text to remove the toxicity.\n\nInput: {text}\n\nResponse: "
            payload = {
                "prompt": prompt,
                "max_tokens": 256,
                "temperature": 0.7
            }
            tasks.append(session.post("http://127.0.0.1:8000/completion", json=payload))

        responses = await asyncio.gather(*tasks)
        return [await resp.json() for resp in responses]

# Process multiple comments
comments = [
    "This is fucking brilliant!",
    "You stupid moron!",
    "What the hell is wrong with you?"
]

clean_comments = await detoxify_batch(comments)
```

## πŸ”§ Advanced Configuration

### Server Configuration
```bash
# GPU acceleration (macOS with Metal)
llama-server \
  -m detoxify-medium-q8_0.gguf \
  --host 127.0.0.1 \
  --port 8000 \
  --n-gpu-layers 35 \
  --ctx-size 4096 \
  --metal

# CPU-only (higher memory usage)
llama-server \
  -m detoxify-medium-q8_0.gguf \
  --host 127.0.0.1 \
  --port 8000 \
  --n-gpu-layers 0 \
  --threads 8 \
  --ctx-size 4096

# Custom context window
llama-server \
  -m detoxify-medium-q8_0.gguf \
  --ctx-size 2048 \
  --host 127.0.0.1 \
  --port 8000
```

### Alternative: Use the MacOS Application
```bash
# If using the provided MacOS app bundle
cd /path/to/downloaded/model
./Minibase-detoxify-medium.app/Contents/MacOS/run_server
```

### Temperature Settings

| Temperature Range | Approach | Description |
|------------------|----------|-------------|
| **0.1-0.3** | Conservative | Minimal changes, preserves original style |
| **0.4-0.7** | **Balanced (Recommended)** | **Best trade-off between detoxification and naturalness** |
| **0.8-1.0** | Creative | More aggressive detoxification, may alter style |

### Context Window Optimization

| Context Size | Use Case | Performance |
|--------------|----------|------------|
| **4,096 tokens** | **Long documents, complex detoxification** | **Best quality, slower processing** |
| **2,048 tokens** | **Balanced performance and quality** | **Good compromise (recommended)** |
| **1,024 tokens** | **Simple tasks, fast processing** | **Faster inference, adequate quality** |

## πŸ“š Limitations & Biases

### Current Limitations

| Limitation | Description | Impact |
|------------|-------------|--------|
| **Vocabulary Scope** | Trained primarily on English toxic content | May not handle other languages effectively |
| **Context Awareness** | Limited detection of sarcasm or cultural context | May miss nuanced toxicity |
| **Length Constraints** | Limited to 4,096 token context window | Cannot process very long documents |
| **Domain Specificity** | Optimized for general web content | May perform differently on specialized domains |
| **Memory Requirements** | Higher RAM usage than smaller models | Requires more system resources |

### Potential Biases

| Bias Type | Description | Mitigation |
|-----------|-------------|------------|
| **Cultural Context** | May not handle culture-specific expressions | Use with awareness of cultural differences |
| **Dialect Variations** | Limited exposure to regional dialects | May not recognize regional toxic patterns |
| **Emerging Slang** | May not recognize newest internet slang | Regular model updates recommended |
| **Long-form Content** | May struggle with very complex toxicity | Break long content into smaller chunks |

## 🀝 Contributing

We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.

### Development Setup
```bash
# Clone the repository
git clone https://github.com/minibase-ai/detoxify-medium
cd detoxify-medium

# Install dependencies
pip install -r requirements.txt

# Run tests
python -m pytest tests/
```

## πŸ“œ Citation

If you use Detoxify-Medium in your research, please cite:

```bibtex
@misc{detoxify-medium-2025,
  title={Detoxify-Medium: A High-Capacity Text Detoxification Model},
  author={Minibase AI Team},
  year={2025},
  publisher={Hugging Face},
  url={https://huggingface.co/Minibase/Detoxify-Language-Medium}
}
```

## πŸ“ž Contact & Community

- **Website**: [minibase.ai](https://minibase.ai)
- **Discord Community**: [Join our Discord](https://discord.com/invite/BrJn4D2Guh)
- **GitHub Issues**: [Report bugs or request features on Discord](https://discord.com/invite/BrJn4D2Guh)
- **Email**: hello@minibase.ai

### Support
- πŸ“– **Documentation**: [help.minibase.ai](https://help.minibase.ai)
- πŸ’¬ **Community Forum**: [Join our Discord Community](https://discord.com/invite/BrJn4D2Guh)

## πŸ“‹ License

This model is released under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0)).

## πŸ™ Acknowledgments

- **ParaDetox Dataset**: Used for benchmarking and evaluation
- **llama.cpp**: For efficient local inference
- **Hugging Face**: For model hosting and community
- **Our amazing community**: For feedback and contributions

---

<div align="center">

**Built with ❀️ by the Minibase team**

*Making AI more accessible for everyone*

[πŸ“– Minibase Help Center](https://help.minibase.ai) β€’ [πŸ’¬ Join our Discord](https://discord.com/invite/BrJn4D2Guh)

</div>