/ Модель

Характеристики

Контекст
512 токенов
Лицензия
Apache 2.0
Архитектура
distilbert · dense
Базовая модель
distilbert-base-uncased
Опубликована
7 апр 2024

distilbert-nsfw-text-classifier

Классификация текстаТекст → label4 профессии

Англоязычный классификатор на базе DistilBERT для фильтрации текста по категориям safe и nsfw.

5 543скачиваний за 30 дней24лайкавеса обновлены16 мая 2025

Бенчмарки

Как модель справилась с задачами пользователей ailist и что о ней публикуют открытые лидерборды

Публичные оценки

Из открытых лидербордов. Сравнивайте результаты одного теста при одинаковых условиях — отсутствие оценки не значит, что модель хуже.

В подключённых источниках результатов для этой модели пока нет.

Что умеет модель

Описание составлено по карточке модели и метаданным Hugging Face

Классификатор текста Elias Al Bouzidi, Massine El Khader, Abdellah Oumida, Mohammed Sbaihi и Eliott Binard для отнесения текста к одной из двух категорий: safe или nsfw. Модель основана на DistilBERT и дообучена для задач модерации и фильтрации контента; она принимает строку текста и выдаёт вероятности классов. В карточке указано 60 млн параметров, английский язык и контекст до 512 токенов.

Модель обучена на 190 тысячах размеченных примеров, включая описания изображений и сцен; авторы сообщают F1 0,974 на выборке из 40 тысяч примеров. Лицензия — Apache-2.0. Для повышения качества требуется предварительная обработка текста, а результат следует проверять с учётом возможных ошибок классификации.

Сценарии применения

  • модерация пользовательских сообщений по признаку NSFW
  • фильтрация текстовых описаний для генерации изображений
  • проверка текстового контента перед публикацией
  • автоматическая разметка текста как безопасного или нежелательного

Ограничения

Модель может хуже работать не на английском языке, а также испытывать трудности с сарказмом и переносным смыслом. Возможны ложноположительные и ложноотрицательные классификации; для качества важна предварительная обработка текста.

Для каких профессий подходит4

Разделы каталога профессий, в задачах которых используется эта модель

Все профессии

Карточка модели

README от автора на Hugging Face, как он его опубликовал

Открыть на Hugging Face

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 Distilbert-base model.

In terms of performance, the model has achieved a score of 0.974 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: Elias Al Bouzidi, Massine El Khader, Abdellah Oumida, Mohammed Sbaihi, Eliott Binard
  • Model type: 60M
  • Language (NLP): English
  • License: apache-2.0

Technical Paper:

A more detailed technical overview of the model and the dataset can be found here.

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: 3
  • mixed_precision_training: Native AMP

Training results

Training LossEpochStepValidation LossAccuracyF1Fbeta 1.6False positive rateFalse negative ratePrecisionRecall
0.33670.09985860.12270.95860.94480.94470.03310.05540.94500.9446
0.09980.199711720.09190.97050.96060.95950.02210.04190.96310.9581
0.08960.299517580.09000.97300.96380.96000.01630.04480.97240.9552
0.0870.399423440.08200.97430.96570.96460.01910.03670.96810.9633
0.08060.499229300.07170.97520.96720.97130.02560.02350.95820.9765
0.07410.599135160.07410.97530.96740.97120.02510.02400.95890.9760
0.07470.698941020.06890.97730.96970.96960.01810.03050.96990.9695
0.07070.798846880.07380.97810.97060.96780.01370.03560.97690.9644
0.06440.898652740.06820.97960.97280.97080.01350.03170.97730.9683
0.06880.998558600.06580.97980.97300.97180.01440.02980.97580.9702
0.04621.098364460.06820.98000.97330.97230.01460.02900.97560.9710
0.04981.198270320.07060.98000.97330.97170.01380.03030.97680.9697
0.04841.298076180.07730.97970.97280.96960.01170.03450.98020.9655
0.04831.397982040.06760.98000.97340.97420.01720.02480.97150.9752
0.04811.497787900.06780.97980.97310.97370.01700.02550.97170.9745
0.04741.597593760.06650.97820.97130.97550.02340.01910.96180.9809
0.04321.697499620.06910.97870.97180.97480.02130.02130.96510.9787
0.04391.7972105480.06830.98110.97480.97470.01500.02540.97500.9746
0.04421.8971111340.07100.98090.97440.97190.01180.03130.98020.9687
0.04251.9969117200.06710.98100.97470.97560.01650.02320.97260.9768
0.02992.0968123060.07230.98020.97380.97580.01870.02170.96920.9783
0.03122.1966128920.07900.98040.97380.97310.01460.02790.97550.9721
0.02662.2965134780.08400.98150.97520.97280.01150.03020.98060.9698
0.02772.3963140640.07420.98080.97460.97700.01880.01990.96900.9801
0.02942.4962146500.07640.98090.97470.97650.01790.02110.97050.9789
0.03042.5960152360.07950.98110.97480.97420.01420.02660.97630.9734
0.02872.6959158220.07830.98140.97510.97410.01340.02720.97750.9728
0.02672.7957164080.08050.98140.97510.97400.01330.02740.97770.9726
0.03182.8956169940.07670.98140.97520.97560.01540.02400.97440.9760
0.03052.9954175800.07790.98150.97530.97510.01460.02510.97570.9749

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

from transformers import AutoTokenizer, AutoModelForSequenceClassification

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

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

Use a pipeline

from transformers import pipeline

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

Citation

If you find our work useful, please consider citing us!

@misc{khader2025diffguardtextbasedsafetychecker,
      title={DiffGuard: Text-Based Safety Checker for Diffusion Models}, 
      author={Massine El Khader and Elias Al Bouzidi and Abdellah Oumida and Mohammed Sbaihi and Eliott Binard and Jean-Philippe Poli and Wassila Ouerdane and Boussad Addad and Katarzyna Kapusta},
      year={2025},
      eprint={2412.00064},
      archivePrefix={arXiv},
      primaryClass={cs.CV},
      url={https://arxiv.org/abs/2412.00064}, 
}

Contact

Please reach out to eliasalbouzidi@gmail.com if you have any questions or feedback.

Как запустить

На своей GPU в ailist. Цена — по текущим предложениям провайдеров

GPU в ailist

Универсальный рантайм · text-classification

Можно запустить

Подбираем GPU…

Класс архитектуры
DistilBertForSequenceClassification
Ревизия весов
c0abb7a

0 моделей