Repository navigation
Preserve ranking-loss gradients with weighted log-sigmoid - #4116
Merged
Merged
Conversation
Member
|
Hello! The fix makes sense. The probability clamps can zero out gradients for misordered pairs even at fairly modest score differences. Using I've pushed a follow-up to move the tests into
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
LambdaLoss computes a weighted sigmoid in probability space, then clamps it before taking the logarithm. For strongly misordered documents, this caps the loss at
-log(eps)and gives the model zero ranking gradients. RankNetLoss inherits the same behavior. With scores[0, 1000]and relevance[1, 0], the natural-log RankNet loss is about 23 instead of 1000.Compute the weighted log-probability directly with
logsigmoid, and convert to binary logarithms afterward. This preserves the pair selection, ranking weights, and mean reduction while retaining gradients for badly misranked documents.Validation: CPU tests import the complete native source package and run the production losses with a deterministic trainable score model at the model-input boundary. The 50 new cases compare losses and gradients against independent float64 binary cross-entropy references, covering both losses, both logarithm bases, multiple sigma values, large positive/negative score gaps, and variable-length padded batches. Before the change: 16 failed, 34 passed. After: 50 passed. The final targeted run included the existing ListMLE numerical regression cases: 62 passed, 16 deselected. Ruff lint and formatting checks pass for both changed files. No pretrained-model or CUDA training run was performed.