What the heck is LLM
Chapter 2 — Working with Text Data

Chapter 2 — Working with Text Data

How raw text becomes tokens, token IDs, and embedding vectors — the entire preparation pipeline that feeds an LLM.

Before an LLM can do anything interesting, raw text has to be turned into numbers it can actually crunch. Chapter 2 is the gap between "I have a text file" and "I have a tensor ready to feed into the model". It's the necessary bridge between the bird's-eye view from Chapter 1 and the actual PyTorch code we'll write in Chapter 3.

What you'll learn

By the end of this chapter you'll be able to answer, in plain language:

  • Why neural networks can't read text directly and why we need embeddings.
  • How to tokenize text into words and punctuation that the model can work with.
  • How tokens are converted into integer token IDs via a vocabulary.
  • The role of special tokens like <|unk|> and <|endoftext|>.
  • What byte pair encoding (BPE) is and why GPT-style LLMs use it.
  • How to build input-target pairs for next-word prediction using a sliding window.
  • How token IDs become embedding vectors the model can train on.
  • How positional embeddings teach the model about word order.

Chapter contents

A heads-up: this chapter is mostly mechanical — text in → tokens out → numbers out. The interesting learning arrives in the next chapter, where we wire those numbers into a model that actually pays attention to them.

On this page