Xlmr Formality Classifier
基于XLM-Roberta的多语言文本正式度分类模型,支持英语、法语、意大利语和葡萄牙语
下载量 795
发布时间 : 3/2/2022
模型简介
该模型用于检测文本的正式程度,能够将输入文本分类为'正式'或'非正式'两类。基于多语言正式度分类数据集XFORMAL训练而成。
模型特点
多语言支持
支持英语、法语、意大利语和葡萄牙语四种语言的正式度分类
高准确率
在英语分类任务中达到85.2%的准确率,其他语言准确率在76-80%之间
基于Transformer架构
使用XLM-Roberta-base作为基础模型,具有强大的文本理解能力
模型能力
文本正式度分类
多语言文本分析
使用案例
文本处理
正式文档筛选
自动识别和分类正式文档与非正式文档
可用于文档管理系统中的自动分类
写作辅助工具
帮助用户检查文本的正式程度,提供写作建议
提高写作质量,确保符合目标场合的正式度要求
内容审核
内容适切性检查
识别不适合正式场合的非正式内容
可用于论坛、评论区的自动审核
🚀 文本正式程度分类模型
本模型用于文本正式程度分类,基于XLM - Roberta架构,在多语言数据集上训练,能有效识别不同语言文本的正式或非正式程度,为自然语言处理相关任务提供支持。
🚀 快速开始
本模型是论文 "Detecting Text Formality: A Study of Text Classification Approaches" 中所提出的模型。它是一个基于XLM - Roberta的分类器,在 XFORMAL 多语言正式程度分类数据集上进行训练。
✨ 主要特性
- 多语言支持:支持英语(en)、法语(fr)、意大利语(it)和葡萄牙语(pt)等多种语言。
- 正式程度分类:能够对文本进行正式或非正式的分类。
📦 安装指南
使用本模型前,需要安装transformers
库,可使用以下命令进行安装:
pip install transformers
💻 使用示例
基础用法
from transformers import XLMRobertaTokenizerFast, XLMRobertaForSequenceClassification
# 加载分词器和模型权重
tokenizer = XLMRobertaTokenizerFast.from_pretrained('s-nlp/xlmr_formality_classifier')
model = XLMRobertaForSequenceClassification.from_pretrained('s-nlp/xlmr_formality_classifier')
id2formality = {0: "formal", 1: "informal"}
texts = [
"I like you. I love you",
"Hey, what's up?",
"Siema, co porabiasz?",
"I feel deep regret and sadness about the situation in international politics.",
]
# 准备输入
encoding = tokenizer(
texts,
add_special_tokens=True,
return_token_type_ids=True,
truncation=True,
padding="max_length",
return_tensors="pt",
)
# 推理
output = model(**encoding)
formality_scores = [
{id2formality[idx]: score for idx, score in enumerate(text_scores.tolist())}
for text_scores in output.logits.softmax(dim=1)
]
print(formality_scores)
运行上述代码后,输出结果如下:
[{'formal': 0.993225634098053, 'informal': 0.006774314679205418},
{'formal': 0.8807966113090515, 'informal': 0.1192033663392067},
{'formal': 0.936184287071228, 'informal': 0.06381577253341675},
{'formal': 0.9986615180969238, 'informal': 0.0013385231141000986}]
📚 详细文档
模型评估结果
所有语言
类别 | 精确率 | 召回率 | F1 - 分数 | 样本数 |
---|---|---|---|---|
0 | 0.744912 | 0.927790 | 0.826354 | 108019 |
1 | 0.889088 | 0.645630 | 0.748048 | 96845 |
准确率 | 0.794405 | 204864 | ||
宏平均 | 0.817000 | 0.786710 | 0.787201 | 204864 |
加权平均 | 0.813068 | 0.794405 | 0.789337 | 204864 |
英语(EN)
类别 | 精确率 | 召回率 | F1 - 分数 | 样本数 |
---|---|---|---|---|
0 | 0.800053 | 0.962981 | 0.873988 | 22151 |
1 | 0.945106 | 0.725899 | 0.821124 | 19449 |
准确率 | 0.852139 | 41600 | ||
宏平均 | 0.872579 | 0.844440 | 0.847556 | 41600 |
加权平均 | 0.867869 | 0.852139 | 0.849273 | 41600 |
法语(FR)
类别 | 精确率 | 召回率 | F1 - 分数 | 样本数 |
---|---|---|---|---|
0 | 0.746709 | 0.925738 | 0.826641 | 21505 |
1 | 0.887305 | 0.650592 | 0.750731 | 19327 |
准确率 | 0.795504 | 40832 | ||
宏平均 | 0.817007 | 0.788165 | 0.788686 | 40832 |
加权平均 | 0.813257 | 0.795504 | 0.790711 | 40832 |
意大利语(IT)
类别 | 精确率 | 召回率 | F1 - 分数 | 样本数 |
---|---|---|---|---|
0 | 0.721282 | 0.914669 | 0.806545 | 21528 |
1 | 0.864887 | 0.607135 | 0.713445 | 19368 |
准确率 | 0.769024 | 40896 | ||
宏平均 | 0.793084 | 0.760902 | 0.759995 | 40896 |
加权平均 | 0.789292 | 0.769024 | 0.762454 | 40896 |
葡萄牙语(PT)
类别 | 精确率 | 召回率 | F1 - 分数 | 样本数 |
---|---|---|---|---|
0 | 0.717546 | 0.908167 | 0.801681 | 21637 |
1 | 0.853628 | 0.599700 | 0.704481 | 19323 |
准确率 | 0.762646 | 40960 | ||
宏平均 | 0.785587 | 0.753933 | 0.753081 | 40960 |
加权平均 | 0.781743 | 0.762646 | 0.755826 | 40960 |
📄 许可证
本模型采用OpenRAIL++许可证,该许可证支持开发服务于公共利益的各类技术,包括工业和学术领域的技术。
📖 引用信息
如果您使用了本模型,请引用以下论文:
@inproceedings{dementieva-etal-2023-detecting,
title = "Detecting Text Formality: A Study of Text Classification Approaches",
author = "Dementieva, Daryna and
Babakov, Nikolay and
Panchenko, Alexander",
editor = "Mitkov, Ruslan and
Angelova, Galia",
booktitle = "Proceedings of the 14th International Conference on Recent Advances in Natural Language Processing",
month = sep,
year = "2023",
address = "Varna, Bulgaria",
publisher = "INCOMA Ltd., Shoumen, Bulgaria",
url = "https://aclanthology.org/2023.ranlp-1.31",
pages = "274--284",
abstract = "Formality is one of the important characteristics of text documents. The automatic detection of the formality level of a text is potentially beneficial for various natural language processing tasks. Before, two large-scale datasets were introduced for multiple languages featuring formality annotation{---}GYAFC and X-FORMAL. However, they were primarily used for the training of style transfer models. At the same time, the detection of text formality on its own may also be a useful application. This work proposes the first to our knowledge systematic study of formality detection methods based on statistical, neural-based, and Transformer-based machine learning methods and delivers the best-performing models for public usage. We conducted three types of experiments {--} monolingual, multilingual, and cross-lingual. The study shows the overcome of Char BiLSTM model over Transformer-based ones for the monolingual and multilingual formality classification task, while Transformer-based classifiers are more stable to cross-lingual knowledge transfer.",
}
Distilbert Base Uncased Finetuned Sst 2 English
Apache-2.0
基于DistilBERT-base-uncased在SST-2情感分析数据集上微调的文本分类模型,准确率91.3%
文本分类 英语
D
distilbert
5.2M
746
Xlm Roberta Base Language Detection
MIT
基于XLM-RoBERTa的多语言检测模型,支持20种语言的文本分类
文本分类
Transformers 支持多种语言

X
papluca
2.7M
333
Roberta Hate Speech Dynabench R4 Target
该模型通过动态生成数据集来改进在线仇恨检测,专注于从最差案例中学习以提高检测效果。
文本分类
Transformers 英语

R
facebook
2.0M
80
Bert Base Multilingual Uncased Sentiment
MIT
基于bert-base-multilingual-uncased微调的多语言情感分析模型,支持6种语言的商品评论情感分析
文本分类 支持多种语言
B
nlptown
1.8M
371
Emotion English Distilroberta Base
基于DistilRoBERTa-base微调的英文文本情感分类模型,可预测埃克曼六种基本情绪及中性类别。
文本分类
Transformers 英语

E
j-hartmann
1.1M
402
Robertuito Sentiment Analysis
基于RoBERTuito的西班牙语推文情感分析模型,支持POS(积极)/NEG(消极)/NEU(中性)三类情感分类
文本分类 西班牙语
R
pysentimiento
1.0M
88
Finbert Tone
FinBERT是一款基于金融通讯文本预训练的BERT模型,专注于金融自然语言处理领域。finbert-tone是其微调版本,用于金融情感分析任务。
文本分类
Transformers 英语

F
yiyanghkust
998.46k
178
Roberta Base Go Emotions
MIT
基于RoBERTa-base的多标签情感分类模型,在go_emotions数据集上训练,支持28种情感标签识别。
文本分类
Transformers 英语

R
SamLowe
848.12k
565
Xlm Emo T
XLM-EMO是一个基于XLM-T模型微调的多语言情感分析模型,支持19种语言,专门针对社交媒体文本的情感预测。
文本分类
Transformers 其他

X
MilaNLProc
692.30k
7
Deberta V3 Base Mnli Fever Anli
MIT
基于MultiNLI、Fever-NLI和ANLI数据集训练的DeBERTa-v3模型,擅长零样本分类和自然语言推理任务
文本分类
Transformers 英语

D
MoritzLaurer
613.93k
204
精选推荐AI模型
Llama 3 Typhoon V1.5x 8b Instruct
专为泰语设计的80亿参数指令模型,性能媲美GPT-3.5-turbo,优化了应用场景、检索增强生成、受限生成和推理任务
大型语言模型
Transformers 支持多种语言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一个基于SODA数据集训练的超小型对话模型,专为边缘设备推理设计,体积仅为Cosmo-3B模型的2%左右。
对话系统
Transformers 英语

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基于RoBERTa架构的中文抽取式问答模型,适用于从给定文本中提取答案的任务。
问答系统 中文
R
uer
2,694
98