Skip to content
eBook Charts
CA
Thinking in Tokens

Thinking in Tokens

Ganapathy Lakshmanaperumal

$17.99

Buy on Amazon View on Apple Books

Prefer it in print? See every format on Amazon →

Price on Apple Books. Amazon’s price may differ.

Read a lot? Try Kindle+ * · Compare subscriptions

Published
Genres
Computers & Internet

Description

Every prompt, reply, price and context limit in a large language model is measured in tokens, yet few engineers know what a token is or why it behaves the way it does. Thinking in Tokens explains the unit that language models actually consume, from Unicode bytes to invoices. You will build a byte pair encoding tokenizer from scratch, compare WordPiece, Unigram and SentencePiece, and see how pre-tokenization, vocabulary size and chat templates shape every request. The book shows why numbers, identifiers, code and emoji tokenize badly, measures the token tax that makes many languages cost more, and explains embeddings, rotary positions and context window extension. It covers effective versus advertised context, prefill and decode, KV cache memory, latency, streaming, sampling, reasoning tokens and constrained decoding. Worked cost models cover input, output and cached pricing, prompt caching break-even and batch discounts, followed by context engineering for retrieval and agents and token-level security against glitch tokens, invisible characters and special-token injection. A multilingual customer-support platform serves as the running example throughout, with Python sketches, checklists, a hands-on lab and review questions. This book is an independent publication and is not authorized, sponsored or endorsed by any company whose products it mentions. All trademarks belong to their respective owners and are used only for identification. This book was drafted with generative AI tools and checked with automated tools. Tools, features and prices change often; confirm them in current documentation.