Chapter 2

Text as Data

Corpora, documents, sentences, normalization, punctuation, splits, and leakage in language tasks.

What this chapter does

Raw text becomes a dataset only after choices about boundaries, cleanup, splitting, and leakage are made visible.

Lessons

Read these in order.

Start with the chapter introduction, then move through the topic lessons. The order is chosen so each page can reuse ideas from the pages before it.

  1. 01
    Introduction

    Why text preparation is part of the modeling problem, not clerical cleanup.

  2. 02
    Corpus, Document, and Sentence

    The basic units used to turn raw text into a language-modeling dataset.

  3. 03
    Normalization, Whitespace, and Punctuation

    Small cleanup choices that can change token counts and model behavior.

  4. 04
    Character Versus Word Views

    Two simple ways to read text as a sequence, and what each view makes easy or hard.

  5. 05
    Train, Validation, and Test Text

    Splitting text so evaluation measures prediction instead of memorized future evidence.

  6. 06
    Leakage in Language Tasks

    How repeated text, future context, and preprocessing mistakes can make a model look better than it is.

Before moving on

  • Build and inspect a tiny corpus.
  • Explain why preparation choices change the task.
  • Split text without leaking future evidence.

Where this leads

  • Unicode and Text Normalization
  • Tokens and Vocabularies

Chapter progress