-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main'
- Loading branch information
Showing
52 changed files
with
1,065 additions
and
840 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
from .base_metric import * | ||
from .base_classification_metric import * | ||
from .base_disambiguation_metric import * | ||
from .base_masked_lm import * | ||
from .base_regression_metric import * | ||
|
||
__all__ = [ | ||
"BaseMetric", | ||
"BaseClassificationMetric", | ||
"BaseDisambiguationMetric", | ||
"BaseMaskedLMMetric", | ||
"BaseRegressionMetric", | ||
] |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from cogktr.core.metric.base_metric import BaseMetric | ||
from sklearn.metrics import top_k_accuracy_score | ||
|
||
|
||
class BaseMaskedLMMetric(BaseMetric): | ||
def __init__(self, topk=1): | ||
super().__init__() | ||
self.topk = topk | ||
self.label_list = list() | ||
self.pre_list = list() | ||
self.default_metric_name = "Top_K_Acc" | ||
|
||
def evaluate(self, pred, label): | ||
self.label_list = self.label_list + label.cpu().tolist() | ||
self.pre_list = self.pre_list + pred.cpu().tolist() | ||
|
||
def get_metric(self, reset=True): | ||
top_k_acc = top_k_accuracy_score(self.label_list, | ||
self.pre_list, | ||
k=self.topk, | ||
labels=list(range(len(self.pre_list[0])))) | ||
evaluate_result = {"Top_K_Acc": top_k_acc} | ||
if reset: | ||
self.label_list = list() | ||
self.pre_list = list() | ||
return evaluate_result |
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,31 +1,22 @@ | ||
from cogktr.core.metric.base_metric import BaseMetric | ||
from sklearn.metrics import precision_score | ||
from sklearn.metrics import recall_score | ||
from sklearn.metrics import f1_score | ||
from sklearn.metrics import top_k_accuracy_score | ||
import numpy as np | ||
|
||
|
||
class BaseQuestionAnsweringMetric(BaseMetric): | ||
def __init__(self): | ||
super().__init__() | ||
self.label_list = list() | ||
self.pre_list = list() | ||
self.default_metric_name = "Top_K_Acc" | ||
|
||
def evaluate(self, pred, label): | ||
# print(pred.size()) | ||
# print(label.size()) | ||
self.label_list = self.label_list + label.cpu().tolist() | ||
self.pre_list = self.pre_list + pred.cpu().tolist() | ||
|
||
def get_metric(self, reset=True, topk=5): | ||
# print(self.pre_list.size()) | ||
# print(self.label_list.size()) | ||
# print(max(self.label_list)) | ||
# print(len(self.pre_list[0])) | ||
acc = top_k_accuracy_score(self.label_list, self.pre_list, k=topk, labels=range(len(self.pre_list[0]))) | ||
evaluate_result = {"Acc": acc} | ||
top_k_acc = top_k_accuracy_score(self.label_list, self.pre_list, k=topk, labels=range(len(self.pre_list[0]))) | ||
evaluate_result = {"Top_K_Acc": top_k_acc} | ||
if reset: | ||
self.label_list = list() | ||
self.pre_list = list() | ||
return evaluate_result | ||
return evaluate_result |
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
Oops, something went wrong.