目录
一、安装方式
1.版本要求
Python版本>=3.8
2.安装命令
pip install tiktoken
二、代码样例
import tiktoken
enc = tiktoken.get_encoding("cl100k_base")
assert enc.decode(enc.encode("hello world")) == "hello world"
# To get the tokeniser corresponding to a specific model in the OpenAI API:
enc = tiktoken.encoding_for_model("gpt-4")
三、性能表现
tiktoken 比其他开源 tokeniser 快 3-6 倍
基于 1GB 文本进行测试,使用 GPT-2 tokeniser,使用 GPT2TokenizerFast
from tokenizers==0.13.2
, transformers==4.24.0
and tiktoken==0.2.0
。