Zubnet AIसीखेंWiki › Softmax
मूल सिद्धांत

Softmax

Softmax Function, Normalized Exponentials
एक function जो raw numbers (logits) के एक vector को probability distribution में convert करता है — सभी values positive हो जाती हैं और 1 तक sum होती हैं। Softmax values के बीच differences को amplify करता है: largest input को highest probability मिलती है, और smaller inputs को exponentially smaller probabilities। ये attention mechanisms, classification outputs, और token prediction में appear होता है।

यह क्यों matter करता है

Softmax modern AI में हर जगह है। हर बार जब एक language model next token predict करता है, softmax model के raw outputs को probabilities में convert करता है। हर attention head attention weights compute करने के लिए softmax use करता है। हर classifier class probabilities produce करने के लिए softmax use करता है। Softmax को समझना आपको temperature, top-p sampling, और क्यों models गलत होने पर भी “confident” होते हैं, ये समझने में help करता है।

Deep Dive

The formula: softmax(x_i) = exp(x_i) / ∑ exp(x_j). The exponential amplifies differences: if one logit is 10 and another is 5, the ratio after softmax isn't 2:1 but roughly 150:1. This winner-take-most behavior is why models tend to be confident — softmax naturally produces peaked distributions rather than uniform ones.

Temperature and Softmax

Temperature is applied by dividing logits before softmax: softmax(x_i / T). Temperature T=1 is standard. T<1 sharpens the distribution (more confident, more deterministic). T>1 flattens it (more uniform, more random). This is exactly how the "temperature" parameter in LLM APIs works — it's a scalar applied to the logits before the final softmax that selects the next token.

Numerical Stability

A practical implementation detail: computing exp(x) for large values of x causes overflow. The standard fix is to subtract the maximum value from all logits before applying softmax: softmax(x_i - max(x)). This doesn't change the output (the subtracted constant cancels in the ratio) but keeps the numbers in a manageable range. Every production softmax implementation does this, and it's the kind of detail that matters when building from scratch.

संबंधित अवधारणाएँ

← सभी Terms
← Slop Sparse Attention →