CoolFace
Modelpublic

s-nlp/xlmr_formality_classifier

sourceHugging Faceopenrail++updated 2y agoView on Hugging Face
12likes222downloads
Model Card

Model Overview

This is the model presented in the paper "Detecting Text Formality: A Study of Text Classification Approaches".

XLM-Roberta-based classifier trained on XFORMAL -- a multilingual formality classification dataset.

Results All languages

precisionrecallf1-scoresupport
00.7449120.9277900.826354108019
10.8890880.6456300.74804896845
accuracy0.794405204864
macro avg0.8170000.7867100.787201204864
weighted avg0.8130680.7944050.789337204864

EN

precisionrecallf1-scoresupport
00.8000530.9629810.87398822151
10.9451060.7258990.82112419449
accuracy0.85213941600
macro avg0.8725790.8444400.84755641600
weighted avg0.8678690.8521390.84927341600

FR

precisionrecallf1-scoresupport
00.7467090.9257380.82664121505
10.8873050.6505920.75073119327
accuracy0.79550440832
macro avg0.8170070.7881650.78868640832
weighted avg0.8132570.7955040.79071140832

IT

precisionrecallf1-scoresupport
00.7212820.9146690.80654521528
10.8648870.6071350.71344519368
accuracy0.76902440896
macro avg0.7930840.7609020.75999540896
weighted avg0.7892920.7690240.76245440896

PT

precisionrecallf1-scoresupport
00.7175460.9081670.80168121637
10.8536280.5997000.70448119323
accuracy0.76264640960
macro avg0.7855870.7539330.75308140960
weighted avg0.7817430.7626460.75582640960

How to use

python
from transformers import XLMRobertaTokenizerFast, XLMRobertaForSequenceClassification

# load tokenizer and model weights
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.",
]

# prepare the input
encoding = tokenizer(
    texts,
    add_special_tokens=True,
    return_token_type_ids=True,
    truncation=True,
    padding="max_length",
    return_tensors="pt",
)

# inference
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)
]
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}]

Citation

@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.",
}

Licensing Information

This model is licensed under the OpenRAIL++ License, which supports the development of various technologies—both industrial and academic—that serve the public good.