Text Generation
Transformers
Safetensors
Vietnamese
t5
text2text-generation
text-generation-inference
Instructions to use nmcuong/ByT5-Vi-Normalization with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use nmcuong/ByT5-Vi-Normalization with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="nmcuong/ByT5-Vi-Normalization")# Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("nmcuong/ByT5-Vi-Normalization") model = AutoModelForSeq2SeqLM.from_pretrained("nmcuong/ByT5-Vi-Normalization") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use nmcuong/ByT5-Vi-Normalization with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "nmcuong/ByT5-Vi-Normalization" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nmcuong/ByT5-Vi-Normalization", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/nmcuong/ByT5-Vi-Normalization
- SGLang
How to use nmcuong/ByT5-Vi-Normalization 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 "nmcuong/ByT5-Vi-Normalization" \ --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": "nmcuong/ByT5-Vi-Normalization", "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 "nmcuong/ByT5-Vi-Normalization" \ --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": "nmcuong/ByT5-Vi-Normalization", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use nmcuong/ByT5-Vi-Normalization with Docker Model Runner:
docker model run hf.co/nmcuong/ByT5-Vi-Normalization
Upload ByT5 Vietnamese Normalization model
Browse files- README.md +37 -4
- model.safetensors +1 -1
README.md
CHANGED
|
@@ -48,22 +48,20 @@ ByT5-Vi-Normalization is a fine-tuned version of Google's ByT5-small model, spec
|
|
| 48 |
|
| 49 |
## Usage
|
| 50 |
|
|
|
|
| 51 |
You can use the model with Hugging Face Transformers as follows:
|
| 52 |
|
| 53 |
```python
|
| 54 |
from transformers import T5ForConditionalGeneration, AutoTokenizer
|
| 55 |
import torch
|
| 56 |
-
|
| 57 |
# Load model and tokenizer
|
| 58 |
model_dir = "nmcuong/ByT5-Vi-Normalization"
|
| 59 |
model = T5ForConditionalGeneration.from_pretrained(model_dir)
|
| 60 |
tokenizer = AutoTokenizer.from_pretrained(model_dir)
|
| 61 |
-
|
| 62 |
# Move model to GPU if available
|
| 63 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 64 |
model = model.to(device).to(dtype=torch.bfloat16)
|
| 65 |
model.eval()
|
| 66 |
-
|
| 67 |
# Example usage
|
| 68 |
input_text = "Normalize: Theo thông tư số 01/2023/TT-BTC, từ ngày 1/1/2024, Việt Nam sẽ áp dụng thuế giá trị gia tăng (VAT) mới cho các mặt hàng tiêu dùng."
|
| 69 |
inputs = tokenizer(input_text, return_tensors="pt", padding=True).to(device)
|
|
@@ -71,10 +69,45 @@ with torch.no_grad():
|
|
| 71 |
outputs = model.generate(**inputs, max_length=768, num_beams=2)
|
| 72 |
decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 73 |
print("Result:", decoded)
|
| 74 |
-
|
| 75 |
# Result: Theo thông tư số không một, năm hai nghìn không trăm hai mươi ba, Thông tư của Bộ Tài chính, từ ngày một tháng một, năm hai nghìn không trăm hai mươi tư, Việt Nam sẽ áp dụng thuế giá trị gia tăng mới cho các mặt hàng tiêu dùng.
|
| 76 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
---
|
| 79 |
|
| 80 |
## Example Inputs & Outputs
|
|
|
|
| 48 |
|
| 49 |
## Usage
|
| 50 |
|
| 51 |
+
## Hugging Face
|
| 52 |
You can use the model with Hugging Face Transformers as follows:
|
| 53 |
|
| 54 |
```python
|
| 55 |
from transformers import T5ForConditionalGeneration, AutoTokenizer
|
| 56 |
import torch
|
|
|
|
| 57 |
# Load model and tokenizer
|
| 58 |
model_dir = "nmcuong/ByT5-Vi-Normalization"
|
| 59 |
model = T5ForConditionalGeneration.from_pretrained(model_dir)
|
| 60 |
tokenizer = AutoTokenizer.from_pretrained(model_dir)
|
|
|
|
| 61 |
# Move model to GPU if available
|
| 62 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 63 |
model = model.to(device).to(dtype=torch.bfloat16)
|
| 64 |
model.eval()
|
|
|
|
| 65 |
# Example usage
|
| 66 |
input_text = "Normalize: Theo thông tư số 01/2023/TT-BTC, từ ngày 1/1/2024, Việt Nam sẽ áp dụng thuế giá trị gia tăng (VAT) mới cho các mặt hàng tiêu dùng."
|
| 67 |
inputs = tokenizer(input_text, return_tensors="pt", padding=True).to(device)
|
|
|
|
| 69 |
outputs = model.generate(**inputs, max_length=768, num_beams=2)
|
| 70 |
decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 71 |
print("Result:", decoded)
|
|
|
|
| 72 |
# Result: Theo thông tư số không một, năm hai nghìn không trăm hai mươi ba, Thông tư của Bộ Tài chính, từ ngày một tháng một, năm hai nghìn không trăm hai mươi tư, Việt Nam sẽ áp dụng thuế giá trị gia tăng mới cho các mặt hàng tiêu dùng.
|
| 73 |
```
|
| 74 |
+
---
|
| 75 |
+
## CTranslate2
|
| 76 |
+
you can also use the model with CTranslate2 for faster inference:
|
| 77 |
+
```bash
|
| 78 |
+
ct2-transformers-converter --model nmcuong/ByT5-Vi-Normalization --output_dir ByT5-Vi-Normalization-CT2
|
| 79 |
+
```
|
| 80 |
+
Then, you can load the model in Python:
|
| 81 |
+
```python
|
| 82 |
+
import ctranslate2
|
| 83 |
+
import transformers
|
| 84 |
+
|
| 85 |
+
# https://opennmt.net/CTranslate2/python/ctranslate2.Translator.html
|
| 86 |
+
translator = ctranslate2.Translator(
|
| 87 |
+
"ByT5-Vi-Normalization-CT2",
|
| 88 |
+
device="cuda",
|
| 89 |
+
device_index=0,
|
| 90 |
+
compute_type="bfloat16",
|
| 91 |
+
|
| 92 |
+
)
|
| 93 |
+
tokenizer = transformers.AutoTokenizer.from_pretrained("nmcuong/ByT5-Vi-Normalization")
|
| 94 |
|
| 95 |
+
|
| 96 |
+
input_text = "Normalize: Hôm nay là ngày 15/07/2025. Giá xăng tăng lên 25.000 đồng/lít"
|
| 97 |
+
input_tokens = tokenizer.convert_ids_to_tokens(
|
| 98 |
+
tokenizer.encode(input_text),
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
results = translator.translate_batch([input_tokens], max_decoding_length=768)
|
| 102 |
+
|
| 103 |
+
output_tokens = results[0].hypotheses[0]
|
| 104 |
+
output_text = tokenizer.decode(tokenizer.convert_tokens_to_ids(output_tokens))
|
| 105 |
+
|
| 106 |
+
print(output_text)
|
| 107 |
+
|
| 108 |
+
# Result: Hôm nay là ngày mười lăm tháng bảy năm hai nghìn không trăm hai mươi lăm. Giá xăng tăng lên hai mươi lăm nghìn đồng một lít.
|
| 109 |
+
```
|
| 110 |
+
> Note: The news in this example is for testing purposes only and does not represent real-life news.
|
| 111 |
---
|
| 112 |
|
| 113 |
## Example Inputs & Outputs
|
model.safetensors
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 1198571496
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1897fbd0ed4f4abe3406bcd6c84bd17586aee136025459e97541c4da7fe2774c
|
| 3 |
size 1198571496
|