Update handler.py
Browse files- handler.py +14 -0
handler.py
CHANGED
|
@@ -140,6 +140,7 @@ class EndpointHandler:
|
|
| 140 |
# Get prediction for this item
|
| 141 |
# Because top_k=20, 'current_preds' is a list of dicts: [{'answer': '...', 'score': ...}, ...]
|
| 142 |
current_preds = predictions[pred_idx]
|
|
|
|
| 143 |
|
| 144 |
# Ensure it is a list
|
| 145 |
if isinstance(current_preds, dict):
|
|
@@ -149,6 +150,19 @@ class EndpointHandler:
|
|
| 149 |
"RECCON raw spans (answer, score): %s",
|
| 150 |
[(p.get("answer"), p.get("score", 0.0), 3) for p in current_preds[:5]]
|
| 151 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
# Extract the answer strings
|
| 154 |
raw_answers = [p.get('answer', '') for p in current_preds]
|
|
|
|
| 140 |
# Get prediction for this item
|
| 141 |
# Because top_k=20, 'current_preds' is a list of dicts: [{'answer': '...', 'score': ...}, ...]
|
| 142 |
current_preds = predictions[pred_idx]
|
| 143 |
+
|
| 144 |
|
| 145 |
# Ensure it is a list
|
| 146 |
if isinstance(current_preds, dict):
|
|
|
|
| 150 |
"RECCON raw spans (answer, score): %s",
|
| 151 |
[(p.get("answer"), p.get("score", 0.0), 3) for p in current_preds[:5]]
|
| 152 |
)
|
| 153 |
+
|
| 154 |
+
best_score = max((p.get("score", 0.0) for p in current_preds), default=0.0)
|
| 155 |
+
|
| 156 |
+
MIN_BEST_SCORE = 0.01 # start here; tune later
|
| 157 |
+
if best_score < MIN_BEST_SCORE:
|
| 158 |
+
results.append({
|
| 159 |
+
"utterance": utterance,
|
| 160 |
+
"emotion": emotion,
|
| 161 |
+
"triggers": [], # no highlight
|
| 162 |
+
"metadata": {"low_confidence": True, "best_score": best_score}
|
| 163 |
+
})
|
| 164 |
+
pred_idx += 1
|
| 165 |
+
continue
|
| 166 |
|
| 167 |
# Extract the answer strings
|
| 168 |
raw_answers = [p.get('answer', '') for p in current_preds]
|