Run this model with HF Jobs
Run kcsheang/ts-t5-base-4tokens on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/kcsheang/ts-t5-base-4tokens. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/kcsheang/ts-t5-base-4tokens on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/kcsheang/ts-t5-base-4tokens. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/kcsheang/ts-t5-base-4tokens. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use kcsheang/ts-t5-base-4tokens with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use kcsheang/ts-t5-base-4tokens with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="kcsheang/ts-t5-base-4tokens")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("kcsheang/ts-t5-base-4tokens") model = AutoModelForSeq2SeqLM.from_pretrained("kcsheang/ts-t5-base-4tokens", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use kcsheang/ts-t5-base-4tokens with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "kcsheang/ts-t5-base-4tokens" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "kcsheang/ts-t5-base-4tokens", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/kcsheang/ts-t5-base-4tokens
- SGLang
How to use kcsheang/ts-t5-base-4tokens 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 "kcsheang/ts-t5-base-4tokens" \ --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": "kcsheang/ts-t5-base-4tokens", "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 "kcsheang/ts-t5-base-4tokens" \ --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": "kcsheang/ts-t5-base-4tokens", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use kcsheang/ts-t5-base-4tokens with Docker Model Runner:
docker model run hf.co/kcsheang/ts-t5-base-4tokens
YAML Metadata Warning:The pipeline tag "text2text-generation" is not in the official list: text-classification, token-classification, table-question-answering, question-answering, zero-shot-classification, translation, summarization, feature-extraction, text-generation, fill-mask, sentence-similarity, text-to-speech, text-to-audio, automatic-speech-recognition, audio-to-audio, audio-classification, audio-text-to-text, voice-activity-detection, depth-estimation, image-classification, object-detection, image-segmentation, text-to-image, image-to-text, image-to-image, image-to-video, unconditional-image-generation, video-classification, reinforcement-learning, robotics, tabular-classification, tabular-regression, tabular-to-text, table-to-text, multiple-choice, text-ranking, text-retrieval, time-series-forecasting, text-to-video, image-text-to-text, image-text-to-image, image-text-to-video, visual-question-answering, document-question-answering, zero-shot-image-classification, graph-ml, mask-generation, zero-shot-object-detection, text-to-3d, image-to-3d, image-feature-extraction, video-text-to-text, keypoint-detection, visual-document-retrieval, any-to-any, video-to-video, other
TS-T5 base, 4-token model
Controllable sentence simplification with a unified text-to-text transfer transformer. This is the 4-token model of Sheang and Saggion (2021), INLG. A T5-base model is fine-tuned to read control tokens that set how much the output should be shortened, rewritten and lexically simplified.
Code, evaluation and reproduction notes: https://github.com/KimChengSHEANG/TS_T5.
These are the weights from the original 2020 Google Drive training runs (max sequence length 256), converted to
safetensors. They are not the later 2021 retrains.
Intended use and limits
- English only, sentence level (one sentence per input), Wikipedia-style text.
- Non-commercial use only (CC BY-NC 4.0).
- Output can drop or change meaning. Check it before relying on it, especially for names, numbers and negation.
- Can return the input unchanged when it finds nothing to simplify.
Training data
WikiLarge (dataset: wikilarge in the training config). Hardware and total training time were not recorded for the
released runs; see docs/REPRODUCE.md.
Input format
The model input is "simplify: " + control tokens + the sentence. The control tokens are written first, and a double
space separates them from the sentence. The default tokens give, for The cat sat on the mat .:
"simplify: C_0.95 L_0.75 WR_0.75 DTD_0.75 The cat sat on the mat ."
Control tokens
Each token is a target ratio between the simplified output and the source.
| Token | Controls | Default |
|---|---|---|
C |
character length ratio | 0.95 |
L |
Levenshtein similarity (how much of the source is kept) | 0.75 |
WR |
word rank ratio (lexical complexity, rarer words score higher) | 0.75 |
DTD |
dependency tree depth ratio (syntactic complexity) | 0.75 |
Use the defaults first. Other values change the output; the effect of each token is in
docs/FINDINGS.md. Write every value with two decimals, as in training (C_0.80, not C_0.8: the model reads them differently), give all
tokens, and keep their order.
How to use
Do not use pipeline(); transformers 5 has no task for this model. Use the code below.
import torch
from transformers import T5ForConditionalGeneration, T5TokenizerFast
repo = "kcsheang/ts-t5-base-4tokens"
tokenizer = T5TokenizerFast.from_pretrained(repo)
model = T5ForConditionalGeneration.from_pretrained(repo).eval()
text = "simplify: C_0.95 L_0.75 WR_0.75 DTD_0.75 The cat sat on the mat ."
enc = tokenizer(text, max_length=256, padding="max_length", truncation=True, return_tensors="pt")
with torch.no_grad():
out = model.generate(
input_ids=enc["input_ids"],
attention_mask=enc["attention_mask"],
num_beams=8,
do_sample=False,
early_stopping=True,
max_length=256,
num_return_sequences=1,
)
print(tokenizer.decode(out[0], skip_special_tokens=True, clean_up_tokenization_spaces=True))
Replace the sentence after the control tokens with your own. The repo's CLI builds the input for you:
ts-t5 simplify (see the GitHub README).
Decoding used for all reported scores: num_beams=8, do_sample=False, early_stopping=True, max_length=256,
input padded to 256 tokens. generation_config.json in this repo carries the same decoding settings, so a bare
model.generate(**inputs) call decodes the same way (padding to 256 aside).
Evaluation
Scored with easse evaluate_system_output(test_set=..., lowercase=True) with turkcorpus_test and asset_test,
default tokens, decoding as above.
| Test set | SARI | BLEU | FKGL |
|---|---|---|---|
| TurkCorpus test | 43.50 | 67.26 | 6.17 |
| ASSET test | 45.05 | 72.24 | 6.33 |
These are the numbers in the GitHub README. The tables in the paper are lower because they score an earlier decoding pass of the same runs. Details are in docs/RESULTS.md.
Human evaluation
The paper's human evaluation (Table 3) rated the 5-token model, not this one. A separate batch of 20 HITs rated this 4-token model at its default tokens; it is not in the paper. Ratings and protocol: docs/HUMAN_EVALUATION.md.
Training hyperparameters
From configs/4tokens.json:
| Parameter | Value |
|---|---|
model_name |
t5-base |
max_seq_length |
256 |
learning_rate |
0.0003 |
weight_decay |
0.1 |
adam_epsilon |
1e-08 |
warmup_steps |
5 |
train_batch_size |
6 |
gradient_accumulation_steps |
16 |
num_train_epochs |
5 |
max_grad_norm |
1.0 |
seed |
12 |
fp_16 |
False |
Citation
@inproceedings{sheang-saggion-2021-controllable,
title = "Controllable Sentence Simplification with a Unified Text-to-Text Transfer Transformer",
author = "Sheang, Kim Cheng and Saggion, Horacio",
booktitle = "Proceedings of the 14th International Conference on Natural Language Generation",
month = aug,
year = "2021",
address = "Aberdeen, Scotland, UK",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2021.inlg-1.38",
pages = "341--352"
}
License
CC BY-NC 4.0 for the model and the code.
- Downloads last month
- 39
Model tree for kcsheang/ts-t5-base-4tokens
Base model
google-t5/t5-base