Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds mechanism for calibrating probabilities for category and binary features #1949

Merged
merged 48 commits into from
Jun 23, 2022

Conversation

dantreiman
Copy link
Collaborator

@dantreiman dantreiman commented Apr 21, 2022

Implements:
temperature scaling for binary and category outputs
matrix scaling for category outputs

Example using Twitter Bots w categorical output feature:
On this example, matrix scaling does not improve ECE, though it improves NLL (probably due to overfitting) so matrix scaling gets rolled back and we get the original uncalibrated probs. On much larger datasets matrix scaling may yield better results.

Validation Set (used to determine softmax temperature):
calibration_1_vs_all_1

Test set:
calibration_1_vs_all_1

@dantreiman dantreiman marked this pull request as draft April 21, 2022 21:44
@dantreiman dantreiman changed the title Adds mechanism for calibrating probabilities for category and binary features Adds mechanism for calibrating probabilities for category and binary features [draft] Apr 21, 2022
@github-actions
Copy link

github-actions bot commented Apr 21, 2022

Unit Test Results

       6 files  ±  0         6 suites  ±0   2h 24m 4s ⏱️ + 10m 50s
2 837 tests +  5  2 803 ✔️ +  5    34 💤 ±0  0 ±0 
8 511 runs  +15  8 405 ✔️ +15  106 💤 ±0  0 ±0 

Results for commit aaea9d8. ± Comparison against base commit 8c6e189.

♻️ This comment has been updated with latest results.

@dantreiman dantreiman force-pushed the daniel/calibrate_probabilities branch from 19d6382 to 08cc421 Compare April 21, 2022 22:16
@dantreiman dantreiman force-pushed the daniel/calibrate_probabilities branch 2 times, most recently from 73a979d to 97058c0 Compare May 9, 2022 19:27
@dantreiman dantreiman force-pushed the daniel/calibrate_probabilities branch 3 times, most recently from 0e5f817 to 624ede4 Compare May 11, 2022 23:38
@dantreiman dantreiman changed the title Adds mechanism for calibrating probabilities for category and binary features [draft] Adds mechanism for calibrating probabilities for category and binary features May 11, 2022
@dantreiman dantreiman force-pushed the daniel/calibrate_probabilities branch 2 times, most recently from cb0419f to e84124f Compare May 16, 2022 22:42
@dantreiman dantreiman marked this pull request as ready for review May 17, 2022 00:55
@w4nderlust
Copy link
Collaborator

In the image I can't see the blue points, do they overlap with the green ones?

@dantreiman
Copy link
Collaborator Author

In the image I can't see the blue points, do they overlap with the green ones?

Thats right, in this example the matrix scaling got rolled back to the original uncalibrated probabilities.

ludwig/features/base_feature.py Outdated Show resolved Hide resolved
ludwig/features/base_feature.py Outdated Show resolved Hide resolved
ludwig/features/binary_feature.py Outdated Show resolved Hide resolved
ludwig/features/category_feature.py Outdated Show resolved Hide resolved
self.batch_size = batch_size
self.skip_save_model = skip_save_model

def calibration(self, dataset, dataset_name: str, save_path: str):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not 100% sure, but it seems to me that in some cases calibration is the act of calibrating outputs, in some cases calibration is the object/function that can calibrate and in some other cases it is the act of training the calibrator.

We probably should be a bit more explicit to avoid confusion.
Wdyt about train_calibrator, get_calibrated_probabilities_from_logits or something else?
Those may be too verbose, but we can brainstorm a bit on this

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I like train_calibrator, that is clear. get_calibrated_probabilities_from_logits is a good name IMO, where are you thinking that should go (which method would be renamed to this)? Right now it happens in the PredictModule which just calls the forward method of the calibration module.

ludwig/models/calibrator.py Outdated Show resolved Hide resolved
ludwig/models/predictor.py Outdated Show resolved Hide resolved
ludwig/models/trainer.py Outdated Show resolved Hide resolved
ludwig/utils/calibration.py Show resolved Hide resolved
ludwig/api.py Outdated Show resolved Hide resolved
@dantreiman dantreiman force-pushed the daniel/calibrate_probabilities branch 3 times, most recently from d6dcd7c to 52085ed Compare June 6, 2022 20:29
@dantreiman dantreiman force-pushed the daniel/calibrate_probabilities branch 5 times, most recently from 47274d9 to fb4c31b Compare June 14, 2022 19:13
@tgaddair tgaddair added feature New feature or request release-0.6 Feature to be implemented in v0.6 labels Jun 15, 2022
@dantreiman dantreiman force-pushed the daniel/calibrate_probabilities branch from b5fcd40 to 32b8011 Compare June 15, 2022 01:27
@dantreiman dantreiman force-pushed the daniel/calibrate_probabilities branch from 81ca5b7 to aaea9d8 Compare June 22, 2022 23:56
@dantreiman dantreiman merged commit e65f74e into ludwig-ai:master Jun 23, 2022
@dantreiman dantreiman deleted the daniel/calibrate_probabilities branch June 23, 2022 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request release-0.6 Feature to be implemented in v0.6
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants