Skip to content

Fix Softmax - #438

Merged
andrewdalpino merged 7 commits into
3.0from
fix-softmax-numpower
Aug 26, 2026
Merged

Fix Softmax#438
andrewdalpino merged 7 commits into
3.0from
fix-softmax-numpower

Conversation

@andrewdalpino

Copy link
Copy Markdown
Member

differentiate() flattens the [class, batch] matrix and builds a [class·batch × class·batch] Jacobian. Wrong shape for any batch > 1. Masked when Multiclass uses the CrossEntropy shortcut (which never calls this). Any other ClassificationLoss + Activation(new Softmax()) will produce shape errors or silent garbage.

@andrewdalpino
andrewdalpino requested review from a team and a lite review from Copilot August 25, 2026 02:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes batched Softmax gradient handling and adds coverage for non-cross-entropy losses.

Changes:

  • Adds shape-preserving batched Softmax derivative coverage.
  • Computes per-sample Jacobian-vector products in Multiclass.
  • Adds gradient tests and cleans ELU formatting.

A critical issue remains: generic Activation usage still drops Softmax cross-class gradient terms.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Summary
tests/NeuralNet/Layers/MulticlassTest.php Adds Relative Entropy gradient coverage.
tests/NeuralNet/ActivationFunctions/SoftmaxTest.php Adds batched derivative tests.
src/NeuralNet/Layers/Multiclass.php Applies batched Jacobian-vector products.
src/NeuralNet/ActivationFunctions/Softmax.php Updates derivative calculation.
src/NeuralNet/ActivationFunctions/ELU.php Formatting-only cleanup.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/NeuralNet/ActivationFunctions/Softmax.php
@andrewdalpino
andrewdalpino merged commit 961b89a into 3.0 Aug 26, 2026
0 of 2 checks passed
@andrewdalpino
andrewdalpino deleted the fix-softmax-numpower branch August 26, 2026 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants