Skip to content

Pillar 03 · Applied Technology

Dictionary

Tokens in Language Models (LLMs) and AI

5 min read
Download article as Markdown (.md) Verify version and integrity

TL;DR

A token is the basic text unit processed by an LLM, often representing a word fragment: on average, 100 tokens equal about 75 words. Here we explain how tokenization works (BPE, WordPiece, and others), why tokens define context limits and usage costs, and how they work in vision and speech.

Tokens in Language Models (LLMs) and AI

What Are Tokens?

Tokens are fundamental components in Language Models (LLMs), such as ChatGPT, Google Gemini, and Claude (by Anthropic) (in Portuguese).

Unlike a complete word, a token can represent smaller parts of a word.

As a general rule of thumb, 100 tokens are equivalent to roughly 75 words.

Thus, before an API request is processed when using an artificial intelligence system (for example), the prompt (user text) is converted into tokens.

If you still do not know what Artificial Intelligence is: Click Here.

How Does Tokenization Work?

This conversion process is called tokenization, where words, characters, and/or phrases are transformed into unique tokens that the model can process.

However, the number of tokens required for a given text depends on the language being processed as well as the specific tokenization method.

See an example of a Tokenizer made available for free by OpenAI (access it here to test it yourself).

Tokenization Example Adapted by the Author. Source: OpenAI Tokenizer, 2024.

The most common tokenization models are:

Byte Pair Encoding (BPE): Starts with individual characters and iteratively merges the most frequent pairs into new subwords (the system used by OpenAI).

WordPiece: Similar to BPE, but uses a probability measure to select which pairs to combine (Google Gemini uses variations of BPE and WordPiece).

Unigram Language Model: Uses a statistical language model to select the subwords that maximize the overall probability of the text.

This step is crucial for handling any textual input, allowing the model to process requests and generate responses.

The Role of Tokens in Language Models

In LLMs, every prompt provided by the user is transformed into a sequence of tokens.

These tokens are then converted into vectors, representing coordinates in a multidimensional space.

Those vectors are subsequently processed by the model’s transformers, adjusting internal weights and interactions to produce a coherent, contextualized response.

For example, when you interact with ChatGPT or Google Gemini, your text input is first tokenized, turning the text into a series of tokens that the model can compute.

When the language model replies to you, it uses a process we call decoding.

During decoding, the vectors generated by the model are converted back into tokens.

Next, those tokens are reassembled into words or sentences in the target language, ensuring the response delivered by the model is clear and readable.

Tokens and the Processing Capacity of LLMs

The processing capacity of LLMs is heavily influenced by token count.

Models with larger context capacity can process longer sequences of tokens, enabling deeper comprehension of complex conversations and requests.

However, this capacity is bounded by a maximum number of tokens that the model can process at once.

We call this capacity the “Context Window”.

Models in the GPT-4 series process a context window of 128,000 tokens (see the OpenAI documentation).

Models like Google Gemini reach an impressive 2 million tokens (see the Google documentation).

Expanding that window without multiplying computing costs is an active research challenge, and one example is the Titans architecture by Google Research (in Portuguese), which I reviewed here.

If you are using an AI through a standard chat interface, you will rarely see the exact volume of tokens being processed.

That limitation stays “built into” the AI’s internal processing and response.

That differs from more advanced environments built for users with deeper technical knowledge, such as the OpenAI Playground.

Example of token usage with an AI assistant. Author screenshot in 2024.

Impact of Tokens on LLM Usage Costs

Tokens also play a crucial role in pricing LLM usage.

Many language model service providers, such as OpenAI, base their pricing plans on the number of tokens processed.

Each token represents a unit of cost, and the more tokens you consume, the higher the cost to the user.

This happens because the basic unit of processing (the token) directly drives compute utilization across large data centers, involving a complex chain of infrastructure factors that culminate in service pricing.

This token-based pricing structure requires users and engineers to manage interactions efficiently to avoid unnecessary expenses, optimizing prompts and making the best use of the model’s processing capacity.

Learn more about API pricing for OpenAI, Google, or Anthropic.

And of course, it is worth noting that tokens are equally used across other applications involving Machine Learning, where algorithms use them to identify patterns in Natural Language Processing (NLP), data analysis, statistics, code development, and more.

Tokens in Computer Vision (Vision) and Text-to-Speech (TTS)

Tokens in Vision Systems

In computer vision systems, tokens can represent distinct visual elements within an image or video, such as:

  • Objects: Cars, people, animals, etc.
  • Features: Edges, corners, textures, colors, etc.
  • Regions: Specific areas of the image, such as the sky, the road, or a face.

These visual tokens can be used for a variety of tasks, including:

  • Object recognition: Identifying and classifying objects within an image.
  • Object detection: Locating objects in an image and drawing bounding boxes around them.
  • Image segmentation: Dividing an image into semantically meaningful regions (for example, separating foreground from background).
  • Object tracking: Following the movement of objects across video frames.
  • Caption generation: Describing the content of an image in natural language.

Tokens for Text-to-Speech (TTS) Systems

In TTS systems, that is, converting text into sound (or audio), tokens represent phonetic units such as phonemes, syllables, or words.

These tokens are used for:

  • Speech synthesis: Converting written text into audible speech.
  • Speech recognition: Converting audible speech into written text.
  • Speech translation: Converting speech from one language into another.
  • Voice customization: Adjusting synthetic voice characteristics to sound more natural or expressive.

Therefore, tokens are used to represent complex information in a structured form, enabling Machine Learning (ML) algorithms to process and analyze that data efficiently.

Tokenization is also a foundational step in developing increasingly sophisticated and accurate computer vision and TTS systems.

Conclusions

Tokens are essential elements in how large language models operate, influencing everything from processing capacity to usage costs.

Understanding the role of tokens and tokenization helps users and developers optimize their interactions with models like ChatGPT and Google Gemini, ensuring more efficient and cost-effective operation.

Sign up on our portal to receive the latest updates (worldwide) on artificial intelligence and language models straight to your email, for free. ;D

References

IBM, OpenAI and Lark.

Direct Advisory

Shall we talk about your project?

Share your context and let's see which path makes sense for your current stage.

Chat on WhatsApp