https://huggingface.co/spaces/schogini/llm-token-explorer
📢 "Hello and welcome! I'm [Your Name], and in this video, we're going to take a deep dive into how input text — something as simple as a sentence — is transformed into numerical tensors that a transformer model can actually work with. This is the very first stage of how powerful language models like GPT and BERT operate. Let's walk through each transformation stage, using a live visualizer to really see what's happening under the hood."
🧠 "The first thing we do is tokenize the input text. Tokenization means breaking your sentence into smaller pieces — called tokens. These tokens could be words, subwords, or even single characters, depending on the tokenizer being used.
For example, the sentence:
'Transformers are amazing!'Might be split into:
['Transform', 'ers', ' are', ' amazing', '!']Each token is then mapped to a unique number — its Token ID — based on a vocabulary.
In the visualizer, we show:
- 🔸 Token IDs — the numbers that represent each token
- 🔸 Decoded Tokens — to confirm the tokenizer’s behavior
- 🔸 And a 📊 bar chart to see token ID distribution visually.
This is the very first numerical transformation of your input!"
🧠 "Next comes the embedding stage. Token IDs are just numbers, but they have no meaning on their own. So we pass each token ID through an embedding layer — like a giant lookup table — to get a high-dimensional vector that captures the token’s semantic meaning.
In our demo, we use OpenAI’s
text-embedding-ada-002model to fetch real token embeddings.Each token now becomes a vector — typically with 1536 dimensions. These vectors help the model understand relationships between tokens: Words with similar meanings will have similar vectors.
The visualizer shows:
- The full vector for each token
- A 🌈 heatmap of its values
- And a 🧭 2D PCA plot to visualize all tokens in semantic space
Embeddings are the first real layer of understanding."
🧠 "Now here's a catch — transformers don’t inherently understand order. The word ‘amazing’ and ‘Transformers’ are just embeddings. There's no clue that one came before the other.
To fix that, we add something called a positional encoding tensor. It’s a mathematical signal — often sinusoidal — added to each token's embedding, based on its position in the sequence.
This lets the transformer know that:
- ‘Transformers’ is token 1
- ‘are’ is token 2
- and so on...
In the visualizer:
- We show the entire positional encoding matrix
- A 🔬 heatmap to help understand how these patterns look
So now we have embeddings with position awareness."
🧠 "Here's where the magic happens. We take the embedding vector and add the positional encoding to it. This gives us the final input tensor — one vector for each token that includes both its meaning and its position.
This tensor is now ready to be fed into the multi-head self-attention layers of the transformer.
The visualizer shows:
- The combined matrix
- A final 🎨 heatmap — the actual numbers that feed into the model
From this point on, the transformer can now compare all tokens to all others using dot products, build contextual relationships, and make sense of your sentence."
🧠 "Let’s quickly recap the journey of a sentence through this pre-transformer pipeline:
- Tokenization – break input into small units and assign IDs
- Embedding – turn those IDs into meaningful vectors
- Positional Encoding – add sequence information
- Final Tensor – the actual input the transformer consumes
Each stage is crucial — without tokenization, we can’t break down input. Without embeddings, the model has no meaning. Without position, it has no sense of order. And without the final tensor, the transformer has nothing to attend to."
📢 "I hope this visual journey made the transformation process crystal clear for you. These are the building blocks of how LLMs work — the foundation for attention, context, and generation.
Keep exploring. If you'd like to try this yourself, the full code is open and deployable on Hugging Face Spaces.
I'm [Your Name], and I'll see you in the next AI deep dive!"