🚀 从文本进行性别预测
该模型仅依据英文文本内容,就能 预测 匿名发言者或作者的可能 性别。它基于 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}
}