Skip to content

Commit

Permalink
fix: formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethEnevoldsen committed Jun 2, 2024
1 parent 53c477f commit 8d3fc1b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion mteb/evaluation/evaluators/RerankingEvaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def nAUC_scores(
"""Computes normalized Area Under the Curve on a set of evaluated instances as presented in the paper https://arxiv.org/abs/2402.12997
Args:
all_conf_scores: Confidence scores for all instances, with length `len(samples)`
all_conf_scores: Confidence scores for all instances, with length `len(samples)`
metrics: Metric scores for all instances, with length `len(samples)`
metric_name: Name of the metric (mrr or ap)
Expand Down
10 changes: 5 additions & 5 deletions mteb/evaluation/evaluators/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,13 @@ def confidence_scores(sim_scores: List[float]) -> Dict[str, float]:
- `diff1`: Difference between highest and second highest similarity scores
"""
sim_scores_sorted = sorted(sim_scores)[::-1]

cs_max = sim_scores_sorted[0]
cs_std = np.std(sim_scores)
if len(sim_scores) > 1:
cs_diff1 = sim_scores_sorted[0] - sim_scores_sorted[1]
elif len(sim_scores) == 1:
cs_diff1 = 0.
cs_diff1 = 0.0

conf_scores = {"max": cs_max, "std": cs_std, "diff1": cs_diff1}

Expand All @@ -323,7 +323,7 @@ def confidence_scores(sim_scores: List[float]) -> Dict[str, float]:
def nAUC(
conf_scores: np.ndarray,
metrics: np.ndarray,
abstention_rates: np.ndarray = np.linspace(0,1,11)[:-1],
abstention_rates: np.ndarray = np.linspace(0, 1, 11)[:-1],
) -> float:
"""Computes normalized Area Under the Curve on a set of evaluated instances as presented in the paper https://arxiv.org/abs/2402.12997
1/ Computes the raw abstention curve, i.e., the average evaluation metric at different abstention rates determined by the confidence scores
Expand All @@ -344,7 +344,7 @@ def nAUC(
def abstention_curve(
conf_scores: np.ndarray,
metrics: np.ndarray,
abstention_rates: np.ndarray = np.linspace(0,1,11)[:-1],
abstention_rates: np.ndarray = np.linspace(0, 1, 11)[:-1],
) -> np.ndarray:
"""Computes the raw abstention curve for a given set of evaluated instances and corresponding confidence scores
Expand All @@ -365,7 +365,7 @@ def abstention_curve(
return abst_curve

def oracle_curve(
metrics: np.ndaray, abstention_rates: np.ndarray = np.linspace(0,1,11)[:-1]
metrics: np.ndaray, abstention_rates: np.ndarray = np.linspace(0, 1, 11)[:-1]
) -> np.ndarray:
"""Computes the oracle curve for a given set of evaluated instances
Expand Down
4 changes: 3 additions & 1 deletion tests/test_RerankingEvaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ def test_nAUC(self):
[0.5, 0.4, 0.5, 0.2],
]

ap_scores = [self.evaluator.ap_score(y, x) for x, y in zip(pred_scores, is_relevant)]
ap_scores = [
self.evaluator.ap_score(y, x) for x, y in zip(pred_scores, is_relevant)
]
conf_scores = [self.evaluator.conf_scores(x) for x in pred_scores]
nauc_scores_map = self.evaluator.nAUC_scores(conf_scores, ap_scores, "map")

Expand Down

0 comments on commit 8d3fc1b

Please sign in to comment.