Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is a token in the context of language models?
A token is a small piece of text, like a word or part of a word, that the model processes. It can be a whole word, part of a word, or even punctuation.
Click to reveal answer
beginner
Why do we count tokens when using language models?
Counting tokens helps estimate how much text the model processes and predicts the cost, since many services charge based on the number of tokens used.
Click to reveal answer
beginner
How does token count affect the cost of using a language model?
The more tokens you use (input plus output), the higher the cost because pricing is usually per 1,000 tokens processed by the model.
Click to reveal answer
beginner
What is the difference between input tokens and output tokens?
Input tokens are the tokens you send to the model as a prompt. Output tokens are the tokens the model generates as a response.
Click to reveal answer
intermediate
How can you estimate the cost of a request to a language model?
Estimate the total tokens (input + output), then multiply by the cost per 1,000 tokens. For example, if cost is $0.02 per 1,000 tokens and you use 500 tokens, cost = 0.02 * (500/1000) = $0.01.
Click to reveal answer
What does one token usually represent in language models?
AA small piece of text like a word or part of a word
BA whole paragraph
CA single character only
DAn entire sentence
✗ Incorrect
Tokens are small pieces of text, often words or parts of words, not whole sentences or paragraphs.
Why is token counting important for cost estimation?
ABecause tokens are the same as characters
BBecause tokens determine the model's accuracy
CBecause tokens limit the number of users
DBecause cost depends on the number of tokens processed
✗ Incorrect
Costs are usually calculated based on how many tokens the model processes.
If a model charges $0.03 per 1,000 tokens, how much does 2,000 tokens cost?
A$0.03
B$0.06
C$0.30
D$0.003
✗ Incorrect
2,000 tokens is twice 1,000 tokens, so cost is 2 * $0.03 = $0.06.
Which tokens count towards cost in a language model request?
AOnly output tokens
BOnly input tokens
CBoth input and output tokens
DNeither input nor output tokens
✗ Incorrect
Both the tokens you send and the tokens the model generates count towards cost.
If your prompt has 300 tokens and you expect 700 tokens output, what is the total token count?
Explain in your own words why counting tokens is important when using language models.
Think about how the model processes text and how pricing works.
You got /3 concepts.
Describe how you would estimate the cost of a language model request given the number of tokens and price per 1,000 tokens.
Use simple multiplication and division.
You got /3 concepts.
Practice
(1/5)
1. What is a token in the context of AI language models?
easy
A. A hardware component
B. A small piece of text like a word or part of a word
C. A programming language
D. A type of AI model
Solution
Step 1: Understand token meaning
Tokens are the smallest pieces of text that AI models read, such as words or parts of words.
Step 2: Identify correct definition
Among the options, only A small piece of text like a word or part of a word correctly describes tokens as small text pieces.
Final Answer:
A small piece of text like a word or part of a word -> Option B
Quick Check:
Token = small text piece [OK]
Hint: Tokens are text chunks, not models or hardware [OK]
Common Mistakes:
Confusing tokens with AI models
Thinking tokens are programming languages
Assuming tokens are hardware parts
2. Which of the following Python code snippets correctly counts tokens using a simple split by spaces?
easy
A. tokens = text.split(' ')
count = len(tokens)
B. tokens = text.count(' ')
count = tokens + 1
C. tokens = len(text)
count = tokens
D. tokens = text.split()
count = tokens
Solution
Step 1: Understand token counting by splitting
Splitting text by spaces returns a list of tokens; counting tokens is length of that list.
Step 2: Check each option
tokens = text.split(' ')
count = len(tokens) splits by space and counts tokens correctly. tokens = text.count(' ')
count = tokens + 1 counts spaces but needs +1 for tokens. tokens = len(text)
count = tokens counts characters, not tokens. tokens = text.split()
count = tokens assigns list to count, which is incorrect.
Final Answer:
tokens = text.split(' ')
count = len(tokens) -> Option A
Quick Check:
Split by space + len() = token count [OK]
Hint: Use split(' ') and len() to count tokens simply [OK]
Common Mistakes:
Counting characters instead of tokens
Forgetting to add 1 when counting spaces
Assigning list directly to count variable
3. Given the text: "Hello world! This is AI." and a token counting method that splits by spaces, what is the token count?
medium
A. 7
B. 6
C. 4
D. 5
Solution
Step 1: Split the text by spaces
Splitting "Hello world! This is AI." by spaces gives: ['Hello', 'world!', 'This', 'is', 'AI.']
Step 2: Count the tokens
There are 5 tokens in the list.
Final Answer:
5 -> Option D
Quick Check:
5 tokens from splitting by space [OK]
Hint: Count words separated by spaces for quick token count [OK]
Common Mistakes:
Counting punctuation as separate tokens
Adding extra tokens incorrectly
Miscounting spaces
4. You wrote this code to count tokens but it gives an error:
text = "AI is fun"
tokens = text.split
count = len(tokens)
What is the error and how to fix it?
medium
A. Missing parentheses in split method call; fix with text.split()
B. len() cannot be used on list; use count() instead
C. text should be a list, not string
D. split method does not exist for strings
Solution
Step 1: Identify the error in method call
text.split is a method reference, not a call. It needs parentheses to execute.
Step 2: Fix the code
Change text.split to text.split() to get the list of tokens, then len() works correctly.
Final Answer:
Missing parentheses in split method call; fix with text.split() -> Option A
Quick Check:
Use split() with parentheses to call method [OK]
Hint: Always add () to call string methods like split() [OK]
Common Mistakes:
Forgetting parentheses on method calls
Using len() on method instead of list
Thinking split is not a string method
5. You want to estimate the cost of an AI request. The model charges $0.0001 per token. If your input has 120 tokens and output is expected to be 80 tokens, what is the total estimated cost?