-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: move scipy and sklearn module imports to func imports Signed-off-by: Nathan Weinberg <nweinber@redhat.com> * refactor: consolidate weighted_f1_score func into lm_eval utils Signed-off-by: Nathan Weinberg <nweinber@redhat.com> * lint: allow for utils file to have unused imports this allows for shared functions to be defined only once while allowing for the YAML function importing to continue working Signed-off-by: Nathan Weinberg <nweinber@redhat.com> --------- Signed-off-by: Nathan Weinberg <nweinber@redhat.com>
- Loading branch information
1 parent
63e76e8
commit 7f15cce
Showing
17 changed files
with
42 additions
and
89 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,6 @@ | ||
from sklearn.metrics import f1_score | ||
from lm_eval.utils import weighted_f1_score | ||
|
||
|
||
def doc_to_target(doc): | ||
replacements = {0: "True", 1: "Neither", 2: "False"} | ||
return replacements[doc["label"]] | ||
|
||
|
||
def weighted_f1_score(items): | ||
unzipped_list = list(zip(*items)) | ||
golds = unzipped_list[0] | ||
preds = unzipped_list[1] | ||
fscore = f1_score(golds, preds, average="weighted") | ||
return fscore |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1 @@ | ||
from sklearn.metrics import f1_score | ||
|
||
|
||
def weighted_f1_score(items): | ||
unzipped_list = list(zip(*items)) | ||
golds = unzipped_list[0] | ||
preds = unzipped_list[1] | ||
fscore = f1_score(golds, preds, average="weighted") | ||
return fscore | ||
from lm_eval.utils import weighted_f1_score |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,6 @@ | ||
from sklearn.metrics import f1_score | ||
from lm_eval.utils import weighted_f1_score | ||
|
||
|
||
def doc_to_target(doc): | ||
replacements = {0: "True", 1: "Neither", 2: "False"} | ||
return replacements[doc["label"]] | ||
|
||
|
||
def weighted_f1_score(items): | ||
unzipped_list = list(zip(*items)) | ||
golds = unzipped_list[0] | ||
preds = unzipped_list[1] | ||
fscore = f1_score(golds, preds, average="weighted") | ||
return fscore |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
import numpy as np | ||
import sklearn | ||
|
||
|
||
def cb_multi_fi(items): | ||
from sklearn.metrics import f1_score | ||
|
||
preds, golds = zip(*items) | ||
preds = np.array(preds) | ||
golds = np.array(golds) | ||
f11 = sklearn.metrics.f1_score(y_true=golds == 0, y_pred=preds == 0) | ||
f12 = sklearn.metrics.f1_score(y_true=golds == 1, y_pred=preds == 1) | ||
f13 = sklearn.metrics.f1_score(y_true=golds == 2, y_pred=preds == 2) | ||
f11 = f1_score(y_true=golds == 0, y_pred=preds == 0) | ||
f12 = f1_score(y_true=golds == 1, y_pred=preds == 1) | ||
f13 = f1_score(y_true=golds == 2, y_pred=preds == 2) | ||
avg_f1 = np.mean([f11, f12, f13]) | ||
return avg_f1 |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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