python tiktoken的簡(jiǎn)介、安裝、使用方法
tiktoken的簡(jiǎn)介
tiktoken是一個(gè)用于OpenAI模型的快速BPE標(biāo)記器。
1、性能:tiktoken比一個(gè)類(lèi)似的開(kāi)源分詞器快3到6倍
tiktoken的安裝
pip install tiktoken pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tiktoken
C:\Windows\system32>pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tiktoken Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting tiktoken Downloading https://pypi.tuna.tsinghua.edu.cn/packages/91/cf/7f3b821152f7abb240950133c60c394f7421a5791b020cedb190ff7a61b4/tiktoken-0.5.1-cp39-cp39-win_amd64.whl (760 kB) |████████████████████████████████| 760 kB 726 kB/s Requirement already satisfied: regex>=2022.1.18 in d:\programdata\anaconda3\lib\site-packages (from tiktoken) (2022.3.15) Requirement already satisfied: requests>=2.26.0 in d:\programdata\anaconda3\lib\site-packages (from tiktoken) (2.31.0) Requirement already satisfied: charset-normalizer<4,>=2 in d:\programdata\anaconda3\lib\site-packages (from requests>=2.26.0->tiktoken) (2.0.12) Requirement already satisfied: urllib3<3,>=1.21.1 in d:\programdata\anaconda3\lib\site-packages (from requests>=2.26.0->tiktoken) (1.26.9) Requirement already satisfied: idna<4,>=2.5 in d:\programdata\anaconda3\lib\site-packages (from requests>=2.26.0->tiktoken) (3.3) Requirement already satisfied: certifi>=2017.4.17 in d:\programdata\anaconda3\lib\site-packages (from requests>=2.26.0->tiktoken) (2021.10.8) Installing collected packages: tiktoken Successfully installed tiktoken-0.5.1
tiktoken的使用方法
1、基礎(chǔ)用法
(1)、用于OpenAI模型的快速BPE標(biāo)記器
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")
(2)、幫助可視化BPE過(guò)程的代碼
from tiktoken._educational import * # Train a BPE tokeniser on a small amount of text enc = train_simple_encoding() # Visualise how the GPT-4 encoder encodes text enc = SimpleBytePairEncoding.from_tiktoken("cl100k_base") enc.encode("hello world aaaaaaaaaaaa")
到此這篇關(guān)于python tiktoken的簡(jiǎn)介、安裝、使用方法的文章就介紹到這了,更多相關(guān)python tiktoken安裝使用內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
keras讀取訓(xùn)練好的模型參數(shù)并把參數(shù)賦值給其它模型詳解
這篇文章主要介紹了keras讀取訓(xùn)練好的模型參數(shù)并把參數(shù)賦值給其它模型詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-06-06如何向scrapy中的spider傳遞參數(shù)的幾種方法
這篇文章主要介紹了如何向scrapy中的spider傳遞參數(shù)的幾種方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11Python實(shí)現(xiàn)Youku視頻批量下載功能
前段時(shí)間由于收集視頻數(shù)據(jù)的需要,自己搗鼓了一個(gè)YouKu視頻批量下載的程序。下面小編把實(shí)現(xiàn)過(guò)程分享到腳本之家平臺(tái),供大家參考2017-03-03python實(shí)現(xiàn)Dijkstra靜態(tài)尋路算法
這篇文章主要介紹了python實(shí)現(xiàn)Dijkstra靜態(tài)尋路算法,常用于路由算法或者作為其他圖算法的一個(gè)子模塊,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-01-01完美解決python遍歷刪除字典里值為空的元素報(bào)錯(cuò)問(wèn)題
下面小編就為大家?guī)?lái)一篇完美解決python遍歷刪除字典里值為空的元素報(bào)錯(cuò)問(wèn)題。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-09-09Python可變參數(shù)會(huì)自動(dòng)填充前面的默認(rèn)同名參數(shù)實(shí)例
今天小編就為大家分享一篇Python可變參數(shù)會(huì)自動(dòng)填充前面的默認(rèn)同名參數(shù)實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-11-11