SecondThought both-t5

A small T5 model that rewrites a heated or casual sentence so it's polite and professional, while keeping what it says. It powers the SecondThought browser extension, which suggests a calmer version of a message before you send it.

One model does two jobs, chosen with a prefix:

Prefix What it does Example
detoxify: Removes insults and hostility "this report is garbage" β†’ "this report is not good"
formalize: Makes casual writing formal "hey, send me those numbers" β†’ "Please send me those numbers."

The extension runs detoxify: first and then formalize: on each sentence. Together, "this report is garbage, fix it" becomes "This report is bad, but you should fix it."

How to use

from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

repo = "SaiRahul5/secondthought-both-t5"
tokenizer = AutoTokenizer.from_pretrained(repo)
model = AutoModelForSeq2SeqLM.from_pretrained(repo)

def rewrite(prefix, text):
    inputs = tokenizer(prefix + text, return_tensors="pt", truncation=True, max_length=128)
    output = model.generate(**inputs, max_length=128, num_beams=4, do_sample=False)
    return tokenizer.decode(output[0], skip_special_tokens=True)

text = rewrite("detoxify: ", "this report is garbage, fix it")
print(rewrite("formalize: ", text))

It runs comfortably on a CPU (about 60M parameters, 240 MB).

Training

  • Base model: google-t5/t5-small
  • Detoxification data: ParaDetox (Logacheva et al., 2022), with the detoxify: prefix
  • Formality data: GYAFC (Rao & Tetreault, 2018), informal β†’ formal pairs from the Entertainment & Music and Family & Relationships domains, with the formalize: prefix
  • Setup: both tasks mixed in one fine-tuning run for 3 epochs, learning rate 3e-4, inputs and outputs capped at 128 tokens.

The training notebook is research/notebooks/train_both.ipynb.

Limitations

  • Word-level edits. It swaps or drops harsh words but rarely restructures a sentence, so sarcasm, passive aggression and rhetorical jabs ("Did you even read it?") usually come back unchanged.
  • Facts can drift. Like most small rewriters, it sometimes changes numbers, dates or names. The SecondThought extension checks for this and puts the original values back. If you use the model on its own, check the output.
  • One sentence at a time, up to 128 tokens, English only.
  • It can still be wrong about tone. Always read the suggestion before sending it.

Licence and data

This model is shared for research and non-commercial use only.

  • No training data is included in this repository. GYAFC is available only on request, through the Yahoo Answers L6 corpus, under its own terms. This model doesn't grant any rights to that data.
  • ParaDetox and T5-small have their own licences. Please see their pages.

Citation

If you use this model, please cite the datasets it was trained on:

@inproceedings{rao-tetreault-2018-dear,
  title = "Dear Sir or Madam, May {I} Introduce the {GYAFC} Dataset: Corpus, Benchmarks and Metrics for Formality Style Transfer",
  author = "Rao, Sudha and Tetreault, Joel",
  booktitle = "Proceedings of NAACL-HLT 2018",
  year = "2018"
}

@inproceedings{logacheva-etal-2022-paradetox,
  title = "{P}ara{D}etox: Detoxification with Parallel Data",
  author = "Logacheva, Varvara and Dementieva, Daryna and Ustyantsev, Sergey and Moskovskiy, Daniil and Dale, David and Krotova, Irina and Semenov, Nikita and Panchenko, Alexander",
  booktitle = "Proceedings of ACL 2022",
  year = "2022"
}
Downloads last month
43
Safetensors
Model size
60.5M params
Tensor type
F32
Β·
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for SaiRahul5/secondthought-both-t5

Finetuned
(2,351)
this model

Dataset used to train SaiRahul5/secondthought-both-t5