Downloads · 30 days
10
6% of all-time downloads
KevynKrancenblum/hebrew-offensive-detection
hebrew-offensive-detection is a text classification model from KevynKrancenblum. Use it when you need a label for a piece of text. It is set up for peft. The card lists the license as mit.
This model is a fine-tuned version of dicta-il/dictalm2.0-instruct specialized for detecting offensive language in Hebrew text while providing explainable rationales in Hebrew.
Downloads · 30 days
10
6% of all-time downloads
All-time downloads
154
Public
Repo size
2.7 GB
Likes
1
Public
Click a slice to open those files.
.safetensors5.4 GB · 100%
From the Hugging Face model README
This model is a fine-tuned version of dicta-il/dictalm2.0-instruct specialized for detecting offensive language in Hebrew text while providing explainable rationales in Hebrew.
Model Repository: KevynKrancenblum/hebrew-offensive-detection
This model performs binary classification of Hebrew text to determine if it contains offensive language, with the unique capability of explaining its reasoning in Hebrew. It addresses critical challenges in Hebrew NLP:
| Dataset | Accuracy | Precision | Recall | F1-Score |
|---|---|---|---|---|
| OlaH-5000 (test) | 0.85 | 0.85 | 0.85 | 0.85 |
| HeDetox (cross-domain) | 0.91 | 0.92 | 0.91 | 0.91 |
Comparison with baselines:
pip install transformers torch peft bitsandbytes accelerate
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
# Load model and tokenizer
model_name = "KevynKrancenblum/hebrew-offensive-detection"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
load_in_4bit=True, # Use 4-bit quantization for efficiency
device_map="auto"
)
# Prepare system prompt in Hebrew
SYSTEM_PROMPT = """אתה מומחה לזיהוי תוכן פוגעני בעברית. נתח את הטקסט הבא והסבר את הנימוק שלך.
בהתבסס על הנימוק, תן תווית: 1 לפוגעני או 0 ללא פוגעני."""
# Classification function
def classify_hebrew_text(text: str) -> dict:
prompt = f"{SYSTEM_PROMPT}\n\nטקסט: \"{text}\""
messages = [{"role": "user", "content": prompt}]
input_text = tokenizer.apply_chat_template(messages, tokenize=False)
inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=256,
temperature=0.2,
do_sample=True,
pad_token_id=tokenizer.eos_token_id
)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
# Parse response
lines = response.split('\n')
label = None
reason = None
for line in lines:
if 'תווית:' in line or 'label:' in line.lower():
# Extract label (0 or 1)
if '1' in line and 'פוגעני' in line:
label = 1
elif '0' in line:
label = 0
elif len(line.strip()) > 10 and label is None:
# Rationale is typically the longer text after label
reason = line.strip()
return {
"label": label, # 1 = offensive, 0 = non-offensive
"reason": reason, # Hebrew explanation
"full_response": response
}
# Example usage
text = "יא מטומטם, לך תמות"
result = classify_hebrew_text(text)
print(f"Label: {result['label']}")
print(f"Reason: {result['reason']}")
Input: "יא מטומטם, לך תמות"
Output:
Label: 1 (Offensive)
Reason: הטקסט מכיל קללה ("מטומטם") ואיום ("לך תמות"), שניהם ביטויים פוגעניים המטרתם להשפיל ולאיים.
Translation: "The text contains an insult ('idiot') and a threat ('go die'), both offensive expressions intended to humiliate and threaten."
This model was developed through a sophisticated three-stage training process combining teacher-student learning with preference optimization:
Direct Preference Optimization was chosen over traditional RLHF/PPO because:
Hardware:
Hyperparameters:
Memory Optimization:
This model is designed for:
⚠️ Important: This model reflects cultural and contextual interpretations of offensiveness in Israeli Hebrew discourse. Classifications should be:
This model was trained with Direct Preference Optimization (DPO), a method introduced in Direct Preference Optimization: Your Language Model is Secretly a Reward Model.
If you use this model in your research, please cite:
@mastersthesis{krancenblum2025hebrew,
title={Developing Reasoning-Augmented Language Models for Hebrew Offensive Language Detection},
author={Krancenblum, Kevyn},
year={2025},
school={Sami Shamoon College of Engineering},
note={Model: https://huggingface.co/KevynKrancenblum/hebrew-offensive-detection}
}
@inproceedings{rafailov2023direct,
title = {{Direct Preference Optimization: Your Language Model is Secretly a Reward Model}},
author = {Rafael Rafailov and Archit Sharma and Eric Mitchell and Christopher D. Manning and Stefano Ermon and Chelsea Finn},
year = 2023,
booktitle = {Advances in Neural Information Processing Systems 36: Annual Conference on Neural Information Processing Systems 2023, NeurIPS 2023, New Orleans, LA, USA, December 10 - 16, 2023},
url = {http://papers.nips.cc/paper_files/paper/2023/hash/a85b405ed65c6477a4fe8302b5e06ce7-Abstract-Conference.html}
}
@misc{vonwerra2022trl,
title = {{TRL: Transformer Reinforcement Learning}},
author = {Leandro von Werra and Younes Belkada and Lewis Tunstall and Edward Beeching and Tristan Thrush and Nathan Lambert and Shengyi Huang and Kashif Rasul and Quentin Gallou{\'e}dec},
year = 2020,
journal = {GitHub repository},
publisher = {GitHub},
howpublished = {\url{https://github.com/huggingface/trl}}
}
MIT License - See LICENSE file for details