The Unit of Understanding Prompts in Generative AI: Token
A token is the smallest unit of text that an AI processes, which includes words, punctuation, numbers, and more.
Reference: How Generative AI Understands Prompts
AI models like ChatGPT process text on a token basis, enabling them to understand and generate sentences.
For example, the sentence Hello, my name is CodeFriends!
is tokenized as follows:
- Hello
- ,
- my
- name
- is
- Code
- Friends
- !
The AI model understands the relationships between these tokens statistically, and based on the input prompt, generates new text.
Cost Calculation Structure of Generative AI Models
Generative AI calculates costs considering both input tokens
to understand the prompt and output tokens
to generate responses.
For example, let's assume a model's cost structure is $0.002 per 1,000 tokens.
If an AI needs 400 tokens to understand a prompt and 1,100 tokens to generate a response, the total cost is calculated as follows:
-
Input tokens: 400 tokens x $0.002 / 1,000 tokens = $0.0008
-
Output tokens: 1,100 tokens x $0.002 / 1,000 tokens = $0.0022
Therefore, the total cost is $0.0008 (input) + $0.0022 (output) = $0.003.
Writing Prompts to Reduce Costs
To reduce the number of tokens required for the desired response, it's beneficial to write prompts as follows:
Generally, more tokens are used for output than input, so optimizing for output tokens is especially important.
- Control Output Length: Limit the length of the AI's response to ensure it includes only the necessary information.
Please explain the reasons for the global acceleration of low birth rates within 200 characters.
- Specify Answer Format: Without a specified format, AI may generate responses longer than desired. Therefore, providing a preferred format with examples is advisable.
Explain the reasons for the global acceleration of low birth rates using the format below:
1. Economic factors: [within 100 characters]
2. Social change factors: [within 100 characters]
3. Policy factors: [within 100 characters]
Practice
Send prompt examples and compare the AI's responses.
Want to learn more?
Join CodeFriends Plus membership or enroll in a course to start your journey.