Developer's Corner
Local-only: Tokenization runs in your browser via Xenova/all-MiniLM-L6-v2—your text is never uploaded or stored. 100% private.

AI Tokenizer & Token ID Visualizer

Explore how Large Language Models split text into tokens and numerical Token IDs in real time.

121 chars•20 words•0 tokens•Loading tokenizer...
Tokens0 tokens
Loading tokenizer...
Token IDs
Integer Array

How AI Tokenizers, Subword Splitting & Token IDs Work

Large Language Models (LLMs) such as GPT-4, Claude, and Llama, as well as embedding models like BERT and all-MiniLM-L6-v2, do not read raw text as characters or whole words. Before inference begins, a tokenizer splits your prompt into subword chunks called tokens and maps each chunk to an integer Token ID from a fixed vocabulary. Use this free browser-based AI token counter to inspect token boundaries and export Token ID arrays with zero prompt logging.

What Is a Token?

A token can be a full word ("apple"), a word with its leading space (" cat"), a prefix or suffix ("##ization"), punctuation, or a raw UTF-8 byte. In English text, 1 token averages around 4 characters or 0.75 words.

Token IDs & Embeddings

Each token maps to a vocabulary index such as [101, 2026, 4937]. The model looks up each ID in an embedding matrix to obtain a dense vector, which attention layers use to capture meaning and context across the sequence.

Local Browser Execution

Tokenization runs locally in your browser using Transformers.js and cached tokenizer files. System prompts, source code, and sensitive text stay on your machine with zero network requests.

BPE vs. WordPiece vs. SentencePiece

Different model families split the exact same string differently because they use different subword algorithms and vocabularies. Here is how the three main approaches work in practice:

1. Byte-Pair Encoding (BPE) in GPT-2 & GPT-4

OpenAI models use byte-level BPE. Training starts at the individual UTF-8 byte level and repeatedly merges the most frequent adjacent byte pairs into new vocabulary entries. Because the base alphabet is all 256 byte values, BPE never falls back to an unknown ([UNK]) token: any emoji, symbol, or non-Latin script can be encoded. Leading spaces are usually merged into the following word (" server" is one token, while "server" at the start of a line is a different Token ID).

2. WordPiece in BERT & all-MiniLM-L6-v2

WordPiece powers BERT and sentence-embedding models like all-MiniLM-L6-v2. Instead of merging purely by raw frequency, WordPiece chooses merges that maximize the likelihood of the training corpus. Rare or compound words are split into a root token followed by continuation pieces prefixed with ## (for example, "unbelievable" becomes "un", "##believ", "##able"). Sequences are also wrapped in [CLS] and [SEP] boundary tokens.

3. SentencePiece in T5 & Multilingual Models

SentencePiece (used by T5, LLaMA, and Mistral) operates directly on raw Unicode characters without assuming that words are separated by spaces. Spaces are encoded as an explicit ▁ character, making tokenization lossless and reversible. That design works well for languages without whitespace delimiters such as Japanese, Chinese, and Thai.

Example: How "Tokenizing 100ms!" splits across architectures
  • GPT-4 (BPE): ["Token", "izing", " 100", "ms", "!"] (5 tokens, leading space stays on " 100")
  • BERT / MiniLM (WordPiece): ["[CLS]", "token", "##izing", "100", "##ms", "!", "[SEP]"] (7 tokens, lowercased with ## continuations)
  • T5 (SentencePiece): ["▁Token", "izing", "▁100", "ms", "!", "</s>"] (6 tokens, explicit ▁ space marker)

Tokenizer Reference by Model

ModelAlgorithmTypical Use CaseNotable Behavior
GPT-4Byte-level BPE (cl100k)Chat, reasoning, code generationMerges multi-space indentation and common code keywords
GPT-2Byte-level BPE (50k vocab)Causal language modelingSplits repeated spaces individually; higher code token count
all-MiniLM-L6-v2WordPiece (30k vocab)Semantic search, RAG embeddingsLowercases input; adds [CLS] and [SEP]
BERT UncasedWordPiece (30.5k vocab)NER, text classification, Q&AStrips accents and casing; prefixes subwords with ##
T5 SmallSentencePiece UnigramTranslation, summarization, seq2seqPreserves spaces via ▁; appends </s>

Practical Impact on Prompt Token Counts, RAG Chunks & API Costs

  • API billing and latency: Providers charge per input and output token, and response time grows with output token count. Trimming redundant instructions or compacting JSON payloads (for example with our JSON Formatter & Minifier) directly lowers token usage.
  • Context window limits in RAG: Embedding models like all-MiniLM-L6-v2 and BERT typically cap sequences at 256 or 512 tokens. Any text past that boundary is silently truncated during indexing, so checking chunk sizes with a local tokenizer prevents lost context.
  • Why LLMs miscount letters or digits: Models see Token IDs rather than characters. Asking a model to count letters in a word or add large unspaced numbers often fails because subwords and digit groups (like "123" + "456") are opaque integers to the first layer.
  • Non-English & code token inflation: Vocabularies trained primarily on English prose encode common English words in one token, whereas non-Latin scripts, JSON punctuation, or unformatted stack traces can take 2x to 4x as many tokens for the same character count.
  • Special tokens & offline caching: Models reserve control tokens like [CLS], [SEP], </s>, and <|endoftext|> to mark boundaries. Once a tokenizer loads in your browser, it is cached locally so you can test prompts even offline.

Frequently Asked Questions

How many characters is 1 AI token?

In English prose, 1 token averages about 4 characters or 0.75 words. Punctuation, whitespace, emojis, code, and non-English text split into more tokens depending on the model vocabulary.

Why do GPT-4, GPT-2, BERT, and T5 produce different token counts?

Each model family uses a different algorithm (BPE, WordPiece, or SentencePiece) and a different vocabulary size, so the same text produces different token boundaries and Token IDs.

What do [CLS] and [SEP] mean in BERT and MiniLM?

[CLS] is prepended to the start of a sequence as an aggregate classification/pooling token, and [SEP] marks the end of a sequence or separates two input segments.

Can I copy the generated Token IDs for debugging or tests?

Yes. Click Copy IDs in the Token IDs panel to copy the integer sequence as a JSON array (such as [101, 2026, 4937, 102]) for unit tests, notebooks, or ONNX inputs.

Why do different colors appear on adjacent tokens?

Rotating colors show exact subword boundaries, including merged spaces and punctuation. Hovering or tapping any token highlights its corresponding Token ID.

Is my prompt text sent to any server?

No. Tokenization runs locally in your browser using Transformers.js and cached local tokenizer files, so your text and Token IDs never leave your device.