liveBook · Manning

Categorical encoding

Categorical encoding transforms discrete category values into numerical representations, such as separate binary indicators or vectors with one active position per category.

How 13 Manning books explain it

Natural Language Processing in Action, Second Edition

A one-hot encoder is a component that maps categorical items to binary vectors with one active position per item.

How it is used
Represents token sequences numerically for NLP pipelines and connects vocabulary items to neural-network training.
How deep it goes
Works through vocabulary-indexed vector construction and sequence preservation, then discusses sparsity and limitations for comparing meaning.
Examples
Uses an 18-token, 15-word-vocabulary matrix and WikiText2 skip-gram pairs to illustrate encoding.
What you can do after
Builds one-hot token vectors from scratch and checks vocabulary ordering when reusing a model.

Read how Natural Language Processing in Action, Second Edition explains categorical encoding →

Deep Learning with PyTorch, Second Edition

An encoding in which exactly one position is set to indicate a category and all others are zero.

How it is used
Represents categorical features, text items, and classification targets as tensors.
How deep it goes
Explains category-to-index mapping and tensor construction, including scattering, concatenation, and vocabulary-size limitations.
Examples
Uses wine scores, weather levels, characters, words, and bird-versus-airplane classes.
What you can do after
Apply it via PyTorch to construct one-hot tensors and append encoded features to a dataset.

Read how Deep Learning with PyTorch, Second Edition explains categorical encoding →

Learn Generative AI with PyTorch

A vector representation with a single active entry used here to encode token or position identities before projection.

How it is used
Prepares categorical identities as numerical inputs for number generation, conditional images, text, and music.
How deep it goes
Defines vector construction and decoding, then works through batch inputs, label concatenation, and image-channel preparation.
Examples
Uses integers from 0 to 99, eyeglasses labels, word tokens, and 84-value musical pitch vectors.
What you can do after
Apply it via PyTorch to encode categories, decode vectors with argmax, and attach labels to model inputs.

Read how Learn Generative AI with PyTorch explains categorical encoding →

Grokking Machine Learning

A data-encoding technique that represents each category of a categorical feature with a separate binary indicator feature.

How it is used
Converts categorical data into numerical features for machine-learning models and binary questions in decision trees.
How deep it goes
Defines one indicator column per category and explains why numeric labels can imply an unwanted order.
Examples
Uses dog, cat, and bird indicators, plus passenger-data features such as sex and embarkation port.
What you can do after
Apply it with Pandas `get_dummies` to turn categorical columns into numerical indicator columns.

Read how Grokking Machine Learning explains categorical encoding →

Math and Architectures of Deep Learning

A vector with exactly one element equal to 1 and all others equal to 0, used here to encode the correct class.

How it is used
Encodes categorical outcomes and supplies classifier ground truth for cross-entropy training.
How deep it goes
Defines the vector, derives its probability role, and connects it to cross-entropy and PyTorch code.
Examples
Uses cat, dog, airplane, and automobile labels, numeric prediction vectors, loss values, and PyTorch listings.
What you can do after
Apply it via PyTorch to represent class targets and compute categorical or softmax cross-entropy loss.

Read how Math and Architectures of Deep Learning explains categorical encoding →

Grokking AI Algorithms, Second Edition

One-hot encoding represents each category by a separate binary indicator, with one indicator active for each example.

How it is used
Uses one-hot encoding to prepare categorical data for statistical models and neural-network inputs.
How deep it goes
Explains indicator construction, contrasts label encoding, and discusses input-size trade-offs without providing an implementation.
Examples
Works through diamond cut and origin categories, plus empty, vehicle, pedestrian, and goal grid states.
What you can do after
Evaluate how one-hot encoding represents unordered categories without imposing a numeric ranking.

Read how Grokking AI Algorithms, Second Edition explains categorical encoding →

Ensemble Methods for Machine Learning

Categorical encoding is the transformation of categorical feature values into numerical representations suitable for machine-learning models.

How it is used
Prepares categorical features for machine-learning algorithms that require numeric inputs.
How deep it goes
Explains ordinal and one-hot representations, demonstrates encoded matrices, and connects them to reusable preprocessing pipelines.
Examples
Uses color, size, Adult income data, missing workclass values, and scikit-learn encoded matrices.
What you can do after
Apply encoding via scikit-learn pipelines and compare encoders within ensemble-model evaluation.

Read how Ensemble Methods for Machine Learning explains categorical encoding →

Machine Learning System Design

One-hot encoding is a representation technique that converts a categorical value into a vector with one active indicator for its category.

How it is used
Uses one-hot encoding as basic feature engineering within model training and inference pipelines.
How deep it goes
Compares encoding methods and flags leakage risk, but does not detail vector construction or implementation steps.
Examples
Uses logistic regression preprocessing and Uber’s DeepETA pipeline as concrete examples.
What you can do after
Apply it within a model pipeline and select alternatives while avoiding target leakage.

Read how Machine Learning System Design explains categorical encoding →

The Art of AI Product Development

One-hot encoding represents each item in a categorical set as a vector with one active element and all other elements zero.

How it is used
Represents categorical data numerically before feeding it into an AI model.
How deep it goes
Defines the vector representation and its information loss, then defers richer word representations to word embeddings.
Examples
Uses words represented as zero vectors with one active element and illustrates the mapping in Figure 3.4.
What you can do after
Apply it to represent categorical items numerically while recognizing its coarse treatment of information.

Read how The Art of AI Product Development explains categorical encoding →

Outlier Detection in Python

Categorical encoding is the transformation of categorical values into numerical representations suitable for computational analysis.

How it is used
Prepares categorical features for numeric outlier detectors and other methods requiring strictly numeric predictors.
How deep it goes
Defines ordinal, count, and one-hot methods with concrete mappings, but defers fuller method discussion.
Examples
Uses color mappings and baseball position indicators to demonstrate ordinal, count, and one-hot representations.
What you can do after
Apply it via pandas get_dummies to convert categorical dataframe columns into binary features.

Read how Outlier Detection in Python explains categorical encoding →

Machine Learning Platform Engineering

One-hot encoding is a technique that represents each value of a categorical variable with a separate binary indicator feature.

How it is used
Prepares categorical features and binary targets for model training, inference, experiment tracking, reproducibility, and debugging.
How deep it goes
Explains implementation through encoder settings, dummy generation, column persistence, and train-test splitting, but defers encoding theory.
Examples
Uses an income-classification dataset with categorical features and <=50K or >50K target labels.
What you can do after
Builds an encoded train-test dataset and preserves feature columns for later inference.

Read how Machine Learning Platform Engineering explains categorical encoding →

Deep Learning with Python, Third Edition

A representation scheme where one position is 1 and all others are 0 to encode a discrete category or symbol.

How it is used
Represents categorical labels and token IDs as numeric inputs for classification and recurrent neural-network models.
How deep it goes
Defines the representation, implements it with NumPy and Keras, and demonstrates its dimensional cost before deferring to word embeddings.
Examples
Uses 46-class label vectors, 30,000-word token vectors, NumPy and Keras implementations, and a bidirectional LSTM sequence model.
What you can do after
Build one-hot labels or token inputs with NumPy or Keras and select a compatible categorical loss.

Read how Deep Learning with Python, Third Edition explains categorical encoding →

Build a Text-to-Image Generator (from Scratch)

A one-hot tensor represents each categorical value with a vector containing one active entry and zeros elsewhere.

How it is used
Conditions diffusion-model image generation on discrete class labels.
How deep it goes
Implements conversion, masking, embedding, and output shapes, stopping short of encoding theory.
Examples
Uses clothing labels 2, 9, and 0 across ten classes, producing 512- and 256-channel embedding tensors.
What you can do after
Builds one-hot label conditioning with PyTorch embedding blocks and configurable context masking.

Read how Build a Text-to-Image Generator (from Scratch) explains categorical encoding →

Also covered in

What to know first

Related concepts

Questions about categorical encoding

What is categorical encoding?

Categorical encoding transforms discrete category values into numerical representations, such as separate binary indicators or vectors with one active position per category.

Which Manning books explain categorical encoding?

Natural Language Processing in Action, Second Edition, Deep Learning with PyTorch, Second Edition, Learn Generative AI with PyTorch, Grokking Machine Learning, Math and Architectures of Deep Learning, Grokking AI Algorithms, Second Edition, Ensemble Methods for Machine Learning, Machine Learning System Design and 5 more.

What should I know before learning categorical encoding?

Manning books that teach categorical encoding usually introduce language model, categorical data, classifier and embedding first.

What is the difference between categorical encoding and embedding?

Categorical encoding transforms discrete category values into numerical representations, such as separate binary indicators or vectors with one active position per category. An embedding is a numerical vector representation of an item in a feature space, encoding selected properties or relationships for computational tasks such as comparison or retrieval.

What kinds of categorical encoding are there?

Kinds of categorical encoding include label encoding and one-hot encoding.

What is categorical encoding a kind of?

Categorical encoding is a kind of encoding. Encoding is the process or scheme of mapping information into a different representation according to defined rules for storage, processing, transmission, or interpretation.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.