Arabic Gender Classifier (MARBERTv2, multi-task)
One model that predicts male / female / unknown from any Arabic text: a tweet, a profile or first name, a sentence, or longer text. You give it only the text. The model works out what kind of input it is and which evidence to use.
| Input | Example | Output | Evidence |
|---|---|---|---|
| name | فاطمة | female | name |
| name | أبو محمد | male | name |
| self-referential sentence | أنا تعبانة جدا اليوم | female | grammar |
| tweet with no explicit cue | الأهلي فاز اليوم بثلاثية | male (0.83) | style |
| emoji only | 😂😂 | unknown | style |
How it works
A shared MARBERTv2 encoder with five classification heads, trained jointly:
| Head | Classes | Learns |
|---|---|---|
is_name |
text / name | routing: is the input a name or running text? |
names |
female / male / unknown | gender of a first name (endings such as ـة، ـى، ـاء) |
grammatical |
female / male / unknown | speaker gender marked in the grammar, e.g. أنا سعيدة vs أنا سعيد |
author |
female / male / unknown | the writer's gender from writing style and content (weak signal) |
entity |
female / male / unknown | auxiliary (gender of a named entity in MT sentences); not used in the decision |
Decision rule (in predict):
- If
is_name≥ 0.5, use the names head. - Otherwise, if the grammatical head says male or female with confidence ≥
T_GRAM, use it (strong evidence). - Otherwise, use the author (style) head.
- Any answer below its threshold becomes
unknown.
The evidence column says which rule produced the answer. name and grammar are strong evidence. style is weak, so treat it as probabilistic.
Usage
# pip install transformers huggingface_hub safetensors pandas torch
from huggingface_hub import hf_hub_download
import importlib.util, sys
REPO = "rafiulbiswas/arabic-gender-marbertv2-multitask"
path = hf_hub_download(REPO, "gender_model.py")
spec = importlib.util.spec_from_file_location("gender_model", path)
gm = importlib.util.module_from_spec(spec); spec.loader.exec_module(gm)
clf = gm.ArabicGenderClassifier.from_pretrained(REPO) # add token="hf_..." if the repo is private
clf.predict(["فاطمة", "أنا تعبانة جدا اليوم", "الأهلي فاز اليوم بثلاثية", "😂😂"])
# id text gender confidence evidence
# 0 0 فاطمة female 0.9996 name
# 1 1 أنا تعبانة جدا اليوم female 1.0000 grammar
# 2 2 الأهلي فاز اليوم بثلاثية male 0.8291 style
# 3 3 😂😂 unknown 0.9993 style
With your own ids, or stricter thresholds for style:
import pandas as pd
df = pd.DataFrame({"id": [101, 102], "text": ["ريم", "صباح الخير يا جماعة"]})
clf.predict(df["text"].tolist(), ids=df["id"].tolist(), t_auth=0.90)
Raw probabilities from every head: clf.predict_proba(texts).
Results
Test sets are held out with group-aware 80/10/10 splits. Duplicates, and the male/female rewrites of the same sentence, never cross splits.
Per head (test)
| Head | Accuracy | Macro-F1 | Female F1 | Male F1 | Unknown F1 | Test rows |
|---|---|---|---|---|---|---|
| grammatical | 0.986 | 0.954 | 0.950 | 0.920 | 0.993 | 43,618 |
| names | 0.888 | 0.784 | 0.829 | 0.941 | 0.583 | 2,481 |
| author (single tweet/text) | 0.688 | 0.643 | 0.703 | 0.690 | 0.536 | 55,090 |
A separately trained names-only model reached macro-F1 0.797 and accuracy 0.884 on the same split. The multi-task model loses almost nothing by sharing the encoder.
Choosing the style threshold (T_AUTH, dev set)
Style-based answers trade coverage for accuracy:
| T_AUTH | Texts answered | Accuracy |
|---|---|---|
| 0.50 | 94% | 69.7% |
| 0.70 (default) | 70% | 75.5% |
| 0.80 | 56% | 78.9% |
| 0.90 | 39% | 84.3% |
| 0.95 | 27% | 88.7% |
The name and grammar thresholds are insensitive. Accuracy stays around 89% for names and 94% for grammar across 0.5–0.95.
End-to-end (text only, default thresholds, mixed test sets)
| True input type | Answered | Accuracy when answered |
|---|---|---|
| names | 90.2% | 89.7% |
| keywords | 95.8% | 100% |
| author texts | 70.1% | 75.1% |
About 6% of author texts (3,553 / 55,090) were decided by grammar, i.e. the writer referred to themself in gendered form. The rest were decided by style.
Training data
1,039,241 rows from 12 sources, unified into text → female / male / unknown:
| Task | Sources | Rows | Female | Male | Unknown |
|---|---|---|---|---|---|
| names + keywords | 5 Arabic first-name lists; ArabGend gender keywords | 21,572 | 6,029 | 13,330 | 2,213 |
| grammatical | Arabic Parallel Gender Corpus v2.1 (all four MM/FM/MF/FF files); APGC-labelled sentences | 436,509 | 23,376 | 23,387 | 389,746 |
| author | Arabic tweets by gender; Arabic opinion columns by author gender; Arabic profile texts | 581,060 | 259,630 | 257,826 | 63,604 |
| entity | Arabic MT-gender (WinoMT-style) sentences | 100 | 12 | 84 | 4 |
Label construction:
- APGC v2.1: the file suffix gives speaker/addressee gender (
FM= female speaker, male addressee). A line identical in its male- and female-speaker versions has no speaker marking and is labelledunknown. Two-letter APGC labels (MB/FB/BB…) map from the first letter. - Names: labels from several lists, merged by majority vote (≥ 80% agreement), otherwise
unknown. Single letters areunknown. - Conflicts: an identical text labelled both male and female (e.g. "يارب" tweeted by both, or unisex names) is
unknown. - Cleaning: site footers, retweet markers, mentions, URLs and APGC tags were removed. No rows were dropped.
Training procedure
- Base:
UBC-NLP/MARBERTv2, [CLS] representation, linear heads, dropout 0.1 - Loss: class-weighted cross-entropy per task + 0.3 ×
is_nameloss - Task sampling ∝ √(task size) per step, so the 580k tweets don't drown out 21k names
- AdamW, lr 2e-5, weight decay 0.01, 10% linear warm-up, batch 32, max length 128, fp16
- 3 epochs; best epoch chosen by mean dev macro-F1 across heads
- All rows of all tasks used for training
Limitations and bias
- Style predictions partly reflect topic stereotypes. Football → male is an example. The author head learns what men and women in the training data tend to write about, not who wrote a given text. Use a high
T_AUTH(≥ 0.90) where errors matter, and report style-based predictions separately from name and grammar evidence. - A single short text is weak evidence. Most tweets (emoji, greetings, religious phrases, news retweets) carry no gender signal. Aggregating many texts per user is far more reliable than one text.
- Binary labels. The model only knows
femaleandmale(plusunknown). It cannot represent non-binary identities and should not be used to assign gender to individuals. - Grammar ≠ author. The grammatical head detects the speaker's grammatical gender. In quoted speech, fiction or translation, that may not be the writer's.
- Names: unisex names (نور، عصمت، ميسرة) and Latin-script names are often
unknown. Female names are under-represented (about 1 : 2.2). - Domain: trained mostly on MSA news, Gulf/Egyptian Twitter and subtitle-style sentences. Other dialects and domains may perform worse.
Intended use
Aggregate, research-oriented analysis of Arabic text, such as studying gendered discourse at population level, auditing datasets, or estimating gender distribution in social-media corpora with explicit uncertainty.
Not intended for: profiling, targeting, or making decisions about identifiable individuals; inferring sensitive attributes of private persons; or any use where a wrong gender label could cause harm.
Files
| File | Content |
|---|---|
config.json, model.safetensors |
MARBERTv2 encoder (fine-tuned) |
| tokenizer files | MARBERTv2 tokenizer |
heads.safetensors |
weights of the five heads |
gender_config.json |
head sizes, label order, max length, default thresholds |
gender_model.py |
ArabicGenderClassifier loader and predict() |
Citation
If you use this model, please cite MARBERT and the Arabic Parallel Gender Corpus:
@inproceedings{abdul-mageed-etal-2021-arbert,
title = {{ARBERT} \& {MARBERT}: Deep Bidirectional Transformers for {A}rabic},
author = {Abdul-Mageed, Muhammad and Elmadany, AbdelRahim and Nagoudi, El Moatez Billah},
booktitle = {Proceedings of ACL-IJCNLP 2021},
year = {2021}
}
@inproceedings{alhafni-etal-2022-arabic,
title = {The {A}rabic Parallel Gender Corpus 2.0: Extensions and Analyses},
author = {Alhafni, Bashar and Habash, Nizar and Bouamor, Houda},
booktitle = {Proceedings of LREC 2022},
year = {2022}
}
@inproceedings{habash-etal-2019-automatic,
title = {Automatic Gender Identification and Reinflection in {A}rabic},
author = {Habash, Nizar and Bouamor, Houda and Chung, Christine},
booktitle = {Proceedings of the First Workshop on Gender Bias in Natural Language Processing},
year = {2019}
}
License
other: check the licenses of MARBERTv2 and of each training dataset (APGC is released for research use) before any redistribution or commercial use.
- Downloads last month
- 6
Model tree for rafiulbiswas/arabic-gender-marbertv2-multitask
Base model
UBC-NLP/MARBERTv2