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

Fix accuracy computation in Reporter #195

Merged
merged 2 commits into from
Apr 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions elk/training/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ def score(self, labels: Tensor, hiddens: Tensor) -> EvalResult:
Returns:
an instance of EvalResult containing the loss, accuracy, calibrated
accuracy, and AUROC of the probe on `hiddens`.
accuracy, and AUROC of the probe on `contrast_set`.
Accuracy: top-1 accuracy averaged over questions and variants.
Calibrated accuracy: top-1 accuracy averaged over questions and
variants, calibrated so that x% of the predictions are `True`,
where x is the proprtion of examples with ground truth label `True`.
AUROC: averaged over the n * v * c binary questions
ECE: Expected Calibration Error
"""
logits = self(hiddens)
(_, v, c) = logits.shape
Expand All @@ -116,11 +122,11 @@ def score(self, labels: Tensor, hiddens: Tensor) -> EvalResult:
cal_acc = 0.0
cal_err = 0.0

raw_preds = to_one_hot(logits.argmax(dim=-1), c).long()
Y = to_one_hot(Y, c).long().flatten()
Y_one_hot = to_one_hot(Y, c).long().flatten()
auroc_result = roc_auc_ci(Y_one_hot, logits.flatten())

raw_preds = logits.argmax(dim=-1).long()
raw_acc = accuracy(Y, raw_preds.flatten())
auroc_result = roc_auc_ci(Y, logits.flatten())
return EvalResult(
auroc=auroc_result.estimate,
auroc_lower=auroc_result.lower,
Expand Down