Downloads · 30 days
28
3% of all-time downloads
Ibracadabra13/arabic-bert-hate-speech-detection
arabic-bert-hate-speech-detection is a text classification model from Ibracadabra13. Use it when you need a label for a piece of text. The card lists the license as mit.
This model is a fine-tuned version of aubmindlab/bert-base-arabertv2 for Arabic hate speech detection.
Downloads · 30 days
28
3% of all-time downloads
All-time downloads
1.1K
Public
Parameters
135M
541 MB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors541 MB · 100%
From the Hugging Face model README
This model is a fine-tuned version of aubmindlab/bert-base-arabertv2 for Arabic hate speech detection.
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
# Load model and tokenizer
model_name = "Ibracadabra13/arabic-bert-hate-speech-detection"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
# Function to predict hate speech
def predict_hate_speech(text):
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=128)
with torch.no_grad():
outputs = model(**inputs)
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
predicted_class = torch.argmax(predictions, dim=-1).item()
confidence = predictions[0][predicted_class].item()
label_map = {0: 'Normal', 1: 'Hate Speech'}
return {
'prediction': label_map[predicted_class],
'confidence': confidence,
'is_hate_speech': predicted_class == 1
}
# Example usage
result = predict_hate_speech("أنت حيوان حقير")
print(result) # {'prediction': 'Hate Speech', 'confidence': 0.97, 'is_hate_speech': True}
This model is trained on a specific dataset and may not generalize well to all Arabic dialects or contexts. Use with caution in production environments.