🚀 從文本進行性別預測
該模型僅依據英文文本內容,就能 預測 匿名發言者或作者的可能 性別。它基於 DeBERTa - v3 - large 構建,並在包含正式和非正式文本的多樣化、多語言、多領域數據集上進行了微調。
🚀 Space鏈接:🤗 在Hugging Face Spaces上試用
📂 模型倉庫:🤗 在Hugging Face Hub上查看
✨ 主要特性
📦 安裝指南
文檔未提供安裝步驟,故跳過此章節。
💻 使用示例
基礎用法
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))
高級用法
文檔未提供高級用法示例,故跳過此部分。
📚 詳細文檔
模型信息
屬性 |
詳情 |
模型類型 |
基於DeBERTa - v3 - large的文本分類模型,用於性別預測 |
訓練數據 |
samzirbo/europarl.en - es.gendered、czyzi0/luna - speech - dataset、czyzi0/pwr - azon - speech - dataset、sagteam/author_profiling、kaushalgawri/nptel - en - tags - and - gender - v0等多領域數據集 |
評估指標 |
準確率、F1值、精確率、召回率 |
基礎模型 |
microsoft/deberta - v3 - large |
數據集
使用了以下數據集:
- [samzirbo/europarl.en - es.gendered](https://huggingface.co/datasets/samzirbo/europarl.en - es.gendered):正式演講(議會),英文
- [czyzi0/luna - speech - dataset](https://huggingface.co/datasets/czyzi0/luna - speech - dataset):電話對話,波蘭語(已翻譯)
- [czyzi0/pwr - azon - speech - dataset](https://huggingface.co/datasets/czyzi0/pwr - azon - speech - dataset):電話對話,波蘭語(已翻譯)
- sagteam/author_profiling:社交帖子,俄語(已翻譯)
- [kaushalgawri/nptel - en - tags - and - gender - v0](https://huggingface.co/datasets/kaushalgawri/nptel - en - tags - and - gender - v0):口語轉錄,英文
- Blog Authorship Corpus:博客文章,英文
所有數據集都進行了歸一化處理,必要時進行了翻譯、去重,並通過 隨機欠採樣 確保兩種性別的樣本數量平衡。
預處理與訓練
- 歸一化:清理了所有數據集中的引號、破折號、佔位符、噪聲和HTML/代碼。
- 翻譯:使用
Helsinki - NLP/opus - mt - *
模型處理波蘭語和俄語數據。
- 欠採樣:隨機欠採樣以平衡男性和女性樣本。
- 訓練策略:
- 使用LR Finder優化學習率(
2.66e - 6
)
- 使用基於F1值和損失的早停策略進行微調
- 每250步進行一次基於步驟的評估
- 保存並評估第24,750步的最佳檢查點
- 第二階段微調:
- 在完整合並數據集上進行2個epoch的微調
- 使用餘弦學習率調度器和熱身步驟
性能(在完整合並測試集上)
類別 |
精確率 |
召回率 |
F1值 |
準確率 |
樣本數 |
女性 |
0.70 |
0.65 |
0.68 |
|
591,027 |
男性 |
0.68 |
0.72 |
0.70 |
|
591,027 |
宏平均 |
0.69 |
0.69 |
0.69 |
|
1,182,054 |
準確率 |
|
|
|
0.69 |
1,182,054 |
未來工作與侷限性
目前模型存在一定侷限性,預測結果存在偏向性,例如情感、心理和內省類文本常被預測為女性,更直接和注重結果的文本常被預測為男性。因此,需要一個大規模、精心標註且能反映相反模式的數據集。
訓練模型使用的數據集來自開源平臺,限制了可獲取數據的範圍。要取得進一步進展,需要自己創建和標註更大的數據集,這需要大量的時間、精力和成本。
在創建數據集之前,計劃使用當前數據集嘗試更多方法。如果這些方法都無效,構建新數據集將是下一步,但這將既耗時又昂貴,可能會導致開發停止。
🔧 技術細節
該模型基於 DeBERTa - v3 - large 構建,在多領域、多語言數據集上進行微調。預處理階段對數據進行了歸一化、翻譯和欠採樣等操作。訓練過程中使用了LR Finder優化學習率,採用早停策略,並在第二階段微調中使用了餘弦學習率調度器和熱身步驟。
📄 許可證
作者:Furkan Çoban
項目:CENG - 481性別預測模型
許可證:MIT
引用
@misc{fc63_gender1_2025,
title = {Gender Prediction from Text},
author = {Çoban, Furkan},
year = {2025},
howpublished = {\url{https://doi.org/10.5281/zenodo.15619489}},
note = {DeBERTa-v3-large model fine-tuned on multi-domain gender-labeled texts}
}