Encoder/Decoder and tokens counter for GPT3
Project description
An OpenAI GPT3 helper library for encoding/decoding strings and counting tokens.
Counting tokens gives the same output as OpenAI’s tokenizer
Works with any Python version starting from 2.7.18
Installing
pip install gpt3_tokenizer
Examples:
Encoding/decoding a string
import gpt3_tokenizer
a_string = "That's my beautiful and sweet string"
encoded = gpt3_tokenizer.encode(a_string) # outputs [2504, 338, 616, 4950, 290, 6029, 4731]
decoded = gpt3_tokenizer.decode(encoded) # outputs "That's my beautiful and sweet string"
Counting tokens
import gpt3_tokenizer
a_string = "That's my beautiful and sweet string"
tokens_count = gpt3_tokenizer.count_tokens(a_string) # outputs 7
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
gpt3_tokenizer-0.1.0.tar.gz
(560.6 kB
view hashes)
Built Distribution
Close
Hashes for gpt3_tokenizer-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6f5c4416c2b3251d845e27b36a2b6b3b49c5bd5264ef7d59bb311a9b44083e6 |
|
MD5 | ad2e100b72e60ca7313f4e4948645f51 |
|
BLAKE2b-256 | 76559bc7de2dad3bfb159f3e0c8c4451549b8149da879f3649570799e32d00eb |