Skip to content

Exception: stream did not contain valid UTF-8 #282

Description

@phamdinhkhanh

I get bug when tokenize ByteLevelBPETokenizer() for diacritic language in utf-16 such as 'Viet Nam' language. Bellow are my code initialize tokenizer.

%%time 
from pathlib import Path

from tokenizers import ByteLevelBPETokenizer

paths = ['file1.txt', 'file2.txt']
print(paths)
# Initialize a tokenizer
tokenizer = ByteLevelBPETokenizer()
# Customize training
tokenizer.train(files=paths, vocab_size=52000, min_frequency=2, special_tokens=[
    "<s>",
    "<pad>",
    "</s>",
    "<unk>",
    "<mask>",
])

And bug log:

in train(self, files, vocab_size, min_frequency, show_progress, special_tokens)
90 files = [files]
91 print('files list: \n', files)
---> 92 self._tokenizer.train(trainer, files)

Exception: stream did not contain valid UTF-8

my file1.txt and file2.txt contain words like:

xin chào tôi đến từ Việt Nam, tôi gặp vấn đề với tokenizer.

I try to find what self._tokenizer.train() does to fix it myself but project code are complicated. Can you explain what i was wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions