skills/llm/confidence-threshold-fallback/SKILL.md
Uses primary model predictions only when confidence exceeds a threshold, falling back to a backup ensemble otherwise.
npx skillsauth add wenmin-wu/ds-skills llm-confidence-threshold-fallbackInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
When a primary model (e.g., LLM with RAG) is strong but unreliable on some inputs, set a confidence threshold on its softmax output. Use its prediction when max probability exceeds the threshold; otherwise fall back to a pre-computed backup (e.g., ensemble of smaller models). This combines the strengths of both approaches.
import numpy as np
from scipy.special import softmax
def predict_with_fallback(primary_logits, backup_preds, threshold=0.4):
"""Use primary model if confident, else fallback."""
results = []
for i, logits in enumerate(primary_logits):
probs = softmax(logits)
if probs.max() > threshold:
ranked = np.argsort(-probs)[:3]
pred = " ".join(["ABCDE"[j] for j in ranked])
else:
pred = backup_preds[i]
results.append(pred)
return results
data-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
data-ai
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
testing
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
tools
Convert point forecasts to prediction intervals by scaling with logit-transformed quantile ratios passed through a Normal CDF