Hierarchical Softmax › The Training Objective

Michael BrenndoerferUpdated February 8, 20262 min read
Language AI HandbookAll chapters
Part 4 of 67Word Embeddings
Chapter 22Hierarchical Softmax › The Training Objective
Reading section 6 of 16 · The Training Objective · 2 minSection 6 of 16 · 2 min

Book contents

Section 6 of 16 · 2 min read

Hierarchical Softmax › The Training ObjectiveOne section · Sections in this chapter6 / 16 ↓
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

The hierarchical softmax objective follows directly from maximum likelihood. We want to maximize the probability of the observed (center, context) pairs in the training corpus. Taking the log converts products into sums, which is numerically more stable and mathematically easier to differentiate:

L=∑(wc,wo)∈corpuslog⁡P(wo∣hwc)\mathcal{L} = \sum_{(w_c, w_o) \in \text{corpus}} \log P(w_o | \mathbf{h}_{w_c})

where:

  • wcw_c: the center word
  • wow_o: the observed context word
  • hwc\mathbf{h}_{w_c}: the input embedding of center word wcw_c
  • P(wo∣hwc)P(w_o | \mathbf{h}_{w_c}): computed as the product of path probabilities

Substituting the path probability formula and applying the logarithm:

log⁡P(wo∣h)=∑j=1L(wo)−1log⁡σ ⁣(dj⋅vn(wo,j)⋅h)\log P(w_o | \mathbf{h}) = \sum_{j=1}^{L(w_o)-1} \log \sigma\!\left( d_j \cdot \mathbf{v}_{n(w_o, j)} \cdot \mathbf{h} \right)

where:

  • log⁡P(wo∣h)\log P(w_o | \mathbf{h}): log-probability of context word wow_o
  • djd_j: direction code at step jj along the path to wow_o
  • vn(wo,j)\mathbf{v}_{n(w_o, j)}: the learned node vector at step jj

The product of probabilities becomes a sum of log-probabilities, which eliminates the risk of underflow for long paths. Converting the maximization to minimization (for gradient descent), we minimize the negative log-likelihood:

J=−∑j=1L(wo)−1log⁡σ ⁣(dj⋅vn(wo,j)⋅h)\mathcal{J} = -\sum_{j=1}^{L(w_o)-1} \log \sigma\!\left( d_j \cdot \mathbf{v}_{n(w_o, j)} \cdot \mathbf{h} \right)

This loss has a pleasant interpretation that makes the training dynamics intuitive. Each term −log⁡σ(dj⋅vj⋅h)-\log \sigma(d_j \cdot \mathbf{v}_j \cdot \mathbf{h}) is the binary cross-entropy loss for a single binary classifier at node jj. The "correct label" at each node is determined by the direction djd_j: if we should go left, the correct output is σ>0.5\sigma > 0.5, which corresponds to a positive dot product. If we should go right, the correct output is σ<0.5\sigma < 0.5, corresponding to a negative dot product. The loss penalizes the model whenever any of these binary classifiers makes a wrong or uncertain decision.

Training pushes the model to make each binary decision more confidently correct. Concretely, for each node on the path to the target word, the node vector vj\mathbf{v}_j and the context embedding h\mathbf{h} are adjusted so that their dot product has the correct sign and magnitude. After sufficient training, the model should be able to traverse the tree decisively, assigning high probability to each correct turn and arriving at the target leaf with high confidence.