Softmax and log-softmax: spec definitions versus analytic presentation #
NN.Proofs.Autograd.FDeriv.Softmax and NN.Proofs.Autograd.FDeriv.LogSoftmax prove
Fréchet-derivative facts about softmaxVec and logSoftmaxVec, which are stated directly on
Euclidean vectors. The specification layer instead defines Activation.softmaxVecSpec and
Activation.logSoftmaxVecSpec on tensors, using the numerically stable max-shifted form.
This file closes that gap over ℝ:
getScalarE_softmaxVecSpecandgetScalarE_logSoftmaxVecSpecidentify the spec kernels with the analytic definitions after vectorization;hasFDerivAt_softmaxSpec_vecandhasFDerivAt_logSoftmaxSpec_vectransfer differentiability toActivation.softmaxSpec 0andActivation.logSoftmaxSpec 0;softmaxFDerivCorrectandlogSoftmaxFDerivCorrectpackageSpec.softmaxOp 0andSpec.logSoftmaxOp 0asOpSpecFDerivCorrect, so their backward rules are proved to be the adjoint of the true derivative (softmaxBackwardSpec_eq_vjp,logSoftmaxBackwardSpec_eq_vjp).hasFDerivAt_distillSpec_vecidentifies the cancellation-resistant student pullback with the derivative of the teacher-logit loss, with the teacher held fixed.hasFDerivAt_crossEntropyLogitsSpec_vecandhasFDerivAt_crossEntropyTargets_vecprove the logits and target-weight derivatives of the weighted loss. Targets need not sum to one.
Softmax #
The spec softmax kernel is the analytic softmaxVec after vectorization.
softmaxVecSpec on a vector built from Euclidean coordinates.
The vectorized forward map of Spec.softmaxOp 0 on vectors is softmaxVec.
Axis-0 spec softmax on vectors is Fréchet-differentiable with derivative
softmaxDerivCLM.
The spec softmax VJP is the analytic softmaxJvp (the softmax Jacobian is symmetric).
Spec.softmaxOp 0 on vectors with its analytic JVP and the VJP/JVP adjointness law.
Instances For
Spec.softmaxOp 0 on vectors is analytically correct: its JVP is the Fréchet derivative.
Instances For
The spec softmax backward is the vector-Jacobian product of the spec softmax forward.
Log-softmax #
The spec log-softmax kernel is the analytic logSoftmaxVec after vectorization.
The vectorized forward map of Spec.logSoftmaxOp 0 on vectors is logSoftmaxVec.
Axis-0 spec log-softmax on vectors is Fréchet-differentiable with derivative
logSoftmaxDerivCLM.
Exponentiating the spec log-softmax output recovers the analytic softmax coordinates.
The typed graph's compensated log-softmax JVP agrees with the analytic derivative.
The spec log-softmax VJP, evaluated on the recomputed forward output, is the analytic
logSoftmaxVjp.
Spec.logSoftmaxOp 0 on vectors with its analytic JVP and the VJP/JVP adjointness law.
Instances For
Spec.logSoftmaxOp 0 on vectors is analytically correct: its JVP is the Fréchet
derivative.
Instances For
The spec log-softmax backward is the vector-Jacobian product of the spec log-softmax forward.
Weighted logits cross-entropy #
The overflow-aware weighted loss preserves the real cross-entropy formula. This is a real identity, not bitwise equivalence between the two floating-point evaluation schedules.
The shared logits pullback differentiates the actual weighted loss, including unnormalized and zero target weights. No probability-normalization hypothesis is needed.
Target weights remain differentiable, including at zero. The numerical implementation must not turn a zero-weight forward shortcut into a zero target derivative.
Distillation #
The logit-difference gradient is the usual student-minus-teacher probability difference over the reals. Both numerical branches and the residual correction preserve this identity.
With teacher logits fixed, distillDerivSpec is the Fréchet derivative of the actual
distillation loss on nonempty class vectors. This connects the compensated pullback to the loss,
rather than just identifying it with another gradient formula.