CoolFace
Modelpublic

monsifnadir/DarijaBERT-For-Sentiment-Analysis

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
0likes28downloads
Model Card

DarijaBERT Fine-Tuned for Sentiment Analysis πŸ‡²πŸ‡¦πŸ§ 

This sentiment analysis model is based on DarijaBERT, a language model pretrained on Moroccan Arabic (Darija) text. The model has been fine-tuned to classify Moroccan Arabic tweets and public comments into three sentiment categories:

  • β€”Positive (2)
  • β€”Neutral (0)
  • β€”Negative (1)

πŸ›  Model Architecture

The base DarijaBERT architecture was extended with:

  • β€”Two fully connected layers of 1024 neurons each
  • β€”Dropout layer (p=0.3) to enhance generalization
  • β€”Final classification layer with 3 output neurons (one for each sentiment class)

🧠 Pretraining Details

  • β€”Dataset: 17,441 Moroccan tweets
  • β€”9,894 positive tweets (56.73%)
  • β€”4,039 neutral tweets (23.16%)
  • β€”3,508 negative tweets (20.11%)
  • β€”Training Framework: Hugging Face Trainer API
  • β€”Hyperparameters:
  • β€”Learning rate: 1e-5
  • β€”Batch size: 16 (with gradient accumulation = 32)
  • β€”Weight decay: 0.01
  • β€”EarlyStoppingCallback: Training stopped automatically at 92% accuracy
  • β€”Epochs: Up to 20
  • β€”Evaluation Strategy: Evaluated after every epoch, best model saved

Performance:

  • β€”Accuracy: 87%
  • β€”F1 Score: 87%
  • β€”Precision: 88%
  • β€”Cohen's Kappa: 0.80

πŸ”₯ Fine-Tuning Details (Cash Transfer Public Policy 2023)

  • β€”Dataset: 1,344 Moroccan comments from YouTube and Hespress
  • β€”515 neutral
  • β€”505 negative
  • β€”324 positive
  • β€”Split: 80% training / 20% testing
  • β€”Hyperparameters:
  • β€”Learning rate: 5e-6
  • β€”Batch size: 32
  • β€”Maximum sequence length: 256 tokens
  • β€”Warmup ratio: 0.1
  • β€”Early stopping enabled
  • β€”Class weights adjusted for imbalance

Performance:

  • β€”Accuracy: 91.6%
  • β€”Precision: 0.916
  • β€”Recall: 0.916
  • β€”F1 Score: 0.916
  • β€”Cohen’s Kappa: 0.872

πŸ“₯ How to Use the Model

python
from transformers import AutoTokenizer, AutoModelForSequenceClassification

model = AutoModelForSequenceClassification.from_pretrained("monsifnadir/DarijaBERT-For-Sentiment-Analysis")
tokenizer = AutoTokenizer.from_pretrained("monsifnadir/DarijaBERT-For-Sentiment-Analysis")

text = "فرحΨͺ بزاف Ψ§Ω„ΩŠΩˆΩ… Ψ§Ω„Ψ­Ω…Ψ― Ω„Ω„Ω‡"
inputs = tokenizer(text, return_tensors="pt", truncation=True)
outputs = model(**inputs)
predicted_class = outputs.logits.argmax(dim=-1).item()

# Map prediction to label
label_map = {0: "Neutral", 1: "Negative", 2: "Positive"}
print("Predicted Sentiment:", label_map[predicted_class])