



















OpenAI在6月13日刚刚进行了大规模降价和升级,text-embedding-ada-002降价95%,GPT-3.5-turbo降价了25%,GPT4最高可支持32K文本。
在OpenAI的官网( https://openai.com/pricing )上,对chatGPT的价格计算方式有详细的说明。但是其价格是以token来计算的,我们来算算现在的价格实际到底是多少。
官方网页上聊天是不花钱的,收费项目主要针对API用户。API用户默认赠送5美元额度。
测试样本:
Multiple models, each with different capabilities and price points. Prices are per 1,000 tokens. You can think of tokens as pieces of words, where 1,000 tokens is about 750 words. This paragraph is 35 tokens.
官方的样本文字中说明了,这段测试样本的长度为35个tokens。
ChatGPT使用的tokenizer是Byte-Pair Encoding(BPE)算法,有几种方法可以近似计算token值:
使用Transformers方法对测试样本进行tokens计算:
def get_transformers_tokens(text: str, encoding_name: str) -> int:
tokenizer = transformers.AutoTokenizer.from_pretrained(encoding_name)
tokens = tokenizer.tokenize(text)
num_tokens = len(tokens)
return num_tokens
得到tokens值为45。
使用tiktoken的方法对测试样本进行tokens计算:
def get_tiktoken_tokens(text: str, encoding_name: str) -> int:
encoding = tiktoken.get_encoding(encoding_name)
num_tokens = len(encoding.encode(text))
return num_tokens
得到tokens值也为45。
有趣的是,得出的值是45,和openai官方网页中给出35不同,但使用openai官方计算器( https://platform.openai.com/tokenizer )计算的结果,也是45。
又找到一个工具也可以计算tokens值:https://articlefiesta.com/seo-tools/token-calculator
这个工具得出的tokens值却是35。
tokens的消耗,至少受到以下三个因素的影响:
用以下样本为例,看下实际的费用:
How to calculate tokens for chatGPT?
To calculate the number of tokens for a text sequence in ChatGPT, you can follow these steps:
Tokenization: In ChatGPT, the text needs to be segmented into a sequence of words or subword units, called tokens. You can use a tokenizer to convert the text into tokens. The tokenizer used in ChatGPT is based on Byte-Pair Encoding (BPE) algorithm, which can convert the text into a decodable sequence of subword units.
Counting tokens: Once the text has been segmented into tokens, you can count the number of tokens. In ChatGPT, the number of tokens is equal to the number of tokens contained in the text. You can use the len() function to count the number of tokens.
Here is an example code that can calculate the number of ChatGPT tokens for a given text sequence:
python
import transformers
# Load the ChatGPT tokenizer
tokenizer = transformers.AutoTokenizer.from_pretrained("EleutherAI/gpt-neo-2.7B")
# Convert the text into tokens using the tokenizer
text = "Hello, how are you?"
tokens = tokenizer.tokenize(text)
# Count the number of tokens
num_tokens = len(tokens)
# Print the number of tokens
print("Number of tokens:", num_tokens)
Note that punctuation marks and spaces in the text are also converted into tokens. Therefore, the number of tokens may be higher than the number of words in the text.
Model Input Output
4K context $0.0015 / 1K tokens $0.002 / 1K tokens
16K context $0.003 / 1K tokens $0.004 / 1K tokens
将上面的样本内容和定价带入,可以计算出,5美元对应的对话次数是6887。也就是账号自带的5美元额度,大约可以聊6、7千句英文对话(中文对话会有所出入)。
通过此方法可以计算其他收费项目的具体价格情况:
Model Input Output
8K context $0.03 / 1K tokens $0.06 / 1K tokens
32K context $0.06 / 1K tokens $0.12 / 1K tokens
Ada $0.0004 / 1K tokens
Babbage $0.0005 / 1K tokens
Curie $0.0020 / 1K tokens
Davinci $0.0200 / 1K tokens
Model Training Usage
Ada $0.0004 / 1K tokens $0.0016 / 1K tokens
Babbage $0.0006 / 1K tokens $0.0024 / 1K tokens
Curie $0.0030 / 1K tokens $0.0120 / 1K tokens
Davinci $0.0300 / 1K tokens $0.1200 / 1K tokens
Model Usage
Ada v2 $0.0001 / 1K tokens
Ada v1 $0.0040 / 1K tokens
Babbage v1 $0.0050 / 1K tokens
Curie v1 $0.0200 / 1K tokens
Davinci v1 $0.2000 / 1K tokens
Resolution Price
1024×1024 $0.020 / image
512×512 $0.018 / image
256×256 $0.016 / image
Model Usage
Whisper $0.006 / minute (rounded to the nearest second)
虽然openai提供了token计算工具,但工具的计算值却和官方网页中的说明不一致。
使用API访问chatGPT3.5的话,账号自带的5美元,大约可以聊6000多句对话。
想深入理解token和分词,需要进一步深度学习如下概念:
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。