Language Models from Scratch
- 28Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is the primary philosophy behind the course 'CS 336: Language Models from Scratch'?
28 questions
- 1
What is the primary philosophy behind the course 'CS 336: Language Models from Scratch'?
Model answer
The philosophy is that to truly understand language models, you must build them from scratch, enabling fundamental research by providing a full understanding of the technology.
Explanation
The course emphasizes hands-on building to gain deep technical knowledge, as opposed to just using high-level abstractions like prompting.
- 2
Why is teaching a course on building language models considered important despite the availability of high-level abstractions?
Model answer
Abstractions like prompting are leaky and do not provide a deep understanding needed for fundamental research that requires co-designing data, systems, and models across the stack.
Explanation
The instructor argues that while abstractions enable more productivity, they obscure underlying mechanisms, which is problematic for cutting-edge research.
- 3
What does the 'bitter lesson' refer to in the context of this course?
Model answer
The bitter lesson is not that scale is all that matters, but that algorithms at scale matter: efficiency is crucial, and algorithmic improvements have historically outpaced Moore's law.
Explanation
The instructor clarifies a common misconception, stating that the right interpretation is the combination of algorithms and scale, not scale alone.
- 4
According to the lecture, what is the key question to ask when building a language model given a compute and data budget?
Model answer
The key question is: given a certain compute and data budget, what is the best model one can build? This focuses on maximizing efficiency (accuracy per resources).
Explanation
This frame applies at any scale and guides design decisions to squeeze the most out of available resources.
- 5
How does the fraction of FLOPs spent in attention vs. MLP layers change from small to large models?
Model answer
In small models, attention and MLP FLOPs are roughly comparable, but in large models (e.g., 175B parameters), MLP layers dominate.
Explanation
This illustrates that optimizing attention at small scale may be misdirected for large-scale models, since MLPs become the main cost.
- 6
What is the significance of the 44x algorithmic efficiency improvement from 2012 to 2019 mentioned in the lecture?
Model answer
It shows that algorithmic improvements have been faster than Moore's law, meaning that algorithms are crucial for reducing cost and enabling larger models.
Explanation
This efficiency gain implies that without such improvements, achieving the same accuracy would cost 44 times more.
- 7
What are the three types of knowledge the course aims to impart?
Model answer
The three types are: (1) mechanics of how things work, (2) mindset of squeezing maximum efficiency from hardware and taking scaling seriously, and (3) intuitions about which data and modeling decisions lead to good models (only partially teachable).
Explanation
These categories guide the curriculum: mechanics are taught directly, mindset is instilled through the class approach, and intuitions are developed through hands-on experience.
- 8
Why can the course only partially teach 'intuitions' about data and modeling decisions?
Model answer
Because what works at small scales may not generalize to large scales, and the landscape is still not fully understood.
Explanation
The instructor notes that empirical results sometimes defy explanation, and intuitions are often derived from large-scale experiments that are not feasible in the course.
- 9
What was the role of language models in NLP before the deep learning revolution?
Model answer
They were components of larger systems like machine translation and speech recognition, and Google trained large n-gram models (e.g., 5-gram over 2 trillion tokens) as early as 2007.
Explanation
This historical context shows that while large-scale language modeling existed, it was limited to n-grams without the emergent phenomena of modern neural LMs.
- 10
List at least three key ingredients that were developed before 2020 that contributed to the rise of modern language models.
Model answer
Key ingredients include: neural language models (Bengio 2003), sequence-to-sequence models, the Adam optimizer, attention mechanisms, the Transformer (2017), mixture of experts scaling, and model parallelism techniques.
Explanation
These components were developed over time and converged to enable the current generation of large language models.
- 11
What is the difference between closed models, open-weight models, and open-source models according to the lecture?
Model answer
Closed models (e.g., GPT-4) have no public details. Open-weight models release weights and architectural details but not data. Open-source models release both weights and data, with papers explaining as much as possible.
Explanation
This distinction affects reproducibility and understanding; the course aims to bridge gaps using open-source information and reading between the lines.
- 12
Why is the class considered a 'five-unit' class but with a heavy workload?
Model answer
The workload is equivalent to multiple other CS courses combined; for example, the first assignment alone was reportedly as much work as all five assignments of CS 224N plus the final project.
Explanation
This is a warning to students that the class requires significant time and effort despite being listed as five units.
- 13
What is the recommended strategy for completing assignments in this course?
Model answer
First, implement and verify correctness locally on a laptop using small data. Then, use the provided cluster for benchmarking accuracy and speed, and avoid debugging large models on the cluster.
Explanation
This approach saves compute resources and follows the principle of prototyping with minimal resources before scaling up.
- 14
What are the five units (pillars) of the course?
Model answer
The five units are: Basics (tokenizer, architecture, training), Systems (kernels, parallelism, inference), Scaling Laws, Data (curation, evaluation), and Alignment (SFT, DPO, GRPO).
Explanation
Each unit corresponds to an assignment and covers a critical aspect of building language models from scratch.
- 15
What is the purpose of a tokenizer in language modeling?
Model answer
A tokenizer converts between strings (raw text) and sequences of integers (token IDs), enabling the model to process fixed-dimensional inputs.
Explanation
Tokenization is a necessary preprocessing step that maps text to integers, with each integer representing a token (character, byte, or subword unit).
- 16
What are the problems with character-based tokenization?
Model answer
Problems include: poor compression ratio (each character is one token, leading to long sequences), and inefficient use of vocabulary because rare characters take up slots.
Explanation
Character-based tokenization results in very long sequences, which is computationally expensive for Transformers due to quadratic attention.
- 17
What are the problems with byte-based tokenization?
Model answer
The main problem is long sequences: compression ratio is exactly one byte per token, leading to very long input sequences and inefficient compute.
Explanation
Byte-based tokenization is elegant but impractical because it drastically increases sequence length, making attention expensive.
- 18
What is the problem with word-based tokenization?
Model answer
The vocabulary size is effectively unbounded; rare or unseen words must be mapped to an unknown token (UNK), which causes issues with perplexity calculation and generalization.
Explanation
Word-based tokenization does not handle out-of-vocabulary words well, making it less robust than subword methods.
- 19
What is BPE (Byte Pair Encoding) and where did it originate?
Model answer
BPE is a data compression algorithm from 1994 by Philip Gage, later adapted for NLP (neural machine translation) and then for language modeling via GPT-2.
Explanation
BPE is a simple algorithm that iteratively merges the most frequent pair of adjacent tokens, allowing adaptive vocabulary allocation.
- 20
Describe the high-level steps of the BPE algorithm as used for tokenizer training.
Model answer
- Convert the text to a sequence of bytes (or characters after pre-tokenization). 2. Count all pairs of adjacent tokens. 3. Merge the most frequent pair into a new token. 4. Repeat the merge step until the desired vocabulary size is reached.
Explanation
This iterative merging process builds a vocabulary that represents common substrings as single tokens, improving compression and efficiency.
- 21
In the BPE algorithm, how is the compression ratio affected by the number of merges?
Model answer
As merges are applied, the vocabulary grows and sequences become shorter, improving the compression ratio (more bytes per token).
Explanation
Each merge reduces the number of tokens needed to represent the text, leading to better compression.
- 22
What is the role of pre-tokenization in the GPT-2 BPE tokenizer?
Model answer
Pre-tokenization splits the text into segments using regular expressions (e.g., splitting on spaces and punctuation), and then BPE is applied within each segment.
Explanation
This improves efficiency by preventing BPE merges across word boundaries and reduces the number of merges needed.
- 23
How does the BPE tokenizer encode a new string after training?
Model answer
Encoding applies the learned merges in the order they were learned: start with byte representation, then repeatedly replace each pair that matches a merge with the corresponding token ID.
Explanation
This process is deterministic and ensures that the tokenizer can handle any input string without unknown tokens.
- 24
What is a special token in the context of tokenizers, and give an example?
Model answer
Special tokens are reserved token IDs with specific meanings, such as the end-of-sequence token (<|endoftext|>) used in GPT-2.
Explanation
Special tokens are added to the vocabulary and play roles in formatting and controlling model behavior during training and inference.
- 25
Why might the BPE tokenizer be considered inefficient, and how can it be optimized?
Model answer
The naive implementation loops over all merges for encoding, which is slow. Optimization can include using a priority queue or precomputing merges to only apply relevant ones.
Explanation
The assignment expects students to make the implementation fast, possibly by parallelizing or using efficient data structures.
- 26
What is the compression ratio of the GPT-2 tokenizer?
Model answer
The compression ratio is approximately 1.6 bytes per token (i.e., each token represents about 1.6 bytes of raw text).
Explanation
This is given as an example in the lecture to show typical BPE tokenizer performance.
- 27
In the GPT-2 tokenizer, how is the space character typically handled?
Model answer
The space is usually attached to the preceding word token (i.e., space is part of the token and comes before the word).
Explanation
This is a convention from the pre-tokenization step; it affects how tokens are formed and can cause certain edge cases.
- 28
What is the main reason that tokenization is still used instead of tokenizer-free methods?
Model answer
Current architectures (Transformers) are not efficient when processing raw bytes due to quadratic self-attention; tokenization provides a practical compression that makes training feasible.
Explanation
Tokenizer-free methods are promising but have not yet been scaled to frontier models, so BPE remains the standard.

Ask anything
We've read this whole study set, so questions about it get the best answers.