Created
May 15, 2024 06:22
-
-
Save que-nguyen/65e416657c85a5ac259926d31c7aed89 to your computer and use it in GitHub Desktop.
vietnamese_token_inspector_gpt4o.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tiktoken | |
from lingua import Language, LanguageDetectorBuilder | |
detector = LanguageDetectorBuilder.from_all_languages().build() | |
T = tiktoken.get_encoding("o200k_base") | |
token_lengths = [] | |
for i in range(T.n_vocab): | |
try: | |
token = T.decode([i]) | |
if detector.detect_language_of(token) == Language.VIETNAMESE: | |
token_lengths.append((i, token, len(token))) | |
except: | |
continue | |
token_lengths.sort(key=lambda x: -x[2]) | |
# In ra 1000 từ Tiếng Việt | |
# LƯU Ý: lingua có thể không nhận diện chính xác tiếng Việt do giới hạn của thư viện :) | |
for idx, token, _ in token_lengths[:1000]: | |
print(idx, token) | |
''' | |
Result: | |
... | |
46901 trường | |
56202 nghiệp | |
61975 thường | |
76781 thương | |
77258 phương | |
80691 chuyển | |
83881 chuyên | |
91902 nghiệm | |
98606 nguyên | |
104745 truyền | |
107116 nghiền | |
107483 khoảng | |
121297 chuyện | |
... | |
131196 xử | |
131934 ươi | |
132945 ãng | |
135386 Bạn | |
137082 ưu | |
137746 cố | |
138394 Uy | |
138461 bố | |
139089 .Th | |
139745 ịtị | |
143913 tố | |
146655 dữ | |
147406 kể | |
150454 sẻ | |
151210 tô | |
152775 lã | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment