Formality Transfer: Register and Style in Text
Module: Natural Language Processing | Difficulty: Advanced
Formality Score
Transfer Model
Evaluation
| Model | BLEU | Formality | Fluency |
|---|---|---|---|
| Copy | 85.2 | 52.3 | 92.1 |
| Seq2Seq | 68.5 | 78.1 | 75.3 |
| BERT-based | 72.3 | 82.5 | 80.2 |
import torch
import torch.nn as nn
class FormalityTransfer(nn.Module):
def __init__(self, encoder, decoder, formality_control):
super().__init__()
self.encoder = encoder
self.decoder = decoder
self.formality_control = formality_control
def forward(self, x, target_formality):
content = self.encoder(x)
style = self.formality_control(target_formality)
output = self.decoder(content, style)
return output
Research Insight: Formality transfer is useful for adjusting text to different audiences. The key challenge is preserving content while changing style. Contrastive learning between formal and informal versions improves transfer quality.