🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

Formality Transfer: Register and Style in Text

Natural Language ProcessingFormality Transfer: Register and Style in TextđŸŸĸ Free Lesson

Formality Transfer: Register and Style in Text

Module: Natural Language Processing | Difficulty: Advanced

What You'll Learn

  • 1Define formality as a measurable property of text and score it with a lexical index
  • 2Formulate style transfer as conditioning a generator on a target register
  • 3Evaluate a transfer system with style accuracy, meaning preservation, and BLEU together
  • 4Use the GYAFC and X-FORMAL benchmarks and recall their reported scores

Formality transfer rewrites text from an informal register to a formal one, or the reverse, while keeping the meaning intact. It is harder than sentiment flipping because formality is gradient rather than binary, it is partly domain specific, and automatic metrics disagree with human judgments.

What Formality Means

Register is realized mostly at the lexical and syntactic levels: contractions, slang, discourse particles, and emoji signal informality, while nominalization, hedges, and complete clauses signal formality. A quick reference score is the lexical formality index of Matsuyoshi et al., which counts marked tokens:

ResourceSizeDomainsAnnotation
GYAFC (Rao and Tetreault, 2018)about 110K pairsEntertainment and Music, Family and Relationships4 human references per test sentence
PT16 (Pavlick and Tetreault, 2016)about 5,000 sentencesmixed web textLikert formality ratings, 88 percent pairwise agreement
X-FORMAL (Briakou et al., 2021)1,000 informal and 4,000 formal per languagesocial, reviewsFrench, Italian, Portuguese

GYAFC is the standard English resource: informal sentences from Yahoo Answers are paired with crowd-written formal rewrites, and evaluation always reports the two domains separately because Family and Relationships is more formulaic than Entertainment and Music.

The Transfer Task

A system must choose edits, not just words. The conditional generator view writes the target as

where is a register code injected into the decoder, either as a learned embedding or by prepending a control token. Meaning preservation is a constraint on that distribution, commonly expressed as a semantic cost:

with an sentence embedding and the token-level Levenshtein rate. Lower cost means fewer unnecessary changes; too low a cost, however, describes the copy strategy, which is why the copy baseline is always reported.

Evaluation

Three numbers are always reported together. Style accuracy is the fraction of outputs a formality classifier labels as the target register. Meaning similarity is cosine similarity between sentence embeddings of source and output. BLEU measures n-gram overlap with references.

Datasets and Baselines

System, GYAFC E and MBLEUNotes
Copy baseline29.9preserves meaning, never changes register
Rule based rewrite22.4low BLEU, drops references with heavy edits
Informal to formal direction32.7strongest of the reported baselines

Two cautions from the GYAFC paper. First, BLEU correlates negatively with human formality judgments on this task, at -0.10 for Entertainment and Music and -0.01 for Family and Relationships. Second, the formality classifier score correlates with humans at 0.55 and 0.57, which is better but still far from agreement, so neither number should be quoted alone.

X-FORMAL extends the same protocol to three European languages and adds an explicit direction, informal to formal and formal to informal, so a single model can be tested for both strengthening and weakening of register. PT16 matters for a different reason: it supplies graded human ratings rather than pairs, which is what you need to calibrate a formality classifier before using it as a metric.

Worked Code

python
import re

CONTRACTIONS = {"gonna": "going to", "wanna": "want to", "kinda": "somewhat",
                "gotta": "must", "yeah": "yes", "lol": "", "u": "you",
                "ur": "your", "thx": "thank you", "pls": "please"}
INFORMAL = set(CONTRACTIONS) | {"cool", "awesome", "stuff", "ok"}
FORMAL = {"therefore", "however", "shall", "furthermore", "regarding"}

def lexical_formality(text):
    words = re.findall(r"[a-z']+", text.lower())
    if not words:
        return 0.0
    formal = sum(1 for w in words if w in FORMAL)
    informal = sum(1 for w in words if w in INFORMAL)
    return (formal - informal) / len(words)

def formalize(text):
    out = text
    for slang, replacement in CONTRACTIONS.items():
        out = re.sub(rf"\b{slang}\b", replacement, out)
    out = re.sub(r"[!]{2,}", "!", out)
    out = re.sub(r"\s{2,}", " ", out)
    return out.strip().capitalize()

samples = ["gonna skip the party lol, ur loss", "yeah the movie was cool stuff"]
for s in samples:
    t = formalize(s)
    print(f"{lexical_formality(s):+.3f} -> {lexical_formality(t):+.3f}  {t}")

The second program scores candidates instead of applying rules blindly, which mirrors how reranking systems choose among edits.

python
import math
from itertools import product

LEXICON = {"gonna": ["going to", "will"], "wanna": ["want to", "wish to"],
           "cool": ["excellent", "fine"], "ok": ["acceptable", "fine"],
           "big": ["substantial", "large"]}

def tokens(text):
    return [w.strip(".,!?") for w in text.lower().split()]

def jaccard(a, b):
    a, b = set(a), set(b)
    return len(a & b) / max(len(a | b), 1)

def formal_score(text):
    words = tokens(text)
    marks = {"gonna": -1, "wanna": -1, "cool": -1, "ok": -1, "big": -1,
             "therefore": 1, "furthermore": 1, "shall": 1, "large": 1}
    return sum(marks.get(w, 0) for w in words) / max(len(words), 1)

def candidates(text):
    words = tokens(text)
    options = [LEXICON.get(w, [w]) for w in words]
    for combo in product(*options):
        yield " ".join(combo)

def best_rewrite(text, lam=0.6):
    src = tokens(text)
    ranked = []
    for cand in candidates(text):
        s_form = formal_score(cand)
        s_keep = jaccard(src, tokens(cand))
        ranked.append((s_form - lam * (1 - s_keep), cand))
    return max(ranked)

print(best_rewrite("gonna wanna cool big stuff"))
print(f"formality {formal_score('gonna wanna cool'):+.3f}")

Real-World Applications

  • Customer support: chat logs are rewritten into formal tickets, where the lexical index flags which messages still need editing.
  • Product review moderation: marketplaces normalize slang-heavy reviews before ranking them.
  • Accessibility: formal variants serve readers who struggle with colloquial text.
  • Localization: X-FORMAL shows the task transfers to French, Italian, and Portuguese with 81.5 and 80.5 formality accuracy against human references.

💡Never optimize BLEU alone

On GYAFC, BLEU correlates negatively with human formality judgments, so a system that edits more can look worse by BLEU while being judged better by people. Always report , , and BLEU together.

Common Mistakes

Treating formality as a binary label

Fix: Report the graded index F(x), since formality varies within one sentence

Optimizing only style accuracy

Fix: Pair it with meaning similarity, because an unrelated formal text scores well on style

Quoting one BLEU number for GYAFC

Fix: Report both domains separately, as the paper does

Best Practices

  • Always include the copy baseline for reference
  • Report style accuracy, meaning similarity, and BLEU as a triple
  • Ablate by domain, since Family and Relationships behaves differently

Key Takeaways

  • Formality is graded, so systems are scored with a lexical index plus classifier scores
  • The composite score is the geometric mean of style accuracy and meaning similarity
  • On GYAFC, BLEU correlates negatively with human formality judgments
  • GYAFC has about 110K pairs in two domains with 4 references per test sentence

Frequently Asked Questions

Why is BLEU unreliable for style transfer?

Because many valid rewrites share no n-gram overlap with the four references. On GYAFC the correlation between BLEU and human formality judgments was -0.10 and -0.01, meaning higher BLEU did not track what annotators preferred.

What does a copy baseline tell you?

It bounds the meaning side of the trade. Copying gives near perfect but low , so any real system must beat the copy on style while staying close to its similarity.

Do these metrics work across languages?

Partly. X-FORMAL evaluated French, Italian, and Portuguese with the same style accuracy measure and reported 81.5 and 80.5 against human references, but the formality lexicons and the notion of polite register need to be rebuilt per language.

Interview Questions

Q1: How do you stop a transfer model from changing the meaning?

Constrain decoding with an embedding similarity threshold or a cost term lambda times the edit rate

Q2: Why keep a copy baseline in every table?

It separates meaning preservation from actual style change, since copy wins on similarity and fails on style

Q3: Which human annotation supports the formality classifier?

PT16, about 5,000 sentences rated on a Likert scale with 88 percent pairwise agreement

CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-07

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Related Tutorials

Content with similar topics across other courses

Need Expert NLP Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement