CBOW Model › Architecture: Context Averaging

Michael BrenndoerferApril 3, 20255 min read
Language AI HandbookAll chapters
Part 4 of 67Word Embeddings
Chapter 20CBOW Model › Architecture: Context Averaging
Reading section 3 of 15 · Architecture: Context Averaging · 5 minSection 3 of 15 · 5 min

Book contents

Section 3 of 15 · 5 min read

CBOW Model › Architecture: Context AveragingOne section · Sections in this chapter3 / 15 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

CBOW shares its overall structure with Skip-gram but adds a critical averaging step between the embedding lookup and the output layer. Understanding this step is essential to understanding both what CBOW can learn and why it makes the design choices it does.

The architecture has three components: an input embedding matrix, a context averaging operation, and an output projection matrix. These three pieces work in sequence to convert a set of context word identifiers into a probability distribution over the vocabulary, and backpropagation through this sequence adjusts the parameters so that the correct center word receives the highest probability.

Out[7]:
Visualization
Diagram of CBOW neural network showing context word inputs, embedding lookup, averaging, and output softmax over vocabulary.
CBOW architecture showing the flow from context words through embedding lookup, averaging, output projection, and softmax. Each context word retrieves its row from the embedding matrix W. These rows are averaged to form the hidden representation h-bar. The output matrix W-prime projects this vector to vocabulary-sized scores, and softmax converts them to probabilities. Training maximizes the probability of the true center word.

The two weight matrices in CBOW mirror those in Skip-gram:

  • Embedding matrix W\mathbf{W} (size V×dV \times d): Each row is the dd-dimensional embedding for one vocabulary word. When CBOW receives context words, it looks up each context word's row and averages them.
  • Output matrix W′\mathbf{W}' (size d×Vd \times V): Each column corresponds to a vocabulary word's "context representation." This matrix converts the averaged embedding into a score vector over the full vocabulary.

These two matrices serve distinct roles during training even though both are learned simultaneously. The embedding matrix W\mathbf{W} is the primary product: these are the word vectors you use after training. The output matrix W′\mathbf{W}' is more of a scaffolding: it provides the contrastive signal needed to push word embeddings apart during training. Some practitioners use W′\mathbf{W}' as an alternative embedding matrix (averaging the two is sometimes beneficial), but in most applications only W\mathbf{W} is retained.

Why Not Use a Nonlinear Hidden Layer?

You might wonder why CBOW has no activation function between the embedding lookup and the output layer. Skip-gram also omits nonlinearities. This is a deliberate choice, and it carries practical effects.

Nonlinearities like ReLU or sigmoid introduce computational cost and complicate backpropagation. More importantly, they change the geometry of the embedding space. A linear architecture means the learned embeddings live in a space where vector arithmetic is meaningful. The famous Word2Vec property that king - man + woman = queen holds precisely because the embedding space is linear. Adding a nonlinearity would destroy this arithmetic structure.

There is also a theoretical argument from information theory. The task of predicting a word from its context is a self-supervised objective that forces the model to compress distributional information into a fixed-size vector. The compression happens through the bottleneck of the embedding dimension dd, not through a nonlinearity. As long as dd is much smaller than VV, the model must find a compact representation of the word's distributional properties, and that representation turns out to be geometrically meaningful.