Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/mlops_nlp/utils/drift.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,32 @@

LOGGER = get_logger(__name__)

def log_inference(
log_path: str | Path,
text: str,
prediction: str,
confidence: float,
model_version: str,
) -> None:
"""Logs inference data to a JSONL file for future drift detection."""
from datetime import datetime, timezone
log_entry = {
"timestamp": datetime.now(timezone.utc).isoformat(),
"text": text,
"prediction": prediction,
"confidence": confidence,
"model_version": model_version,
}

path = Path(log_path)
path.parent.mkdir(parents=True, exist_ok=True)

try:
with path.open("a", encoding="utf-8") as f:
f.write(json.dumps(log_entry) + "\n")
except Exception as e:
LOGGER.error("Failed to log inference data: %s", e)

def run_drift_check(config: AppConfig) -> Dict[str, Any]:
"""
Runs a drift detection check comparing reference (training) data
Expand Down
Loading