liveBook · Manning

Softmax

As explained in Optimization Algorithms: AI techniques for design, planning, and control problems

Softmax is a function that converts a vector of real-valued scores into nonnegative class probabilities that sum to one.

Softmax turns a set of raw scores into nonnegative probabilities that sum to one. In a neural-network classifier, the final layer produces one score, or logit, per class. Softmax makes those scores usable as a probability distribution for evaluating predictions. section 9.7

For each input, the forward pass:

  • Computes the class logits from the network’s weights and biases. section 9.7
  • Exponentiates the logits and divides each result by the sum across classes: `probs = exp_scores / np.sum(exp_scores, axis=1, keepdims=True)`. section 9.7
  • Uses the predicted probability of the true class to calculate negative log-likelihood loss. section 9.7

Attention over graph neighbors

A graph attention network assigns raw attention scores to a node’s neighbors. Softmax normalizes those scores into comparable attention coefficients within the neighborhood. After multi-head attention, a final softmax may also turn classification outputs into probabilities. section 11.3.2

Choosing the next convex-hull point

A pointer network produces a softmax distribution over the points in its input sequence. At each step, that distribution assigns a probability to each candidate point, supporting the choice of which point to add next to the convex hull. The number of candidates follows the input length. section 11.9

def forward_prop(params):
  
    logits = logits_function(params)                                  #1
  
    exp_scores = np.exp(logits)                                       #2
    probs = exp_scores / np.sum(exp_scores, axis=1, keepdims=True)    #2
  
    correct_logprobs = -np.log(probs[range(num_samples), y])          #3
    loss = np.sum(correct_logprobs) / num_samples                     #4
  
    return loss                                                       #4

Inspect the NumPy forward pass to see where logits become probabilities and where those probabilities enter the loss calculation. section 9.7

How Optimization Algorithms: AI techniques for design, planning, and control problems covers it

How deep it goes
Shows explicit NumPy normalization in a forward pass and describes attention uses, but does not derive the function mathematically.
Examples
Uses penguin-species classification, graph-neighbor attention, and point selection for a convex hull.
What it assumes
Builds on neural-network scores and attention scores while introducing neuron inputs, weights, and biases before the classifier implementation.
What you can do after
Apply it via NumPy to convert class logits into probabilities for a neural-network loss calculation.
How it connects
Links softmax to neural-network logits, negative log-likelihood, graph attention networks, multi-head attention, and pointer networks.

Also explained in

Compare how 17 books explain softmax →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Optimization Algorithms: AI techniques for design, planning, and control problems. The section links point to the parts of the book it draws on.