param-bharat
commited on
Upload NLIScorer
Browse files- pipeline.py +27 -31
pipeline.py
CHANGED
@@ -331,31 +331,31 @@ TASK_CLASSES = {
|
|
331 |
}
|
332 |
|
333 |
TASK_THRESHOLDS = {
|
334 |
-
"Detection/Hallucination/Factual Consistency": 0.
|
335 |
-
"Detection/Prompt Injection": 0.
|
336 |
-
"Detection/Source Code": 0.
|
337 |
-
"Detection/Toxicity/Disability": 0.
|
338 |
-
"Detection/Toxicity/Gender": 0.
|
339 |
-
"Detection/Toxicity/Identity Hate": 0.
|
340 |
-
"Detection/Toxicity/Insult": 0.
|
341 |
-
"Detection/Toxicity/Obscene": 0.
|
342 |
-
"Detection/Toxicity/Race": 0.
|
343 |
-
"Detection/Toxicity/Religion": 0.
|
344 |
-
"Detection/Toxicity/Toxic": 0.
|
345 |
-
"Detection/Toxicity/Violence": 0.
|
346 |
-
"Quality/Context/Document Relevance": 0.
|
347 |
-
"Quality/Context/Document Utilization": 0.
|
348 |
-
"Quality/Context/Sentence Relevance": 0.
|
349 |
-
"Quality/Context/Sentence Utilization": 0.
|
350 |
-
"Quality/Response/Adherence": 0.
|
351 |
-
"Quality/Response/Attribution": 0.
|
352 |
-
"Quality/Response/Coherence": 0.
|
353 |
-
"Quality/Response/Complexity": 0.
|
354 |
-
"Quality/Response/Correctness": 0.
|
355 |
-
"Quality/Response/Helpfulness": 0.
|
356 |
-
"Quality/Response/Instruction Following": 0.
|
357 |
-
"Quality/Response/Relevance": 0.
|
358 |
-
"Quality/Response/Verbosity": 0.
|
359 |
}
|
360 |
|
361 |
|
@@ -381,12 +381,8 @@ class NLIScorer(Pipeline):
|
|
381 |
return outputs
|
382 |
|
383 |
def postprocess(self, model_outputs, task_type=None, threshold=None):
|
384 |
-
if threshold is
|
385 |
-
threshold =
|
386 |
-
elif task_type is not None:
|
387 |
-
threshold = TASK_THRESHOLDS[task_type]
|
388 |
-
else:
|
389 |
-
threshold = 0.5
|
390 |
pos_scores = model_outputs["logits"].softmax(-1)[0][1]
|
391 |
best_class = int(pos_scores > threshold)
|
392 |
if best_class == 1:
|
|
|
331 |
}
|
332 |
|
333 |
TASK_THRESHOLDS = {
|
334 |
+
"Detection/Hallucination/Factual Consistency": 0.5,
|
335 |
+
"Detection/Prompt Injection": 0.5001,
|
336 |
+
"Detection/Source Code": 0.5039,
|
337 |
+
"Detection/Toxicity/Disability": 0.5111,
|
338 |
+
"Detection/Toxicity/Gender": 0.5003,
|
339 |
+
"Detection/Toxicity/Identity Hate": 0.5035,
|
340 |
+
"Detection/Toxicity/Insult": 0.5187,
|
341 |
+
"Detection/Toxicity/Obscene": 0.5034,
|
342 |
+
"Detection/Toxicity/Race": 0.5081,
|
343 |
+
"Detection/Toxicity/Religion": 0.5058,
|
344 |
+
"Detection/Toxicity/Toxic": 0.5005,
|
345 |
+
"Detection/Toxicity/Violence": 0.5001,
|
346 |
+
"Quality/Context/Document Relevance": 0.5016,
|
347 |
+
"Quality/Context/Document Utilization": 0.5014,
|
348 |
+
"Quality/Context/Sentence Relevance": 0.5002,
|
349 |
+
"Quality/Context/Sentence Utilization": 0.5039,
|
350 |
+
"Quality/Response/Adherence": 0.5107,
|
351 |
+
"Quality/Response/Attribution": 0.5053,
|
352 |
+
"Quality/Response/Coherence": 0.6103,
|
353 |
+
"Quality/Response/Complexity": 0.5603,
|
354 |
+
"Quality/Response/Correctness": 0.501,
|
355 |
+
"Quality/Response/Helpfulness": 0.5018,
|
356 |
+
"Quality/Response/Instruction Following": 0.5001,
|
357 |
+
"Quality/Response/Relevance": 0.5012,
|
358 |
+
"Quality/Response/Verbosity": 0.5408,
|
359 |
}
|
360 |
|
361 |
|
|
|
381 |
return outputs
|
382 |
|
383 |
def postprocess(self, model_outputs, task_type=None, threshold=None):
|
384 |
+
if threshold is None:
|
385 |
+
threshold = TASK_THRESHOLDS.get(task_type, 0.5)
|
|
|
|
|
|
|
|
|
386 |
pos_scores = model_outputs["logits"].softmax(-1)[0][1]
|
387 |
best_class = int(pos_scores > threshold)
|
388 |
if best_class == 1:
|