Upload folder using huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SpanCNN Model for Toxic Text Classification
|
| 2 |
+
|
| 3 |
+
## Overview
|
| 4 |
+
|
| 5 |
+
The SpanCNN model is designed for toxic text classification, distinguishing between safe and toxic content. This model is part of the research presented in the paper titled [CMD: A Framework for Context-aware Model Self-Detoxification](https://arxiv.org/abs/2308.08295).
|
| 6 |
+
|
| 7 |
+
## Model Details
|
| 8 |
+
|
| 9 |
+
- **Input**: Text data
|
| 10 |
+
- **Output**: Integer
|
| 11 |
+
- `0` represents **safe** content
|
| 12 |
+
- `1` represents **toxic** content
|
| 13 |
+
|
| 14 |
+
## Usage
|
| 15 |
+
|
| 16 |
+
To use the SpanCNN model for toxic text classification, follow the example below:
|
| 17 |
+
|
| 18 |
+
```python
|
| 19 |
+
from transformers import pipeline
|
| 20 |
+
|
| 21 |
+
# Load the SpanCNN model
|
| 22 |
+
classifier = pipeline("spancnn-classification", model="ZetangForward/SpanCNN", trust_remote_code=True)
|
| 23 |
+
|
| 24 |
+
# Example 1: Safe text
|
| 25 |
+
pos_text = "You look good today~!"
|
| 26 |
+
result = classifier(pos_text)
|
| 27 |
+
print(result) # Output: 0 (safe)
|
| 28 |
+
|
| 29 |
+
# Example 2: Toxic text
|
| 30 |
+
neg_text = "You're too stupid, you're just like a fool"
|
| 31 |
+
result = classifier(neg_text)
|
| 32 |
+
print(result) # Output: 1 (toxic)
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
## Citation
|
| 36 |
+
|
| 37 |
+
If you find this model useful, please consider citing the original paper:
|
| 38 |
+
|
| 39 |
+
```bibtex
|
| 40 |
+
@article{tang2023detoxify,
|
| 41 |
+
title={Detoxify language model step-by-step},
|
| 42 |
+
author={Tang, Zecheng and Zhou, Keyan and Wang, Pinzheng and Ding, Yuyang and Li, Juntao and others},
|
| 43 |
+
journal={arXiv preprint arXiv:2308.08295},
|
| 44 |
+
year={2023}
|
| 45 |
+
}
|
| 46 |
+
```
|
| 47 |
+
|
| 48 |
+
## Disclaimer
|
| 49 |
+
|
| 50 |
+
While the SpanCNN model is effective in detecting toxic segments within text, we strongly recommend that users carefully review the results and exercise caution when applying this method in real-world scenarios. The model is not infallible, and its outputs should be validated in context-sensitive applications.
|