Instructions to use nrl-ai/vn-register-phobert-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use nrl-ai/vn-register-phobert-base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="nrl-ai/vn-register-phobert-base")# Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("nrl-ai/vn-register-phobert-base") model = AutoModelForSequenceClassification.from_pretrained("nrl-ai/vn-register-phobert-base", device_map="auto") - Notebooks
- Google Colab
- Kaggle
vn-register-phobert-base
4-class Vietnamese text register classifier — labels each input as
one of formal (administrative / legal) / business (news /
encyclopaedic) / conversational (chat / forum) / literary
(classical narrative). Use the predicted register to route a text
through the right downstream checkpoint — VN diacritic /
summarization / OCR-rerank checkpoints all spread 5-10 pp accuracy
across registers, so a cheap router lifts every other tool
automatically.
PhoBERT-base backbone (135 M params, MIT, VinAI lab) fine-tuned with a
4-way sequence-classification head. Word-segmented input via
nom.text.word_tokenize
per the BKai gotcha (raw text drops accuracy ≥ 15 pp on PhoBERT-style
models).
Measured on test split
In-house bench, 2026-05-03, n=1234 stratified test split (CUDA, BF16):
| Class | Precision | Recall | F1 | Support |
|---|---|---|---|---|
formal |
0.889 | 0.941 | 0.914 | 34 |
business |
0.885 | 0.928 | 0.906 | 400 |
conversational |
0.887 | 0.945 | 0.915 | 400 |
literary |
0.924 | 0.815 | 0.866 | 400 |
| macro avg | 0.896 | 0.907 | 0.900 | 1234 |
Both adoption gates clear: macro F1 ≥ 0.85, every per-class F1 ≥ 0.75.
Source benchmarks/accuracy/register_phobert_base_baseline.json
re-runnable from a clean clone via
training/register/train.py.
Corpus
Source-provenance labelling — no human annotators needed. Every sentence inherits its register label from the source corpus it came from:
| Label | Source(s) | License |
|---|---|---|
formal |
UDHR-vi (PD) + UDHR diacritic-eval slice (PD) | Public Domain |
business |
wiki_vi (Wikipedia VN extracts) | CC-BY-SA-4.0 |
conversational |
tatoeba_vi 3k + tatoeba diacritic-eval-300 | CC-BY 2.0 FR |
literary |
wikisource_vi (PD) + UD-VTB train/dev/test | PD + CC-BY-SA-4.0 |
Class imbalance — formal only has 169 unique sentences (UDHR is
naturally short), the others cap at 2 000 each. The 134 / 169 / 169 /
169 split per register survives the imbalance (model still hits 0.91
F1 on formal — class weighting wasn't needed). Future v2: add a
permissive VN legal corpus to grow formal.
Use
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tok = AutoTokenizer.from_pretrained("nrl-ai/vn-register-phobert-base")
model = AutoModelForSequenceClassification.from_pretrained("nrl-ai/vn-register-phobert-base")
# IMPORTANT: PhoBERT requires word-segmented input (multi-syllable words
# joined with underscores). Use VnCoreNLP's RDRSegmenter or nom.text:
from nom.text import normalize, word_tokenize
text = "Doanh thu công ty quý 2 năm 2026 tăng 18 %."
segmented = " ".join(t.replace(" ", "_") for t in word_tokenize(normalize(text)))
import torch
ids = tok(segmented, return_tensors="pt", truncation=True, max_length=256)
with torch.no_grad():
logits = model(**ids).logits
probs = torch.softmax(logits, dim=-1).squeeze().tolist()
labels = ["formal", "business", "conversational", "literary"]
for label, p in sorted(zip(labels, probs), key=lambda x: -x[1]):
print(f" {label:<15} {p:.3f}")
# → business 0.952
# formal 0.029
# conversational 0.012
# literary 0.007
Or via the nom-vn wrapper:
from nom.classify import PhoBertRegisterClassifier
clf = PhoBertRegisterClassifier() # default model_id = this repo
result = clf.predict("Doanh thu công ty quý 2 năm 2026 tăng 18 %.")
print(result.label, result.score, result.distribution)
Honesty notes
- Tested only on held-out 20 % of source-provenance corpus. A sentence labelled "formal" because it came from UDHR is a single data-distribution slice — real-world legal prose may shift. A genre classifier this scale needs cross-corpus eval (e.g. legal_vi from th1nhng0) before adoption claims beyond routing.
literaryrecall 0.815 < precision 0.924. When the model says "literary," it's usually right; when something IS literary, the model misses ~18 % to other classes (mostly toformalbecause of shared archaic vocab). Acceptable for routing — false negatives fall back to a sensible default.- Word-segmentation matters. Skip
word_tokenizeand accuracy drops 10-15 pp. The wrapper handles this; if you call the model directly, you must segment.
Citation
@misc{nguyen_vn_register_phobert_base_2026,
author = {Nguyen, Viet-Anh and {Neural Research Lab}},
title = {{vn-register-phobert-base: A 4-class Vietnamese text-register
classifier (formal / business / conversational / literary)}},
year = {2026},
url = {https://huggingface.co/nrl-ai/vn-register-phobert-base}
}
License: MIT (matches PhoBERT-base backbone).
Maintained as part of the nom-vn
project by Viet-Anh Nguyen (vietanh@nrl.ai) and Neural Research Lab.
- Downloads last month
- 6
Model tree for nrl-ai/vn-register-phobert-base
Base model
vinai/phobert-base