Views
No views yet
OneVsRestClassifier ensemble of 23 binary CatBoostClassifier estimators| File | Size | Description |
|---|---|---|
feature_extractor.pkl | 211 KB | Scikit-Learn transformer pipeline combining 5,000 TF-IDF n-gram features with 19 structural heuristics (sentence count, code blocks, math symbols, domain keywords). |
prompt_router.pkl | 13.0 MB | Trained OneVsRestClassifier wrapping 23 individual CatBoostClassifier models (iterations=300, depth=6, learning_rate=0.1). |
label_binarizer.pkl | 826 B | Fitted Scikit-Learn MultiLabelBinarizer mapping categorical label names to binary arrays. |
thresholds.npy | 312 B | Optimal decision threshold matrix ($t_{\text{opt}}$) tuned per class to maximize individual F1 scores. |
easy, moderate, hardreasoning-light, reasoning-moderate, reasoning-intensiveshort-output ($\le 200$), medium-output ($\approx 500$), long-output ($\ge 1,200$)cheap, balanced, premium, realtime, interactive, backgroundcoding, debugging, infrastructure, architecture, architecture-heavy, mlops, analysis, research| Metric | Baseline ($t=0.50$) | Tuned Thresholds ($t=t_{\text{opt}}$) | Relative Change |
|---|---|---|---|
| Macro F1 Score | 0.8094 | 0.8320 | +2.79% |
| Micro F1 Score | 0.8282 | 0.8419 | +1.65% |
| Weighted F1 Score | 0.8300 | 0.8447 | +1.77% |
| Hamming Loss | 0.0907 | 0.0840 | -7.39% (Lower is better) |
| Inference Latency | < 10ms | < 10ms | CPU Real-Time |
| Label | Precision | Recall | F1-Score | Optimal Threshold ($t_{\text{opt}}$) | Test Support |
|---|---|---|---|---|---|
architecture-heavy | 1.00 | 0.90 | 0.95 | 0.40 | 29 |
interactive | 0.91 | 0.98 | 0.94 | 0.35 | 230 |
mlops | 1.00 | 0.85 | 0.92 | 0.45 | 27 |
hard | 0.92 | 0.90 | 0.91 | 0.50 | 136 |
reasoning-intensive | 0.92 | 0.90 | 0.91 | 0.50 | 136 |
realtime | 0.90 | 0.92 | 0.91 | 0.40 | 48 |
background | 0.93 | 0.85 | 0.89 | 0.55 | 91 |
long-output | 0.94 | 0.86 | 0.89 | 0.55 | 104 |
premium | 0.84 | 0.93 | 0.88 | 0.40 | 114 |
medium-output | 0.85 | 0.92 | 0.88 | 0.40 | 177 |
debugging | 0.90 | 0.80 | 0.85 | 0.50 | 46 |
short-output | 0.86 | 0.81 | 0.84 | 0.50 | 91 |
coding | 0.77 | 0.90 | 0.83 | 0.40 | 105 |
easy | 0.88 | 0.77 | 0.82 | 0.55 | 96 |
reasoning-light | 0.88 | 0.76 | 0.82 | 0.55 | 96 |
cheap | 0.82 | 0.79 | 0.80 | 0.50 | 90 |
balanced | 0.75 | 0.83 | 0.79 | 0.45 | 122 |
moderate | 0.67 | 0.89 | 0.77 | 0.35 | 140 |
reasoning-moderate | 0.65 | 0.92 | 0.76 | 0.35 | 140 |
research | 0.71 | 0.77 | 0.74 | 0.45 | 22 |
infrastructure | 0.62 | 0.83 | 0.71 | 0.35 | 77 |
analysis | 0.56 | 0.85 | 0.68 | 0.35 | 41 |
architecture | 0.80 | 0.56 | 0.66 | 0.55 | 43 |
pip install catboost scikit-learn numpy pandas joblib scipy1import joblib
2import numpy as np
3import pandas as pd
4
5# 1. Load serialized artifacts
6feature_extractor = joblib.load("feature_extractor.pkl")
7classifier = joblib.load("prompt_router.pkl")
8mlb = joblib.load("label_binarizer.pkl")
9thresholds = np.load("thresholds.npy")
10
11def predict_prompt_labels(prompt: str, return_scores: bool = False):
12 # Transform input text into combined TF-IDF + structural feature matrix
13 X = feature_extractor.transform(pd.Series([prompt]))
14
15 # Predict probabilities for each binary classifier in the ensemble
16 probs = np.array(classifier.predict_proba(X))
17 scores = np.array([p[0][1] if np.ndim(p) == 2 else p[1] for p in probs])
18
19 # Apply calibrated decision thresholds
20 predictions = (scores >= thresholds).astype(int)
21
22 # Fallback to top-scoring class if no threshold is met
23 if predictions.sum() == 0:
24 predictions[np.argmax(scores)] = 1
25
26 labels = list(mlb.inverse_transform(predictions.reshape(1, -1))[0])
27
28 if return_scores:
29 score_dict = {label: round(float(score), 4) for label, score in zip(mlb.classes_, scores)}
30 return labels, score_dict
31
32 return labels
33
34# Example usage
35query = "Design a distributed real-time fraud detection pipeline with Apache Flink and Kafka."
36labels, scores = predict_prompt_labels(query, return_scores=True)
37print("Predicted labels:", labels)
38# Output: ['architecture-heavy', 'hard', 'infrastructure', 'interactive', 'long-output', 'premium', 'realtime', 'reasoning-intensive']short-output, medium-output, long-output) before generation to prevent token overspend.language: en).