Skip to main content
Version: 9.2.11

text_normalize

Normalize Vietnamese text by fixing common encoding and diacritic issues.

Usage

from underthesea import text_normalize

text = "Ðảm baỏ chất lựơng phòng thí nghịêm hoá học"
normalized = text_normalize(text)
print(normalized)
# "Đảm bảo chất lượng phòng thí nghiệm hóa học"

Function Signature

def text_normalize(text: str, tokenizer: str = 'underthesea') -> str

Parameters

ParameterTypeDefaultDescription
textstrThe input text to normalize
tokenizerstr'underthesea'The tokenizer to use

Returns

TypeDescription
strThe normalized text

Examples

Basic Usage

from underthesea import text_normalize

# Fix diacritic issues
text_normalize("Ðảm baỏ chất lựơng")
# "Đảm bảo chất lượng"

Common Fixes

# Fix Đ/Ð confusion
text_normalize("Ðại học")
# "Đại học"

# Fix vowel diacritics
text_normalize("hoá học")
# "hóa học"

# Fix tone marks
text_normalize("nghịêm")
# "nghiệm"

Full Text Normalization

text = "Ðây là một ví dụ về việc chuẩn hoá văn bản tiếng Việt"
normalized = text_normalize(text)
print(normalized)
# "Đây là một ví dụ về việc chuẩn hóa văn bản tiếng Việt"

Common Issues Fixed

IssueExampleFixed
Đ/Ð confusionÐạiĐại
Old-style diacriticshoáhóa
Incorrect vowel compositionlựơnglượng
Unicode normalizationVariousNFC form

Notes

  • This function is useful for preprocessing Vietnamese text
  • It handles common encoding issues from legacy systems
  • The output is in Unicode NFC normalized form