File size: 6,750 Bytes
aa322d2
d10f014
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aa322d2
 
d10f014
aa322d2
d10f014
 
 
 
 
 
 
 
 
 
aa322d2
d10f014
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aa322d2
d10f014
 
 
aa322d2
d10f014
aa322d2
d10f014
aa322d2
d10f014
aa322d2
d10f014
 
 
aa322d2
d10f014
 
 
 
aa322d2
 
 
 
d10f014
 
 
 
 
 
 
 
 
 
 
 
 
 
aa322d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d10f014
aa322d2
 
 
 
 
 
 
d10f014
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
widget:
- text: A family hiking in the mountains
  example_title: Safe
- text: A child playing with a puppy
  example_title: Safe
- text: A couple kissing passionately in bed
  example_title: Nsfw
- text: A woman naked
  example_title: Nsfw
- text: A man killing people
  example_title: Nsfw
- text: A mass shooting
  example_title: Nsfw
license: apache-2.0

language:
- en
metrics:
- f1
- accuracy
- precision
- recall
pipeline_tag: text-classification
tags:
- Transformers
- ' PyTorch'
- safety
- innapropriate
- roberta
datasets:
- eliasalbouzidi/NSFW-Safe-Dataset
model-index:
- name: NSFW-Safe-Dataset
  results:
  - task:
      name: Text Classification
      type: text-classification
    dataset:
      name: NSFW-Safe-Dataset
      type: .
    metrics:
    - name: F1
      type: f1
      value: 0.977
    - name: Accuracy
      type: accuracy
      value: 0.982
---
# Model Card

This model is designed to categorize text into two classes: "safe", or "nsfw" (not safe for work), which makes it suitable for content moderation and filtering applications.

The model was trained using a dataset containing 190,000 labeled text samples, distributed among the two classes of "safe" and "nsfw".

The model is based on the roberta-base model. 

In terms of performance, the model has achieved a score of 0.975 for F1 (40K exemples).

To improve the performance of the model, it is necessary to preprocess the input text. You can refer to the preprocess function in the app.py file in the following space: <https://huggingface.co/spaces/eliasalbouzidi/distilbert-nsfw-text-classifier>.
### Model Description
The model can be used directly to classify text into one of the two classes. It takes in a string of text as input and outputs a probability distribution over the two classes. The class with the highest probability is selected as the predicted class.

- **Developed by:** Centrale Supélec Students
- **Model type:** 125M
- **Language(s) (NLP):** English
- **License:** apache-2.0




### Uses

The model can be integrated into larger systems for content moderation or filtering.
### Training Data
The training data for finetuning the text classification model consists of a large corpus of text labeled with one of the two classes: "safe" and "nsfw". The dataset contains a total of 190,000 examples, which are distributed as follows:

117,000 examples labeled as "safe"

63,000 examples labeled as "nsfw"

It was assembled by scraping data from the web and utilizing existing open-source datasets. A significant portion of the dataset consists of descriptions for images and scenes. The primary objective was to prevent diffusers from generating NSFW content but it can be used for other moderation purposes.

You can access the dataset : https://huggingface.co/datasets/eliasalbouzidi/NSFW-Safe-Dataset



### Training hyperparameters

The following hyperparameters were used during training:
- learning_rate: 1e-05
- train_batch_size: 32
- eval_batch_size: 32
- seed: 42
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
- lr_scheduler_type: linear
- lr_scheduler_warmup_steps: 600
- num_epochs: 5
- mixed_precision_training: Native AMP

### Training results

| Training Loss | Epoch  | Step  | Validation Loss | Accuracy | F1     | Recall | Precision | False positive rate | False negative rate | Fbeta 0.5 | Fbeta 1.6 | Fbeta 5 |
|:-------------:|:------:|:-----:|:---------------:|:--------:|:------:|:------:|:---------:|:-------------------:|:-------------------:|:---------:|:---------:|:-------:|
| 0.1369        | 0.4999 | 2934  | 0.0811          | 0.9764   | 0.9690 | 0.9823 | 0.9561    | 0.0271              | 0.0177              | 0.9612    | 0.9748    | 0.9812  |
| 0.077         | 0.9998 | 5868  | 0.0791          | 0.9802   | 0.9734 | 0.9659 | 0.9811    | 0.0112              | 0.0341              | 0.9780    | 0.9701    | 0.9665  |
| 0.0556        | 1.4997 | 8802  | 0.0690          | 0.9809   | 0.9745 | 0.9732 | 0.9758    | 0.0145              | 0.0268              | 0.9753    | 0.9740    | 0.9733  |
| 0.0531        | 1.9997 | 11736 | 0.0871          | 0.9801   | 0.9736 | 0.9793 | 0.9680    | 0.0195              | 0.0207              | 0.9702    | 0.9761    | 0.9788  |
| 0.0373        | 2.4996 | 14670 | 0.0777          | 0.9822   | 0.9763 | 0.9797 | 0.9730    | 0.0163              | 0.0203              | 0.9744    | 0.9778    | 0.9794  |
| 0.0383        | 2.9995 | 17604 | 0.0723          | 0.9825   | 0.9768 | 0.9828 | 0.9708    | 0.0177              | 0.0172              | 0.9732    | 0.9794    | 0.9824  |
| 0.0243        | 3.4994 | 20538 | 0.0969          | 0.9825   | 0.9768 | 0.9810 | 0.9726    | 0.0166              | 0.0190              | 0.9742    | 0.9786    | 0.9807  |
| 0.0251        | 3.9993 | 23472 | 0.0917          | 0.9834   | 0.9780 | 0.9805 | 0.9754    | 0.0148              | 0.0195              | 0.9764    | 0.9791    | 0.9803  |
| 0.0171        | 4.4992 | 26406 | 0.0975          | 0.9832   | 0.9777 | 0.9806 | 0.9748    | 0.0152              | 0.0194              | 0.9759    | 0.9790    | 0.9804  |
| 0.0161        | 4.9991 | 29340 | 0.1046          | 0.9835   | 0.9781 | 0.9790 | 0.9772    | 0.0137              | 0.0210              | 0.9776    | 0.9785    | 0.9789  |

We selected the checkpoint with the highest F-beta1.6 score.

### Framework versions

- Transformers 4.40.1
- Pytorch 2.3.0+cu121
- Datasets 2.19.0
- Tokenizers 0.19.1

### Out-of-Scope Use

It should not be used for any illegal activities.

## Bias, Risks, and Limitations

The model may exhibit biases based on the training data used. It may not perform well on text that is written in languages other than English. It may also struggle with sarcasm, irony, or other forms of figurative language. The model may produce false positives or false negatives, which could lead to incorrect categorization of text.

### Recommendations


Users should be aware of the limitations and biases of the model and use it accordingly. They should also be prepared to handle false positives and false negatives. It is recommended to fine-tune the model for specific downstream tasks and to evaluate its performance on relevant datasets.


### Load model directly
```python
from transformers import AutoTokenizer, AutoModelForSequenceClassification

tokenizer = AutoTokenizer.from_pretrained("eliasalbouzidi/roberta-nsfw-text-classifier")

model = AutoModelForSequenceClassification.from_pretrained("eliasalbouzidi/roberta-nsfw-text-classifier")

```
### Use a pipeline 
```python
from transformers import pipeline

pipe = pipeline("text-classification", model="eliasalbouzidi/roberta-nsfw-text-classifier")
```


## Contact
Please reach out to [email protected] if you have any questions or feedback.