This project implements a machine learning model to classify text as hate speech or non-hate speech specifically in the Tunisian dialect. The model is built using the Naive Bayes algorithm and utilizes the Count Vectorizer for text feature extraction. The API is built with Flask and provides endpoints for making predictions.
# Hate Speech Detection API
## Overview
This project implements a machine learning model to classify text as hate speech or non-hate speech specifically in the Tunisian dialect. The model is built using the Naive Bayes algorithm and utilizes the Count Vectorizer for text feature extraction. The API is built with Flask and provides endpoints for making predictions.
## Table of Contents
- Installation
- Usage
- API Endpoints
- Example Usage
- Visualizations
- Performance Metrics
- Data
- Contributing
- License
## Installation
To run this project, ensure you have Python 3.x installed. Follow these steps to set up the environment:
1. Clone the repository:
```bash
git clone
github.com
cd hate-speech-detection-api
```
2. Create a virtual environment (optional but recommended):
```bash
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
```
3. Install the required packages:
```bash
pip install -r requirements.txt
```
## Usage
1. **Train the Model**:
Run the following command to train the model and save it:
```bash
python src/enhanced_model.py
```
2. **Adjust the Classification Threshold**:
Run the following command to optimize the classification threshold:
```bash
python src/threshold_adjustment.py
```
3. **Start the Flask API**:
Run the following command to start the API:
```bash
python src/app.py
```
4. **Test the API**:
You can test the API using `curl` or any API testing tool (like Postman). Here’s an example `curl` command:
```bash
curl -X POST
127.0.0.1 -H "Content-Type: application/json" -d "{\"message\": \"أنت كذاب\"}"
```
## API Endpoints
- **POST /predict**: Predicts whether the input text is hate speech or not.
- **Request Body**:
```json
{
"message": "Your text here"
}
```
- **Response**:
```json
{
"is_hate_speech": true/false
}
```
## Example Usage
### Using React.js
You can also create a simple React component to interact with the API. Below is …