Skip to content

Commit

Permalink
Add aggregation to score
Browse files Browse the repository at this point in the history
  • Loading branch information
hupe1980 committed Apr 24, 2024
1 parent aa9be11 commit af19989
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
1 change: 1 addition & 0 deletions aisploit/classifiers/self_similarity.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def score(self, input: str, references: List[str] | None = None) -> Score[Dict[s
value={
"aggregated_score": score.item(),
"scores": cos_scores.tolist(),
"aggregation": self.aggregation,
},
description="Returns True if the aggregated cosine similarity score is less than the threshold",
explanation=f"The aggregated cosine similarity score for the input is {score}",
Expand Down
7 changes: 4 additions & 3 deletions docs/classifiers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@
"text/plain": [
"{'flagged': True,\n",
" 'value': {'aggregated_score': 0.6721476912498474,\n",
" 'scores': [0.6721476912498474]},\n",
" 'scores': [0.6721476912498474],\n",
" 'aggregation': 'mean'},\n",
" 'description': 'Returns True if the aggregated cosine similarity score is less than the threshold',\n",
" 'explanation': 'The aggregated cosine similarity score for the input is 0.6721476912498474'}"
]
Expand Down Expand Up @@ -257,7 +258,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 8,
"metadata": {},
"outputs": [
{
Expand All @@ -269,7 +270,7 @@
" 'explanation': 'Details about the moderation score'}"
]
},
"execution_count": 1,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
Expand Down
13 changes: 3 additions & 10 deletions examples/classifier.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,16 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"torch.Size([384]) torch.Size([1, 384])\n"
]
},
{
"data": {
"text/plain": [
"Score(flagged=True, value={'aggregated_score': 0.6721476912498474, 'scores': [0.6721476912498474]}, description='Returns True if the aggregated cosine similarity score is less than the threshold', explanation='The aggregated cosine similarity score for the input is 0.6721476912498474')"
"Score(flagged=True, value={'aggregated_score': 0.6721476912498474, 'scores': [0.6721476912498474], 'aggregation': 'mean'}, description='Returns True if the aggregated cosine similarity score is less than the threshold', explanation='The aggregated cosine similarity score for the input is 0.6721476912498474')"
]
},
"execution_count": 3,
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
Expand Down

0 comments on commit af19989

Please sign in to comment.