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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
datasets:
|
| 4 |
+
- Overfit-GM/turkish-toxic-language
|
| 5 |
+
language:
|
| 6 |
+
- tr
|
| 7 |
+
base_model:
|
| 8 |
+
- dbmdz/bert-base-turkish-cased
|
| 9 |
+
pipeline_tag: text-classification
|
| 10 |
+
library_name: transformers
|
| 11 |
+
tags:
|
| 12 |
+
- text-classification
|
| 13 |
+
- toxicity-detection
|
| 14 |
+
- turkish
|
| 15 |
+
- bert
|
| 16 |
+
- nlp
|
| 17 |
+
- content-moderation
|
| 18 |
+
---
|
| 19 |
+
|
| 20 |
+
# MeowML/ToxicBERT - Turkish Toxic Language Detection
|
| 21 |
+
|
| 22 |
+
## Model Description
|
| 23 |
+
|
| 24 |
+
ToxicBERT is a fine-tuned BERT model specifically designed for detecting toxic language in Turkish text. Built upon the `dbmdz/bert-base-turkish-cased` foundation model, this classifier can identify potentially harmful, offensive, or toxic content in Turkish social media posts, comments, and general text.
|
| 25 |
+
|
| 26 |
+
## Model Details
|
| 27 |
+
|
| 28 |
+
- **Model Type**: Text Classification (Binary)
|
| 29 |
+
- **Language**: Turkish (tr)
|
| 30 |
+
- **Base Model**: `dbmdz/bert-base-turkish-cased`
|
| 31 |
+
- **License**: MIT
|
| 32 |
+
- **Library**: Transformers
|
| 33 |
+
- **Task**: Toxicity Detection
|
| 34 |
+
|
| 35 |
+
## Intended Use
|
| 36 |
+
|
| 37 |
+
### Primary Use Cases
|
| 38 |
+
- Content moderation for Turkish social media platforms
|
| 39 |
+
- Automated filtering of user-generated content
|
| 40 |
+
- Research in Turkish NLP and toxicity detection
|
| 41 |
+
- Educational purposes for understanding toxic language patterns
|
| 42 |
+
|
| 43 |
+
### Out-of-Scope Use
|
| 44 |
+
- This model should not be used as the sole decision-maker for content moderation without human oversight
|
| 45 |
+
- Not suitable for languages other than Turkish
|
| 46 |
+
- Should not be used for sensitive applications without proper validation and testing
|
| 47 |
+
|
| 48 |
+
## Training Data
|
| 49 |
+
|
| 50 |
+
The model was trained on the `Overfit-GM/turkish-toxic-language` dataset, which contains Turkish text samples labeled for toxicity. The dataset includes various forms of toxic content commonly found in online Turkish communications.
|
| 51 |
+
|
| 52 |
+
## Model Performance
|
| 53 |
+
|
| 54 |
+
The model outputs:
|
| 55 |
+
- **Binary Classification**: 0 (Non-toxic) or 1 (Toxic)
|
| 56 |
+
- **Confidence Score**: Probability score indicating model confidence
|
| 57 |
+
- **Toxic Probability**: Specific probability of the text being toxic
|
| 58 |
+
|
| 59 |
+
## Usage
|
| 60 |
+
|
| 61 |
+
### Quick Start
|
| 62 |
+
|
| 63 |
+
```python
|
| 64 |
+
import torch
|
| 65 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 66 |
+
|
| 67 |
+
# Load model and tokenizer
|
| 68 |
+
tokenizer = AutoTokenizer.from_pretrained("dbmdz/bert-base-turkish-cased")
|
| 69 |
+
model = AutoModelForSequenceClassification.from_pretrained("MeowML/ToxicBERT")
|
| 70 |
+
|
| 71 |
+
# Prepare text
|
| 72 |
+
text = "Merhaba, nasılsın?"
|
| 73 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=256)
|
| 74 |
+
|
| 75 |
+
# Get prediction
|
| 76 |
+
with torch.no_grad():
|
| 77 |
+
outputs = model(**inputs)
|
| 78 |
+
probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
| 79 |
+
prediction = torch.argmax(probabilities, dim=-1)
|
| 80 |
+
|
| 81 |
+
toxic_probability = probabilities[0][1].item()
|
| 82 |
+
is_toxic = bool(prediction.item())
|
| 83 |
+
|
| 84 |
+
print(f"Is toxic: {is_toxic}")
|
| 85 |
+
print(f"Toxic probability: {toxic_probability:.4f}")
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
### Advanced Usage with Custom Class
|
| 89 |
+
|
| 90 |
+
```python
|
| 91 |
+
import torch
|
| 92 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 93 |
+
|
| 94 |
+
class ToxicLanguageDetector:
|
| 95 |
+
def __init__(self, model_name="MeowML/ToxicBERT"):
|
| 96 |
+
self.tokenizer = AutoTokenizer.from_pretrained("dbmdz/bert-base-turkish-cased")
|
| 97 |
+
self.model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 98 |
+
self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 99 |
+
self.model.to(self.device)
|
| 100 |
+
self.model.eval()
|
| 101 |
+
|
| 102 |
+
def predict(self, text):
|
| 103 |
+
inputs = self.tokenizer(
|
| 104 |
+
text,
|
| 105 |
+
truncation=True,
|
| 106 |
+
padding='max_length',
|
| 107 |
+
max_length=256,
|
| 108 |
+
return_tensors='pt'
|
| 109 |
+
).to(self.device)
|
| 110 |
+
|
| 111 |
+
with torch.no_grad():
|
| 112 |
+
outputs = self.model(**inputs)
|
| 113 |
+
probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
| 114 |
+
prediction = torch.argmax(probabilities, dim=-1)
|
| 115 |
+
|
| 116 |
+
return {
|
| 117 |
+
'text': text,
|
| 118 |
+
'is_toxic': bool(prediction.item()),
|
| 119 |
+
'toxic_probability': probabilities[0][1].item(),
|
| 120 |
+
'confidence': max(probabilities[0]).item()
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
# Usage
|
| 124 |
+
detector = ToxicLanguageDetector()
|
| 125 |
+
result = detector.predict("Merhaba, nasılsın?")
|
| 126 |
+
print(result)
|
| 127 |
+
```
|
| 128 |
+
|
| 129 |
+
## Limitations and Biases
|
| 130 |
+
|
| 131 |
+
### Limitations
|
| 132 |
+
- The model's performance depends heavily on the training data quality and coverage
|
| 133 |
+
- May have difficulty with context-dependent toxicity (sarcasm, irony)
|
| 134 |
+
- Performance may vary across different Turkish dialects or informal language
|
| 135 |
+
- Shorter texts might be more challenging to classify accurately
|
| 136 |
+
|
| 137 |
+
### Potential Biases
|
| 138 |
+
- The model may reflect biases present in the training dataset
|
| 139 |
+
- Certain topics, demographics, or linguistic patterns might be over- or under-represented
|
| 140 |
+
- Regular evaluation and bias testing are recommended for production use
|
| 141 |
+
|
| 142 |
+
## Ethical Considerations
|
| 143 |
+
|
| 144 |
+
- This model should be used responsibly with human oversight
|
| 145 |
+
- False positives and negatives are expected and should be accounted for
|
| 146 |
+
- Consider the impact on freedom of expression when implementing automated moderation
|
| 147 |
+
- Regular auditing and updating are recommended to maintain fairness
|
| 148 |
+
|
| 149 |
+
## Technical Specifications
|
| 150 |
+
|
| 151 |
+
- **Input**: Text strings (max 256 tokens)
|
| 152 |
+
- **Output**: Binary classification with probability scores
|
| 153 |
+
- **Model Size**: Based on BERT-base architecture
|
| 154 |
+
- **Inference Speed**: Optimized for both CPU and GPU inference
|
| 155 |
+
- **Memory Requirements**: Suitable for standard hardware configurations
|
| 156 |
+
|
| 157 |
+
## Citation
|
| 158 |
+
|
| 159 |
+
If you use this model in your research or applications, please cite:
|
| 160 |
+
|
| 161 |
+
```bibtex
|
| 162 |
+
@misc{meowml_toxicbert_2024,
|
| 163 |
+
title={ToxicBERT: Turkish Toxic Language Detection},
|
| 164 |
+
author={MeowML},
|
| 165 |
+
year={2024},
|
| 166 |
+
publisher={Hugging Face},
|
| 167 |
+
url={https://huggingface.co/MeowML/ToxicBERT}
|
| 168 |
+
}
|
| 169 |
+
```
|
| 170 |
+
|
| 171 |
+
## Acknowledgments
|
| 172 |
+
|
| 173 |
+
- Base model: `dbmdz/bert-base-turkish-cased`
|
| 174 |
+
- Training dataset: `Overfit-GM/turkish-toxic-language`
|
| 175 |
+
- Built with Hugging Face Transformers library
|
| 176 |
+
|
| 177 |
+
## Contact
|
| 178 |
+
|
| 179 |
+
For questions, issues, or suggestions, please open an issue in the model repository or contact the MeowML team.
|
| 180 |
+
|
| 181 |
+
---
|
| 182 |
+
|
| 183 |
+
**Disclaimer**: This model is provided for research and educational purposes. Users are responsible for ensuring appropriate and ethical use in their applications.
|