Split the text into tokens
Text is cut into subword pieces from a fixed vocabulary. BERT-style encoders also add a [CLS] token at the start and a [SEP] token at the end.
- WordPiece
- [CLS]
- [SEP]
Lab / Encoders
An encoder reads a whole input at once and turns it into vectors: one per token, and one for the whole input once those are pooled. This toy uses six readable dimensions instead of hundreds of learned ones, so you can watch the numbers move.
Interactive field guide
Follow a sentence from token lookup, through one layer of context, to a single vector you can compare.
01 / Embeddings
02 / Bidirectional context
03 / Sentence embedding
Field guide
The same pipeline sits behind BERT, sentence-embedding models and the text side of retrieval systems.
Text is cut into subword pieces from a fixed vocabulary. BERT-style encoders also add a [CLS] token at the start and a [SEP] token at the end.
Each token ID selects a learned row of numbers, and a position embedding is added so order is not lost. At this point “bank” has the same vector in every sentence.
Encoder self-attention has no causal mask, so a token can use words on both sides. That is how “bank” can lean towards rivers or money depending on what follows it. A decoder only looks left.
Each layer is attention followed by a small MLP, with residual connections around both. A real encoder stacks 6 to 24 of them; the toy in this tool runs one attention step.
To represent the whole sentence, take the [CLS] output or average the token outputs. Sentence-embedding models are fine-tuned so that this pooled vector places similar meanings close together.
Cosine similarity compares the direction of two vectors and ignores their length. It is the usual score behind semantic search, clustering and retrieval.