CoolFace
Modelpublic

NightPrince/Toxic_Classification

sourceHugging Facemitupdated 1y agoView on Hugging Face
0likes21downloads
README.md155 linesDownload Raw Back to root
1 2---3language: en4tags:5- toxic-content6- text-classification7- keras8- tensorflow9- deep-learning10- safety11- multiclass12license: mit13datasets:14- custom15metrics:16- accuracy17- f118pipeline_tag: text-classification19model-index:20- name: Toxic_Classification21  results: []22---23 24 25# Toxic-Predict26 27Toxic-Predict is a machine learning project developed as part of the Cellula Internship, focused on safe and responsible multi-modal toxic content moderation. It classifies text queries and image descriptions into nine toxicity categories such as "Safe", "Violent Crimes", "Non-Violent Crimes", "Unsafe", and others. The project leverages deep learning (Keras/TensorFlow), NLP preprocessing, and benchmarking with modern transformer models to build and evaluate a robust multi-class toxic content classifier.28 29---30 31## ๐Ÿšฉ Project Context32 33This project is part of the **Cellula Internship** proposal:  34**"Safe and Responsible Multi-Modal Toxic Content Moderation"**  35The goal is to build a dual-stage moderation pipeline for both text and images, combining hard guardrails (Llama Guard) and soft classification (DistilBERT/Deep Learning) for nuanced, policy-compliant moderation.36 37---38 39 40## Features41 42- Dual-stage moderation: hard filter (Llama Guard) + soft classifier (DistilBERT/CNN/LSTM)43- Data cleaning, preprocessing, and label encoding44- Tokenization and sequence padding for text data45- Deep learning and transformer-based models for multi-class toxicity classification46- Evaluation metrics: classification report and confusion matrix47- Jupyter notebooks for data exploration and model development48- Streamlit web app for demo and deployment49 50---51 52---53 54## Usage55 56- **Preprocessing and Tokenization:**  57  See `notebooks/Preprocessing.ipynb` and `notebooks/tokenization.ipynb` for step-by-step data cleaning, splitting, and tokenization.58- **Model Training:**  59  Model architecture and training code are in `models/model.py`.60- **Inference:**  61  Load the trained model (`models/toxic_classifier.h5` or `.keras`) and tokenizer (`data/tokenizer.pkl`) to predict toxicity categories for new samples.62 63---64 65## Data66 67- CSV files with columns: `query`, `image descriptions`, `Toxic Category`, and `Toxic Category Encoded`.68- Data splits: `train.csv`, `eval.csv`, `test.csv`, and `cleaned.csv` for processed data.69- 9 categories: Safe, Violent Crimes, Elections, Sex-Related Crimes, Unsafe, Non-Violent Crimes, Child Sexual Exploitation, Unknown S-Type, Suicide & Self-Harm.70 71---72 73## Model74 75- Deep learning model built with Keras (TensorFlow backend).76- Multi-class classification with label encoding for toxicity categories.77- Benchmarking with PEFT-LoRA DistilBERT and baseline CNN/LSTM.78 79---80 81## Evaluation82 83- Classification report and confusion matrix are generated for model evaluation.84- See the evaluation steps in `notebooks/Preprocessing.ipynb`.85 86---87 88language: en89 90## ๐Ÿค— Hugging Face Inference91 92This model is available on the Hugging Face Hub: [NightPrince/Toxic_Classification](https://huggingface.co/NightPrince/Toxic_Classification)93 94### Inference API Usage95 96You can use the Hugging Face Inference API or widget with two fields:97 98- `text`: The main query or post text99- `image_desc`: The image description (if any)100 101**Example (Python):**102 103```python104from huggingface_hub import InferenceClient105client = InferenceClient("NightPrince/Toxic_Classification")106result = client.text_classification({107    "text": "This is a dangerous post",108    "image_desc": "Knife shown in the image"109})110print(result)  # {'label': 'toxic', 'score': 0.98}111```112 113### Custom Pipeline Details114 115- The model uses a custom `pipeline.py` for multi-input inference.116- The output is a dictionary with the predicted `label` (class name) and `score` (confidence).117- Class names are mapped using `label_map.json`.118 119**Files in the repo:**120- `pipeline.py` (custom inference logic)121- `tokenizer.json` (Keras tokenizer)122- `label_map.json` (class code to name mapping)123- TensorFlow SavedModel files (`saved_model.pb`, `variables/`)124 125**Requirements:**126```127tensorflow128keras129numpy130```131 132---133 134---135 136## ๐Ÿ“š Resources137 138- [Cellula Internship Project Proposal](#)  139- [BLIP: Bootstrapped Language-Image Pre-training](https://github.com/salesforce/BLIP)140- [Llama Guard](https://llama.meta.com/llama-guard/)141- [DistilBERT](https://huggingface.co/distilbert-base-uncased)142- [Streamlit](https://streamlit.io/)143 144---145 146## License147 148MIT License149 150---151 152**Author:** Yahya Muhammad Alnwsany  153**Contact:** yahyaalnwsany39@gmail.com  154**Portfolio:** https://nightprincey.github.io/Portfolio/155