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
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
acc now computes top-1 acc
  • Loading branch information
AlexTMallen committed Apr 16, 2023
commit 941c3968b141013f1bb118e9441e6f7ea81cf726
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ elk/trained/*
nohup.out
.idea
*.pkl
.vscode/launch.json
elk/experiment_results.ipynb
elk/training/loss_api.py
prototyping.ipynb
run.sh
dummy/

# scripts for experiments in progress
my_*.sh
Expand Down
13 changes: 10 additions & 3 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,9 +122,10 @@ 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()
roc_auc_ci(Y_one_hot.cpu(), logits.cpu().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(
Expand Down