Skip to content

Fix double exp() of logit_scale in create_probabilities#197

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-double-exp-logit-scale
Draft

Fix double exp() of logit_scale in create_probabilities#197
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-double-exp-logit-scale

Conversation

Copilot AI commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

BaseClassifier.create_probabilities() was calling self.model.logit_scale.exp(), but the BioCLIP pretrained model stores logit_scale already as the scale (not its log), so this applied exp() twice — producing inflated logits and over-confident (potentially overflowing) probabilities.

Changes

  • src/bioclip/predict.py: Remove .exp() from logit_scale in create_probabilities():

    # Before
    logits = (self.model.logit_scale.exp() * img_features @ txt_features)
    # After
    logits = (self.model.logit_scale * img_features @ txt_features)

    Mirrors the identical fix in Imageomics/bioclip#39.

  • tests/test_predict.py: Add TestCreateProbabilities with two unit tests — one asserting the corrected direct-scale behavior, and one confirming the double-exp() path produces a meaningfully different (wrong) result.

Copilot AI linked an issue Jun 1, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix double exp() of logit_scale Fix double exp() of logit_scale in create_probabilities Jun 1, 2026
Copilot finished work on behalf of hlapp June 1, 2026 10:21
Copilot AI requested a review from hlapp June 1, 2026 10:21
@hlapp

hlapp commented Jun 1, 2026

Copy link
Copy Markdown
Member

@work4cs your change seems to lead to complete mis-prediction here (the test failure is in classifying the cat as a plant rather than a cat, not in the newly introduced unit test). Any idea why this is?

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.

Fix double exp() of logit_scale

2 participants