Vietnamese punctuation restoration + capitalization model — ONNX Runtime version of dragonSwing/vibert-capu.
PyTorch dependency removed (~2 GB → ~50 MB onnxruntime).
Variant
File
Size
Use case
FP32
vibert-capu.onnx
438 MB
Best accuracy, server / web service
INT8
vibert-capu.int8.onnx
110 MB
Desktop, embedded — dynamic-quantized weights, ~99% of FP32 accuracy
Architecture: BERT (FPTAI/vibert-base-cased) fine-tuned by dragonSwing on 5.6M OSCAR-2109 samples for the Seq2Labels punctuation+capitalization task (15 GECToR-style edit actions).
Why ONNX?
PyTorch (original)
ONNX Runtime (this repo)
Cold start
~6 s
~0.8 s
Runtime deps
torch (~2 GB)
onnxruntime (~50 MB)
Portable build
very heavy
lightweight
Quick start
python
1import numpy as np
2import onnxruntime as ort
3from huggingface_hub import snapshot_download
4from transformers import AutoTokenizer
56local = snapshot_download("welcomyou/vibert-capu-onnx")7tok = AutoTokenizer.from_pretrained(local)8sess = ort.InferenceSession(f"{local}/vibert-capu.int8.onnx",9 providers=["CPUExecutionProvider"])1011text ="hà nội là thủ đô việt nam tôi yêu nó"12enc = tok(text.split(), is_split_into_words=True, return_tensors="np")13# input_offsets: index of first subword for each word14word_ids = enc.word_ids()15offsets =[]16prev =None17for i, w inenumerate(word_ids):18if w isnotNoneand w != prev:19 offsets.append(i); prev = w
20input_offsets = np.array([offsets], dtype=np.int64)2122logits, detect_logits = sess.run(None,{23"input_ids": enc["input_ids"].astype(np.int64),24"attention_mask": enc["attention_mask"].astype(np.int64),25"token_type_ids": enc["token_type_ids"].astype(np.int64),26"input_offsets": input_offsets,27})28# logits: (1, num_words, 15) — 15 GECToR actions29# detect_logits: (1, num_words, 4) — error detection
Model I/O
Inputs (all int64):
Name
Shape
Description
input_ids
(batch, seq_len)
BPE token IDs from BertTokenizer
attention_mask
(batch, seq_len)
1 = real token, 0 = padding
token_type_ids
(batch, seq_len)
Segment IDs (always 0)
input_offsets
(batch, num_words)
Index of first subword for each whitespace-separated word
Outputs (float32):
Name
Shape
Description
logits
(batch, num_words, 15)
Action probabilities (15 GECToR-style edits)
detect_logits
(batch, num_words, 4)
Error-detection probabilities
15 actions:
$KEEP Giữ nguyên
$TRANSFORM_CASE_CAPITAL Viết hoa chữ cái đầu (hà nội → Hà Nội)
$APPEND_, Thêm dấu phẩy
$APPEND_. Thêm dấu chấm
$TRANSFORM_VERB_VB_VBN (không dùng cho tiếng Việt)
$TRANSFORM_CASE_UPPER Viết hoa toàn bộ (who → WHO)
$APPEND_: Thêm dấu hai chấm
$APPEND_? Thêm dấu hỏi
$TRANSFORM_VERB_VB_VBC (không dùng cho tiếng Việt)
$TRANSFORM_CASE_LOWER Viết thường
$TRANSFORM_CASE_CAPITAL_1 Viết hoa ký tự thứ 2
$TRANSFORM_CASE_UPPER_-1 Viết hoa trừ ký tự cuối
$MERGE_SPACE Nối từ
@@UNKNOWN@@
@@PADDING@@