# Stanford CME295 Transformers & LLMs | Autumn 2026 | Lecture 2 - Large Language Models

**URL:** <https://www.artofsm.art/t/stanford-cme295-transformers-llms-autumn-2026-lecture-2-large-language-models/25396>\
**Category:** Content Creators\
**Tags:** stanford-online, machine-learning, transformers\
**Created:** [9 October 2026 21:32 UTC](https://www.artofsm.art/t/stanford-cme295-transformers-llms-autumn-2026-lecture-2-large-language-models/25396 "2026-10-09T21:32:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![artesia](https://www.artofsm.art/user_avatar/www.artofsm.art/artesia/32/36_2.png) [@artesia](https://www.artofsm.art/u/artesia)\
**Post date:** [9 October 2026 21:32 UTC](https://www.artofsm.art/t/stanford-cme295-transformers-llms-autumn-2026-lecture-2-large-language-models/25396/1 "2026-10-09T21:32:13Z")

</div>

[![](https://www.artofsm.art/uploads/default/original/3X/0/e/0e328c9470a0720139294d983375a3a966827a58.jpeg "Stanford CME295 Transformers & LLMs | Autumn 2026 | Lecture 2 - Large Language Models") ](https://www.youtube.com/watch?v=GaIeu3npx04)

The lecture reviews transformer architectures and large language models, covering encoder-only models like BERT, decoder-only models like GPT, scaling laws, and efficient techniques such as mixture of experts and advanced positional encodings. It also discusses improvements in attention mechanisms, normalization, decoding strategies, and prompting methods that enhance model performance and usability without additional training.

---

<div class="post-metadata">

**Author:** ![artesia](https://www.artofsm.art/user_avatar/www.artofsm.art/artesia/32/36_2.png) [@artesia](https://www.artofsm.art/u/artesia)\
**Post date:** [9 October 2026 21:56 UTC](https://www.artofsm.art/t/stanford-cme295-transformers-llms-autumn-2026-lecture-2-large-language-models/25396/3 "2026-10-09T21:56:13Z")

</div>

The lecture begins with a recap of the transformer architecture introduced in the previous session, focusing on how models process text by converting it into tokens and embeddings. The original transformer consists of an encoder and a decoder, designed for machine translation tasks. Variants of this architecture include encoder-only models like BERT, which use bidirectional self-attention to generate meaningful embeddings for downstream tasks through pre-training on proxy tasks such as masked language modeling and next sentence prediction. BERT requires fine-tuning for specific tasks but excels in understanding context within text.

Another variant discussed is the decoder-only transformer, exemplified by GPT models, which generate text autoregressively by predicting the next token based on previous tokens. Unlike encoder-decoder models, decoder-only models use causal attention, where tokens attend only to themselves and preceding tokens, making them more general and simpler for text generation tasks. These models often do not require fine-tuning and can adapt to various tasks by framing them as text-to-text problems. The lecture also highlights scaling laws showing that larger models trained on more data perform better and are more token-efficient, though compute constraints necessitate balancing model size and training data.

To address the computational cost of large models, the lecture introduces mixture of experts (MoE) architectures, which activate only a subset of specialized experts for each input token, reducing inference costs while allowing model scaling. Sparse MoE models select a few experts per token via a learned router, but training challenges like routing collapse—where only a few experts dominate—are mitigated by auxiliary loss functions encouraging balanced expert utilization. Modern MoE-based LLMs often include hundreds of experts with some shared components, enabling fine-grained specialization and improved performance.

The lecture then delves into positional encoding methods, contrasting the original transformer’s additive learned or sinusoidal embeddings with modern approaches like rotary position embeddings (RoPE). RoPE applies rotations to query and key vectors in the attention mechanism, encoding relative positional information more effectively and generalizing to longer sequences. Additionally, attention mechanisms have evolved to include local or sliding window attention to reduce computational load, and techniques like group query attention (GQA) optimize memory usage by sharing projection matrices across attention heads. Normalization strategies have also shifted from post-layer normalization to pre-layer normalization and from layer norm to RMS norm for better training stability.

Finally, the lecture covers decoding strategies in LLMs, emphasizing the trade-offs between deterministic methods like greedy decoding and beam search versus stochastic sampling approaches that introduce variability and more human-like responses. Temperature scaling is explained as a way to control the randomness of token selection. Practical considerations such as batch invariance affecting determinism and guided decoding for structured outputs like JSON are discussed. The session concludes with an introduction to prompting techniques, including in-context learning and chain-of-thought prompting, which improve model reasoning and performance without changing model weights, highlighting ongoing advances in leveraging LLMs effectively.

## Useful Links

- [Attention Is All You Need (Vaswani et al., 2017)](https://arxiv.org/abs/1706.03762) — Central to understanding the transformer architecture and its attention mechanism.
- [BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding (Devlin et al., 2018)](https://aclanthology.org/N19-1423/) — Central to understanding encoder-only transformer variants and pre-training methods.
- [GPT: Improving Language Understanding by Generative Pre-Training (Radford et al., 2018)](https://cdn.openai.com/research-covers/language-unsupervised/language_understanding_paper.pdf) — Central to understanding decoder-only transformer models and autoregressive text generation.
- [Scaling Laws for Neural Language Models (Kaplan et al., 2020)](https://arxiv.org/abs/2001.08361) — Important for understanding scaling behavior of large language models.
- [Training Compute-Optimal Large Language Models (Hoffmann et al., 2022)](https://arxiv.org/abs/2203.15556) — Central to understanding compute budget trade-offs in LLM training.
