ladderlore
  • Type a service name, like S3 or IAM.

Concept · Builds on AIF-C01

Text pre-processing and tokenization

Clean text, pick stemming or lemmatization, choose word or subword tokens, and augment domain text.

You know from AI Practitioner

  • A token is a small piece of text that a model reads.
  • The context window limits how many tokens fit in one request.
  • Text must be turned into numbers before a model uses it.
Read the AI Practitioner lesson
  • Cleaning

    What it does
    Removes noise
    Example
    Strip HTML, fix spaces
  • Stop words

    What it does
    Drops common words
    Example
    the, of, and
  • Stemming

    What it does
    Chops to a rough root
    Example
    running to run
  • Lemmatization

    What it does
    Finds the base form
    Example
    better to good
Four text clean-up techniques.
  • Word

    Example
    unhappiness
    Unknown words
    Often unknown
  • Subword (BPE)

    Example
    un, happi, ness
    Unknown words
    Rare
  • Character

    Example
    u, n, h, a
    Unknown words
    None, but long input
Three token types and how they handle unseen words.

What it is

Cleaning removes noise: HTML tags, stray characters and extra spaces, mixed encodings and duplicate lines. Lowercasing and Unicode normalization make equal words look equal. Stop words are very common words such as the and of. Classic models, such as TF-IDF with a classifier, often drop them. Large language models need them, because they carry grammar and meaning.

What it is

Stemming cuts words to a crude root by rules: running becomes run, but studies may become studi. It is fast. Lemmatization uses a dictionary and the word class to find the real base form: better becomes good. It is slower and more accurate. Word tokens split text on spaces, so a word that was not in the training vocabulary maps to an unknown token and its meaning is lost. Subword methods, byte-pair encoding (BPE) and WordPiece, split rare words into known pieces, such as un, happi and ness, so unknown words are rare. Large language models use subword tokens. The vocabulary is the fixed list of tokens, and its size trades memory against sequence length.

What it is

Domain-specific augmentation adds training text when data is scarce. Replace words with synonyms. Back-translation translates text to another language and back, for example with Amazon Translate, to get a paraphrase. Use templates to fill slots in sentences, or ask a foundation model to paraphrase. Check that labels stay correct after augmentation.

Remember

  • Clean HTML, spaces and encodings. Normalize case and Unicode.
  • Drop stop words for TF-IDF style models, not for LLMs.
  • Stemming: fast rule-based root. Lemmatization: dictionary base form, more accurate.
  • Word tokens create unknown tokens. Subword tokens (BPE, WordPiece) rarely do.

Remember

  • Augment domain text with synonyms, back-translation, templates or paraphrase.

On the exam

  • “Rare medical terms become unknown tokens” points to a subword tokenizer such as BPE or WordPiece.
  • “Accurate base forms, speed is secondary” points to lemmatization.
  • “Few labeled sentences, add paraphrases” points to back-translation or synonym replacement.