Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
app/monitoring/__pycache__/service_metrics.cpython-311.pyc
CHANGED
|
Binary files a/app/monitoring/__pycache__/service_metrics.cpython-311.pyc and b/app/monitoring/__pycache__/service_metrics.cpython-311.pyc differ
|
|
|
app/monitoring/service_metrics.py
CHANGED
|
@@ -27,7 +27,14 @@ PREDICTION_CONFIDENCE = Histogram(
|
|
| 27 |
buckets=[0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
|
| 28 |
)
|
| 29 |
|
| 30 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
INFERENCE_LATENCY = Histogram(
|
| 32 |
"model_inference_seconds",
|
| 33 |
"Model inference time in seconds",
|
|
|
|
| 27 |
buckets=[0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
|
| 28 |
)
|
| 29 |
|
| 30 |
+
# Prediction confidence margin
|
| 31 |
+
CONFIDENCE_MARGIN = Histogram(
|
| 32 |
+
"prediction_confidence_margin",
|
| 33 |
+
"Distance from decision boundary (2*prob - 1)",
|
| 34 |
+
buckets=[0.05, 0.10, 0.20, 0.30, 0.40, 0.50, 0.60, 0.70, 0.80, 0.90, 1.0]
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
# Inference response time
|
| 38 |
INFERENCE_LATENCY = Histogram(
|
| 39 |
"model_inference_seconds",
|
| 40 |
"Model inference time in seconds",
|
app/services/__pycache__/inference.cpython-311.pyc
CHANGED
|
Binary files a/app/services/__pycache__/inference.cpython-311.pyc and b/app/services/__pycache__/inference.cpython-311.pyc differ
|
|
|
app/services/inference.py
CHANGED
|
@@ -3,7 +3,7 @@ from datetime import datetime, timezone
|
|
| 3 |
from src.core.logger import logging
|
| 4 |
from src.core.exception import AppException
|
| 5 |
from src.app.monitoring.service_metrics import (PREDICTION_REQUEST_SUCCESS, PREDICTION_REQUEST_FAILED,
|
| 6 |
-
PREDICTION_CLASS, INFERENCE_LATENCY, PREDICTION_CONFIDENCE)
|
| 7 |
|
| 8 |
class InferenceService:
|
| 9 |
def __init__(self, model_booster, vectorizer, eval_threshold,
|
|
@@ -54,7 +54,10 @@ class InferenceService:
|
|
| 54 |
|
| 55 |
warnings = None
|
| 56 |
if confidence_margin < 0.10:
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
| 58 |
warnings = {
|
| 59 |
"code": "LOW_CONFIDENCE_MARGIN",
|
| 60 |
"message": message
|
|
@@ -82,6 +85,8 @@ class InferenceService:
|
|
| 82 |
PREDICTION_CLASS.labels(class_label=str(pred[0])).inc()
|
| 83 |
# Track class confidence
|
| 84 |
PREDICTION_CONFIDENCE.labels(class_label=str(pred[0])).observe(confidence)
|
|
|
|
|
|
|
| 85 |
|
| 86 |
response = {
|
| 87 |
"id": request_id,
|
|
|
|
| 3 |
from src.core.logger import logging
|
| 4 |
from src.core.exception import AppException
|
| 5 |
from src.app.monitoring.service_metrics import (PREDICTION_REQUEST_SUCCESS, PREDICTION_REQUEST_FAILED,
|
| 6 |
+
PREDICTION_CLASS, INFERENCE_LATENCY, PREDICTION_CONFIDENCE, CONFIDENCE_MARGIN)
|
| 7 |
|
| 8 |
class InferenceService:
|
| 9 |
def __init__(self, model_booster, vectorizer, eval_threshold,
|
|
|
|
| 54 |
|
| 55 |
warnings = None
|
| 56 |
if confidence_margin < 0.10:
|
| 57 |
+
if pred[0] == 1:
|
| 58 |
+
message=f"Model predicted as 'Toxic', but prediction confidence is close to decision boundary. Manual review is recommended! Please consider providing feedback to help improve the model."
|
| 59 |
+
else:
|
| 60 |
+
message=f"Model predicted as 'Safe', but prediction confidence is close to decision boundary. Manual review is recommended! Please consider providing feedback to help improve the model."
|
| 61 |
warnings = {
|
| 62 |
"code": "LOW_CONFIDENCE_MARGIN",
|
| 63 |
"message": message
|
|
|
|
| 85 |
PREDICTION_CLASS.labels(class_label=str(pred[0])).inc()
|
| 86 |
# Track class confidence
|
| 87 |
PREDICTION_CONFIDENCE.labels(class_label=str(pred[0])).observe(confidence)
|
| 88 |
+
# Track confidence margin
|
| 89 |
+
CONFIDENCE_MARGIN.observe(confidence_margin)
|
| 90 |
|
| 91 |
response = {
|
| 92 |
"id": request_id,
|