Skip to content

Instantly share code, notes, and snippets.

@basujindal
Created May 13, 2024 21:25
Show Gist options
  • Save basujindal/26fb02ea3b681d97f659e10b6269eeed to your computer and use it in GitHub Desktop.
Save basujindal/26fb02ea3b681d97f659e10b6269eeed to your computer and use it in GitHub Desktop.
GPT-4o tokenizer
### based on https://twitter.com/tianle_cai/status/1790109646205890723
import tiktoken
import langdetect
from tqdm import trange, tqdm
import concurrent.futures
import time
import csv
lang = "ja"
num_workers = 40
T = tiktoken.get_encoding("o200k_base")
# # Check token language
# def process_item(item):
# try:
# if langdetect.detect(T.decode([item])) == lang:
# return T.decode([item])
# except:
# pass
# Check token language
def process_item(item):
try:
return (langdetect.detect(T.decode([item])),T.decode([item]))
except:
pass
# Sort by length
length_dict = {}
for i in trange(T.n_vocab):
try:
length_dict[i] = len(T.decode([i]))
except:
pass
length_dict = dict(sorted(length_dict.items(), key=lambda item: -item[1]))
# Using ProcessPoolExecutor
def parallel_process_with_process_pool(items):
results = []
with concurrent.futures.ProcessPoolExecutor(max_workers=num_workers) as executor:
future_to_item = {executor.submit(process_item, item): item for item in items}
for future in tqdm(concurrent.futures.as_completed(future_to_item), total=len(future_to_item), desc="Processing items"):
# for future in concurrent.futures.as_completed(future_to_item):
item = future_to_item[future]
try:
result = future.result()
if result is not None:
results.append(result)
except Exception as e:
# pass
print(f'Item {item} generated an exception: {e}')
return results
# def write_results_to_file(results, filename):
# with open(filename, 'w') as f:
# for result in results:
# f.write(f"{result}\n")
def write_results_to_csv(results, filename):
# Extract unique languages
languages = sorted(set(result[0] for result in results))
with open(filename, 'w', newline='') as f:
writer = csv.writer(f)
writer.writerow(languages)
language_dict = {lang: [] for lang in languages}
for result in results:
language_dict[result[0]].append(result[1])
max_length = max(len(words) for words in language_dict.values())
for i in range(max_length):
row = []
for lang in languages:
if i < len(language_dict[lang]):
row.append(language_dict[lang][i])
else:
row.append("")
writer.writerow(row)
print("Parallel processing using ProcessPoolExecutor:")
results_process = parallel_process_with_process_pool(length_dict)
write_results_to_csv(results_process, "results_process.csv")
@basujindal
Copy link
Author

Hindi:

विश्वविद्यालय
महत्वपूर्ण
अधिकारियों
खिलाड़ियों
पाकिस्तान
क्षेत्रों
जिन्होंने
वैज्ञानिक
निर्धारित
सकारात्मक
उन्होंने
कांग्रेस
प्रदर्शन
בישראל
इस्तेमाल
प्रभावित
परिवर्तन
प्रस्तुत
उद्देश्य
शुक्रवार
संक्रमित
संस्कृति
केंद्रीय
निर्देशन
विशेषज्ञ
राजस्थान
उत्कृष्ट
निर्माता
परिस्थित
इलेक्ट्र
क्षेत्र
जानकारी
क्योंकि
स्थानीय
निर्देश
विश्वास
मुताबिक
परीक्षा
संक्रमण
वेबसाइट
संयुक्त
महिलाओं
वर्तमान
अमेरिकी
स्थापित
परीक्षण
संबंधित
उपस्थित
मुश्किल
किसानों
स्मार्ट
स्वीकार
विस्तार
स्थापना
मंगलवार
उन्होंने
खिलाड़ी
अंग्रेज
दोस्तों
विज्ञान
सम्मेलन
नरेंद्र
अधिकांश
इंटरनेट
जिन्हें
नियुक्त
स्क्रीन
फिल्मों
संरक्षण
छात्रों
अक्टूबर
राज्यों
चिकित्स
उन्हें
प्रदेश
अनुसार
आवश्यक
प्रभाव
जिसमें
वीडियो
कैसीनो
मीडिया
स्थिति
केंद्र
संक्रम
करेंगे
आर्थिक
लगातार
आयोजित
शुरुआत
स्पष्ट
�ედავად
समर्थन
प्रवेश
हिस्सा
इंडिया
क्षमता
अध्ययन
स्वागत

@basujindal
Copy link
Author

basujindal commented May 13, 2024

Japanese

         
ありがとうございました
ありがとうございます
VIPがお送りします
        
風吹けば名無し
     
スーパーコピー
】【。】【”】【
@お腹いっぱい
風吹けば名無し
トラックバック
がお送りします
automaticamente
ご了承ください
名無しさん
ございました
レディース
ラックバック
      
お問い合わせ
お願いします
の名無しさん
してください
中央値との差
しております
・・・。
プロフィール
】【。】
されています
名無しさん
】【。】【
ありがとう
ございます
・・・
@恐縮です
ランキング
     
こんにちは
問い合わせ
続きを読む
】【、】【
送りします
スーパー
スポンサー
しています
名無しの
ありません
転載は禁止
ブラック
があります
平均との差
になります
オンライン
こんばんは
ブランド
カテゴリー
っています
コメント
@おーぷん
    
コメント
ください
  
いっぱい
   
・・・・
いました
しました
風吹けば
ディース
恐縮です
ポイント
について
 
ケース
・・・
あります
コピー
レビュー
ブランド
メンズ
はこちら
この記事
おすすめ
。しかし
ています
サービス
アクセス
おります
フォーム
ニュース
よろしく
カテゴリ
サイズ
クリック
ッション
りました
」という

@basujindal
Copy link
Author

zh-cn:

_日本毛片免费视频观看
中国福利彩票天天
久久免费热在线精品
无码不卡高清免费v
大发快三大小单双
给主人留下些什么吧
_HORIZONTAL
大发快三开奖结果
彩神争霸邀请码
免费视频在线观看
无码不卡高清免费
无码一区二区三区
大发时时彩计划
.TRAILING
大发时时彩开奖
大发时时彩怎么
大发快三是国家
大发快三是不是
精品一区二区三区
大发快三是什么
大发快三走势图
在线观看中文字幕
中国特色社会主义
彩神争霸是不是
大发时时彩是
大发彩票官网
大发快三怎么
大发快三开奖
大发游戏官网
大发快三和值
一本道高清无码
大发快三计划
久久综合久久爱
下载安装到手机
重庆时时彩的
大发快三官网
大发快三豹子
中华人民共和国
彩神争霸网站
中国福利彩票
彩神争霸邀请码
Trump's
大发快三如何
久久精品国产
热这里只有精品
亚洲男人天堂
北京赛车投注
大发时时彩
视频在线观看
一区二区三区
的天天中彩票
大发快三是
彩神争霸是
视频免费观看
《凤凰大参考
菲律宾申博
一级特黄大片
视频在线播放
。...
彩神争霸的
在线观看视频
大发快三的
电影在线观看
免费资料大全
北京赛车的
无码中文字幕
在线观看免费
开奖结果查询
久久国产视频
Théâtre
开奖现场直播
在线视频观看
棋牌游戏官网
亚历山大发
香港赛马会
娱乐官方网站
中文字幕无码
免费在线观看
免费人成视频
中文字幕在线
高清在线观看
人片在线观看
彩网大发快三
久久综合久久
网站免费观看

手机在线观看
日本一本道
在线视频精品
大发彩票网
黄色录像影片
人人中彩票
在线精品视频
娱乐平台开户
大发快三
】【,】【
中文字幕
国产精品
大发时时彩

@basujindal
Copy link
Author

French:

caractéristiques
particulièrement
entrepreneurship
recommendations
responsibilities
Entrepreneurship
implementations
supplémentaires
fonctionnalités
unconstitutional
automatiquement
malheureusement
environmentally
paasissutiss
essentiellement
electromagnetic
complémentaires
Recommendations
representations
supplementation
transplantation
dissatisfaction
implementation
progressivement
investissements
responsabilités
professionnels
transportation
confidentialité
communications
fonctionnement
@implementation
Implementation
advertisements
constitutional
recommendation
concentrations
responsabilité
demonstrations
supplémentaire
reconnaissance
établissements
téléchargement
collaborateurs
questionnaires
unquestionably
représentation
Constitutional
exceptionnelle
Communications
présidentielle
Recommendations
internationaux
quintessential
Recommendation
éventuellement
misconceptions
définitivement
réglementation
incontournable
communication
développement
contributions
entrepreneurs
establishment
implementation
consciousness
Implementation
environmental
contradictions
profissionais
conversations
demonstration
questionnaire
illustrations
environnement
encouragement
transcription
announcements
communications
Opportunities
régulièrement
subscriptions
connaissances
complementary
justification
uncertainties
immédiatement
distributions
jurisdictions
prescriptions
’environnement
établissement
scientifiques
propriétaires
consommateurs
prerequisites
effectivement
constructions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment