Instructions to use SaiRahul5/secondthought-both-t5 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use SaiRahul5/secondthought-both-t5 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="SaiRahul5/secondthought-both-t5")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("SaiRahul5/secondthought-both-t5") model = AutoModelForSeq2SeqLM.from_pretrained("SaiRahul5/secondthought-both-t5", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use SaiRahul5/secondthought-both-t5 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "SaiRahul5/secondthought-both-t5" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "SaiRahul5/secondthought-both-t5", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/SaiRahul5/secondthought-both-t5
- SGLang
How to use SaiRahul5/secondthought-both-t5 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "SaiRahul5/secondthought-both-t5" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "SaiRahul5/secondthought-both-t5", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "SaiRahul5/secondthought-both-t5" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "SaiRahul5/secondthought-both-t5", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use SaiRahul5/secondthought-both-t5 with Docker Model Runner:
docker model run hf.co/SaiRahul5/secondthought-both-t5
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
Model tree for SaiRahul5/secondthought-both-t5
Base model
google-t5/t5-small