Retentive Network: A Successor to Transformer for Large Language Models
Paper
β’
2307.08621
β’
Published
β’
172
A high-performance RetNet model for classifying text content by explicitness level, designed for large-scale content moderation and filtering applications.
| Attribute | Value |
|---|---|
| Model Type | RetNet (Linear Attention) |
| Parameters | 45,029,943 |
| Task | 7-class text classification |
| Performance | 74.4% accuracy, 63.9% macro F1 |
| Speed | 1,574 paragraphs/second |
| Training Time | 4.9 hours |
| Model | Parameters | Accuracy | Macro F1 | Speed | Architecture |
|---|---|---|---|---|---|
| DeBERTa-v3-small | ~44M | 82.3%* | 75.8%* | ~500 p/s | O(nΒ²) attention |
| RetNet | 45M | 74.4% | 63.9% | 1,574 p/s | O(n) linear |
*Results on different data splits. RetNet offers 3x speed advantage with competitive performance.
The model classifies text into 7 categories of explicitness:
# Install dependencies
pip install torch transformers safetensors
from test_model import RetNetExplicitnessClassifier
# Initialize classifier
classifier = RetNetExplicitnessClassifier()
# Classify single text
result = classifier.classify("Your text here...")
print(f"Category: {result['predicted_class']}")
print(f"Confidence: {result['confidence']:.3f}")
# Batch classification for better performance
texts = ["Text 1", "Text 2", "Text 3"]
results = classifier.classify_batch(texts)
python test_model.py
retnet-explicitness-classifier/
βββ README.md # This file
βββ config.json # Model configuration
βββ model.py # RetNet architecture code
βββ model.safetensors # Trained model weights (SafeTensors format)
βββ model_metadata.json # Model metadata
βββ retnet_training_results.json # Training metrics
βββ test_model.py # Test script and API
{
"model_dim": 512,
"num_layers": 6,
"num_heads": 8,
"max_length": 512,
"vocab_size": 50257
}
| Class | Precision | Recall | F1-Score | Support |
|---|---|---|---|---|
| EXPLICIT-DISCLAIMER | 1.00 | 0.93 | 0.96 | 57 |
| EXPLICIT-OFFENSIVE | 0.70 | 0.76 | 0.73 | 1,208 |
| EXPLICIT-SEXUAL | 0.85 | 0.91 | 0.88 | 1,540 |
| EXPLICIT-VIOLENT | 0.58 | 0.25 | 0.35 | 73 |
| NON-EXPLICIT | 0.75 | 0.83 | 0.79 | 2,074 |
| SEXUAL-REFERENCE | 0.61 | 0.37 | 0.46 | 598 |
| SUGGESTIVE | 0.38 | 0.26 | 0.30 | 398 |
| Macro Average | 0.70 | 0.61 | 0.64 | 5,948 |
β Ideal for:
β οΈ Consider alternatives for:
class ProductionRetNet(nn.Module):
def __init__(self, vocab_size=50257, dim=512, num_layers=6,
num_heads=8, num_classes=7, max_length=512):
# FastRetentionMechanism with linear attention
# Rotary positional encoding
# Pre-layer normalization
# Classification head with dropout
FROM python:3.9-slim
COPY retnet-explicitness-classifier/ /app/
WORKDIR /app
RUN pip install torch transformers
EXPOSE 8000
CMD ["python", "-m", "uvicorn", "api:app", "--host", "0.0.0.0"]
from fastapi import FastAPI
from test_model import RetNetExplicitnessClassifier
app = FastAPI()
classifier = RetNetExplicitnessClassifier()
@app.post("/classify")
async def classify_text(text: str):
return classifier.classify(text)
If you use this model in your research, please cite:
@misc{retnet_explicitness_2024,
title={RetNet for Explicitness Classification: Linear Attention for High-Throughput Content Moderation},
author={Claude Code Assistant},
year={2024},
note={Production-scale RetNet implementation for 7-class explicitness classification}
}
This model is released for research and educational purposes. Please ensure compliance with content moderation guidelines and applicable laws when using for production applications.
Model Version: 1.0
Last Updated: August 2024
Framework: PyTorch 2.0+
Minimum Python: 3.8+