From af19989840b0d10909adee033a41af13d252ba0a Mon Sep 17 00:00:00 2001 From: hupe1980 Date: Wed, 24 Apr 2024 23:20:50 +0200 Subject: [PATCH] Add aggregation to score --- aisploit/classifiers/self_similarity.py | 1 + docs/classifiers.ipynb | 7 ++++--- examples/classifier.ipynb | 13 +++---------- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/aisploit/classifiers/self_similarity.py b/aisploit/classifiers/self_similarity.py index c9815cb..99f2a3d 100644 --- a/aisploit/classifiers/self_similarity.py +++ b/aisploit/classifiers/self_similarity.py @@ -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}", diff --git a/docs/classifiers.ipynb b/docs/classifiers.ipynb index 15788e8..2ed560d 100644 --- a/docs/classifiers.ipynb +++ b/docs/classifiers.ipynb @@ -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'}" ] @@ -257,7 +258,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -269,7 +270,7 @@ " 'explanation': 'Details about the moderation score'}" ] }, - "execution_count": 1, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } diff --git a/examples/classifier.ipynb b/examples/classifier.ipynb index c2c3461..55373cf 100644 --- a/examples/classifier.ipynb +++ b/examples/classifier.ipynb @@ -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" }