Byte-Pair Encoding (BPE) Tokenisation
BPE builds a vocabulary of subword units by repeatedly merging the most frequent pair, so rare words are represented by smaller pieces without “unknown” tokens.…
Read the lessonEight generative-AI labs: architectures, text, image, video, 3D, synthetic data, multimodal, and training and evaluation, with simulators that run in your browser, a learning path and a specialised assistant.
From tokens and transformers to decoding strategies and alignment: how a language model generates text.
Large language models treat text as tokens produced by a tokenisation algorithm such as byte-pair encoding (BPE), and estimate the next-token distribution p(x_t|x_{<t}) with a Transformer. Generation behaviour after training is set by the decoding strategy: greedy, beam search, and sampling with temperature, top-k or top-p (nucleus). Alignment with instructions and human feedback is then applied to improve helpfulness and safety.
The lab explains these stages and lets you try tokenisation and decoding on a tiny educational n-gram model, and attention maps on synthetic data. These simulators do not represent the behaviour of a real language model trained on massive text.
BPE builds a vocabulary of subword units by repeatedly merging the most frequent pair, so rare words are represented by smaller pieces without “unknown” tokens.…
Read the lessonAfter computing the next-token distribution we need a rule to pick the token: greedy takes the most likely, beam search tracks several sequences, and sampling with temperature, top-k or top-…
Read the lessonA pre-trained model predicts the next text and does not necessarily follow instructions. Helpfulness and safety are improved by tuning on instruction examples and then training on human pref…
Read the lessonDeterministic embeddings from a token hash with sinusoidal positions and fixed random projections.…
Read the lessonAn n-gram model built from a few sentences; it is not a real language model.…
Read the lessonThe original character-level BPE algorithm.…
Read the lesson| Algorithm | Lab | Covered here | Note |
|---|---|---|---|
| Transformer | Text Generation | Computed in the browser | Attention maps on synthetic data. |
| BPE | Text Generation | Computed in the browser | Training and tokenising in the browser. |
| Decoding (greedy/beam/sampling) | Text Generation | Computed in the browser | A tiny n-gram model. |
| RLHF | Text Generation | Explained only | Explained only: alignment. |
p_i=\frac{\exp(z_i/T)}{\sum_j \exp(z_j/T)}As T→0 it approaches greedy decoding; as T→∞ it approaches the uniform distribution.
\mathrm{Attention}(Q,K,V)=\mathrm{softmax}\!\left(\frac{QK^{\top}}{\sqrt{d_k}}\right)VDividing by √d_k prevents softmax saturation at large dimensions (Vaswani et al. 2017).
\mathcal{L}=-\frac1T\sum_{t=1}^{T}\log p_\theta(x_t\mid x_{<t})Perplexity is exp(L).
10 questions on this lab, graded on the server. Start the quiz
Ask the assistant about any concept or equation in this lab; it answers from the lab’s content and points you to the matching lesson and experiment.
Open the assistantQuizzes · My progress and saved runs
Sections
No section has this name. Press “Search” to search all site content.
Favourites
My results & certificates
My academy progressMy quiz resultsKids’ progressAcademy certificatesQuiz certificatesStart any lesson or quiz and it will show up here so you can get back to it quickly.
Settings
I am the Generative AI Lab assistant. Ask me about architectures, equations and terms, or ask me to explain your simulator results.
Database mode: answers from the lab content on this site's server, with no external service; your conversation is not stored.
The assistant can make mistakes, so check the attached sources.
Welcome! I am Dr. Alaa Taima, and this is my smart assistant on “Deep Learning in Arabic”. Ask it about any term or topic in artificial intelligence, and it will answer from the site's content with links to the sources.
Enter to send · Shift + Enter for a new line · The assistant can make mistakes, so check the sources.