A medium-sized, high-capacity text detoxification model for advanced toxicity removal while preserving meaning.
Built by Minibase - Train and deploy small AI models from your browser. Browse all of the models and datasets available on the Minibase Marketplace.
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.
Install llama.cpp (if not already installed):
git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp && make
Download and run the model:
# 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
Make API calls:
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!"
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!"
| 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 |
| 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:
| 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:
| 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:
# 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!"
# 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."
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!"
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)
# 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
# If using the provided MacOS app bundle
cd /path/to/downloaded/model
./Minibase-detoxify-medium.app/Contents/MacOS/run_server
| 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 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 |
| 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 |
| 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 |
We welcome contributions! Please see our Contributing Guide for details.
# 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/
If you use Detoxify-Medium in your research, please cite:
@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}
}
This model is released under the Apache License 2.0).
Built with ❤️ by the Minibase team
Making AI more accessible for everyone