Skip to content

CanvaChen/chinese-llama-tokenizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

简介

tokenizer-human

重头设计词表,以人类词典规范收录字词(为进一步缩小词表,当前去掉了之前版本的编程语言关键字和数学符号)。

词表大小为39800,包含:

  • 简体字(8106个)
  • 词语(17000条)
  • 英文词根词缀
  • 英文词汇
  • 其它(日文假名等)
  1. 优点:小而美,支持中英日三国语言;兼容Llama 3对话模板
  2. 用法:重头训练LLM

效果

针对以下文本进行分词(运行test_tokenizer.py):

<|begin_of_text|><|start_header_id|>user<|end_header_id|>知足常乐…… <|eot_id|><|end_of_text|>
### 中文
白日依山尽,黄河入海流。欲穷千里目,更上一层楼。
### 日语
日常生活(にちじょうせいかつ、)
### English
TheMore
The Americans
Anarchism is a political philosophy and movement that is skeptical of all justifications for authority and seeks to abolish the institutions it claims maintain unnecessary coercion and hierarchy, typically including nation-states, and capitalism.
### 其他
  f(b)-f(a)=f′(ξ)(b-a),ξ∈(a,b)
  Ⅳ. 2³ ∛8

结果:

['▁\n', '<|begin_of_text|>', '<|start_header_id|>', '▁user', '<|end_header_id|>', '▁', '知足常乐', '……', '<|eot_id|>',
 '<|end_of_text|>', '▁\n', '###▁', '中文', '\n', '白日', '依', '山', '尽', ',', '黄河', '入', '海', '流', '。', '欲',
 '穷', '千', '里', '目', ',', '更', '上', '一', '层', '楼', '。', '\n', '###▁', '日语', '\n', '日常', '生活', '(', 'に',
 'ち', 'じ', 'ょ', 'う', 'せ', 'い', 'か', 'つ', '、', ')', '\n', '###', '▁English', '\n', 'The', 'More', '\n', 'The',
 '▁American', 's', '\n', 'An', 'arch', 'ism', '▁is', '▁a', '▁political', '▁philosophy', '▁and', '▁movement', '▁that',
 '▁is', '▁skeptical', '▁of', '▁all', '▁justification', 's', '▁for', '▁authority', '▁and', '▁seek', 's', '▁to', '▁a',
 'bol', 'ish', '▁the', '▁institution', 's', '▁it', '▁claim', 's', '▁maintain', '▁unnecessary', '▁co', 'er', 'c', 'ion',
 '▁and', '▁hierarchy', ',', '▁typical', 'ly', '▁in', 'clud', 'ing', '▁nation', '-', 'st', 'ate', 's', ',', '▁and',
 '▁capitalism', '.', '\n', '###▁', '其他', '\n', '▁', 'f', '(', 'b', ')', '-', 'f', '(', 'a', ')', '=', 'f', '′', '(',
 'ξ', ')', '(', 'b', '-', 'a', ')', ',', 'ξ', '∈', '(', 'a', ',', 'b', ')', '\n', '▁', 'Ⅳ', '.', '▁', '2', '³', '▁',
 '∛', '8', '\n']

token数为163。


对比下LLaMA-3的分词结果:

['Ċ', '<|begin_of_text|>', '<|start_header_id|>', 'user', '<|end_header_id|>', 'çŁ¥', '足', '常', 'ä¹IJ', 'âĢ¦âĢ¦',
 'Ġ', '<|eot_id|>', '<|end_of_text|>', 'Ċ', '###', 'Ġä¸Ń', 'æĸĩ', 'Ċ', 'çĻ½', 'æĹ¥', 'ä¾Ŀ', 'å±±', 'å°½', 'ï¼Į', 'é»Ħ',
 'æ²³', 'åħ¥', 'æµ·', 'æµģ', 'ãĢĤ', '欲', 'ç©', '·', 'åįĥ', 'éĩĮ', '缮', 'ï¼ĮæĽ´', 'ä¸Ĭ', 'ä¸Ģ', 'å±Ĥ', '楼', 'ãĢĤĊ',
 '###', 'ĠæĹ¥', 'è¯Ń', 'Ċ', 'æĹ¥', '常', 'çĶŁæ´»', 'ï¼Ī', 'ãģ«', 'ãģ¡', 'ãģĺ', 'ãĤĩãģĨ', 'ãģĽ', 'ãģĦãģĭ', 'ãģ¤', 'ãĢģ',
 'ï¼īĊ', '###', 'ĠEnglish', 'Ċ', 'The', 'More', 'Ċ', 'The', 'ĠAmericans', 'Ċ', 'An', 'arch', 'ism', 'Ġis', 'Ġa',
 'Ġpolitical', 'Ġphilosophy', 'Ġand', 'Ġmovement', 'Ġthat', 'Ġis', 'Ġskeptical', 'Ġof', 'Ġall', 'Ġjust', 'ifications',
 'Ġfor', 'Ġauthority', 'Ġand', 'Ġseeks', 'Ġto', 'Ġabolish', 'Ġthe', 'Ġinstitutions', 'Ġit', 'Ġclaims', 'Ġmaintain',
 'Ġunnecessary', 'Ġcoercion', 'Ġand', 'Ġhierarchy', ',', 'Ġtypically', 'Ġincluding', 'Ġnation', '-states', ',', 'Ġand',
 'Ġcapitalism', '.Ċ', '###', 'Ġåħ¶ä»ĸ', 'Ċ', 'Ġ', 'Ġf', '(b', ')-', 'f', '(a', ')=', 'f', 'âĢ²', '(', 'ξ', ')(', 'b',
 '-a', '),', 'ξ', 'âĪ', 'Ī', '(', 'a', ',b', ')Ċ', 'Ġ', 'Ġ', 'âħ', '£', '.', 'Ġ', '2', '³', 'ĠâĪ', 'Ľ', '8', 'Ċ']

LLaMA-3 token数为145。

总体上,中文编码效率我们更高,而英文编码LLaMA-3更好。但其词表非常大,用了128K,而我们不到40K就达到了不错的效果。

About

目标:构建一个更符合语言学的小而美的 llama 分词器,支持中英日三国语言

Topics

Resources

License

Stars

Watchers

Forks

Languages