Skip to content

Commit

Permalink
return_all_scores
Browse files Browse the repository at this point in the history
  • Loading branch information
tcapelle committed Dec 10, 2024
1 parent 30f5f7f commit 5194992
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions weave/scorers/relevance_scorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ class RelevanceScorer(Scorer):
base_url (Optional[str]): Optional URL for external API scoring instead of local model
device (str): Device to run model on, defaults to "cpu"
threshold (float): Threshold for relevance classification, defaults to 0.7
return_all_scores (bool): Whether to return detailed span-level scores, defaults to False
debug (bool): Enable debug logging, defaults to False
Returns:
Expand Down Expand Up @@ -262,7 +261,6 @@ class RelevanceScorer(Scorer):
base_url: Optional[str] = None
device: str = "cpu"
threshold: float = 0.7
return_all_scores: bool = False
_model: Any = PrivateAttr()
_tokenizer: Any = PrivateAttr()

Expand Down Expand Up @@ -325,7 +323,7 @@ def _score_document(
span_prob = positive_probs[start:end].mean()
spans_with_probs.append({
"text": span_text,
"scores": float(span_prob)
"score": float(span_prob)
})

return spans_with_probs, int(label_mask.sum()), int(len(label_mask))
Expand All @@ -334,7 +332,9 @@ def _score_document(
def score(
self,
query: str,
documents: list[str]) -> tuple[list[dict[str, Any]], float]:
documents: list[str],
return_all_scores: bool = False
) -> tuple[list[dict[str, Any]], float]:
"""Score multiple documents and compute weighted average relevance."""
all_spans = []
total_weighted_score = 0.0
Expand All @@ -354,6 +354,6 @@ def score(
final_score = total_weighted_score / total_length if total_length > 0 else 0.0
output = {"flagged": final_score > self.threshold}
output['extras'] = {'score': final_score}
if self.return_all_scores:
if return_all_scores:
output['extras']['all_spans'] = all_spans
return output

0 comments on commit 5194992

Please sign in to comment.