Downloads · 30 days
402
0% of all-time downloads
ariyul/gender_prediction_model_from_text
gender_prediction_model_from_text is a text classification model from ariyul. Use it when you need a label for a piece of text. It is set up for transformers. The card lists the license as mit.
This model predicts the likely gender of an anonymous speaker or writer based solely on the content of an English text. It is built upon DeBERTa-v3-large and fine-tuned on a diverse, multilingual, and multi-domain dat…
Downloads · 30 days
402
0% of all-time downloads
All-time downloads
303K
Public
Parameters
435M
1.7 GB on disk
Likes
2
Public
Click a slice to open those files.
.safetensors1.7 GB · 100%
From the Hugging Face model README
This model predicts the likely gender of an anonymous speaker or writer based solely on the content of an English text. It is built upon DeBERTa-v3-large and fine-tuned on a diverse, multilingual, and multi-domain dataset with both formal and informal texts.
📍 Space link: 🔗 Try it out on Hugging Face Spaces
📁 Model repo: 🔗 View on Hugging Face Hub
🧠 Source code: GitHub
microsoft/deberta-v3-largefemale vs male)0.69 on a balanced multi-domain test set📂 Evaluation: View on Notebook
| Dataset | Domain | Type |
|---|---|---|
| samzirbo/europarl.en-es.gendered | Formal speech (Parliament) | English |
| czyzi0/luna-speech-dataset | Phone conversations | Polish → Translated |
| czyzi0/pwr-azon-speech-dataset | Phone conversations | Polish → Translated |
| sagteam/author_profiling | Social posts | Russian → Translated |
| kaushalgawri/nptel-en-tags-and-gender-v0 | Spoken transcripts | English |
| Blog Authorship Corpus | Blog posts | English |
All datasets were normalized, translated if necessary, deduplicated, and balanced via random undersampling to ensure equal representation of both genders.
Helsinki-NLP/opus-mt-* models for Polish and Russian data.2.66e-6)| Class | Precision | Recall | F1-Score | Accuracy | Support |
|---|---|---|---|---|---|
| Female | 0.70 | 0.65 | 0.68 | 591,027 | |
| Male | 0.68 | 0.72 | 0.70 | 591,027 | |
| Macro Avg | 0.69 | 0.69 | 0.69 | 1,182,054 | |
| Accuracy | 0.69 | 1,182,054 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
import torch.nn.functional as F
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model_name = "fc63/gender_prediction_model_from_text"
tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=False)
model = AutoModelForSequenceClassification.from_pretrained(model_name).eval().to(device)
def predict(text):
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=128).to(device)
with torch.no_grad():
outputs = model(**inputs)
probs = F.softmax(outputs.logits, dim=1)
pred = torch.argmax(probs, dim=1).item()
confidence = round(probs[0][pred].item() * 100, 1)
gender = "Female" if pred == 0 else "Male"
return f"{gender} (Confidence: {confidence}%)"
sample_text = "I love writing in my journal every night. It helps me reflect on the day and plan for tomorrow."
print(predict(sample_text))
The Output Of This Sample:
Female (Confidence: 84.1%)
I do not want to leave this model at the level of 0.69 accuracy and F1 score.
As far as I can detect at this point, there is a bias towards predicting emotional, psychological, and introspective texts as female. Similarly, more direct and result-oriented writings are also often predicted as male. Therefore, a large, carefully labeled dataset that reflects the opposite of this pattern is needed.
The datasets used to train this model had to be obtained from open-source platforms, which limited the range of accessible data.
To make further progress, I need to create and label a larger dataset myself — which requires a significant amount of time, effort, and cost.
Before moving to dataset creation, I plan to try a few more approaches using the current dataset. So far, alternative techniques have not helped improve the scores without causing overfitting. After testing a few more methods, if none work, the only step left will be building a new dataset — and that will likely be the point where I stop development, as it will be both labor-intensive and costly for me.
Author: Furkan Çoban
Project: CENG-481 Gender Prediction Model
License: MIT