liveBook · Manning

One-hot encoding

As explained in Graph Neural Networks in Action

A representation technique that encodes a categorical value as a vector with one active entry and all other entries inactive.

One-hot encoding represents each category with a vector containing one active entry and inactive entries elsewhere. In graph encoders, it records which receiving node each directed edge targets. section 6.4.1

A practical edge-to-node aggregation pipeline is:

  • Create one category position for every node and mark each edge's receiving-node position. section 6.4.1
  • Transpose the encoding so its shape becomes number of nodes by number of edges. section 6.4.1
  • Multiply the fixed matrix by edge embeddings to aggregate incoming messages into node embeddings, then normalize by possible nodes. section 6.4.1

Three-node fully connected graph

Six directed edges connect every node to the other two. The one-hot incoming-edge matrix marks each edge's destination, allowing edge embeddings to become three node embeddings.

How Graph Neural Networks in Action covers it

How deep it goes
Explains destination indicators, transposition, tensor shapes, multiplication, and normalization, but defers general encoding strategies.
Examples
Uses a fully connected three-node graph, six directed edges, destination indicators, and PyTorch tensor indices.
What it assumes
Assumes adjacency matrices, directed edges, embeddings, and message passing; teaches the encoding matrix construction explicitly.
What you can do after
Apply it via PyTorch to convert directed-edge embeddings into aggregated node embeddings.
How it connects
Connects one-hot encoding with adjacency matrices, directed edges, edge embeddings, node embeddings, and message passing.

Also explained in

Compare how 6 books explain one-hot encoding →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Graph Neural Networks in Action. The section links point to the parts of the book it draws on.