Spaces:
Sleeping
Sleeping
Commit ·
888871f
1
Parent(s): e15627e
Fix score - shift rewards to positive range, never 0.0 or 1.0
Browse files- inference.py +9 -6
inference.py
CHANGED
|
@@ -223,27 +223,30 @@ def run_episode(client: OpenAI, difficulty: str, task_id: str) -> dict:
|
|
| 223 |
break
|
| 224 |
|
| 225 |
# Score strictly between 0 and 1 exclusive
|
|
|
|
| 226 |
if rewards:
|
| 227 |
-
|
| 228 |
-
|
|
|
|
| 229 |
else:
|
| 230 |
-
raw_score = 0.
|
| 231 |
|
| 232 |
score = max(0.001, min(0.999, raw_score))
|
| 233 |
success = score >= SUCCESS_SCORE_THRESHOLD
|
| 234 |
|
| 235 |
except Exception as e:
|
| 236 |
print(f"[DEBUG] Episode error: {e}", flush=True)
|
| 237 |
-
score = 0.
|
| 238 |
success = False
|
| 239 |
|
| 240 |
finally:
|
|
|
|
|
|
|
| 241 |
log_end(
|
| 242 |
success = success,
|
| 243 |
steps = steps,
|
| 244 |
-
rewards =
|
| 245 |
)
|
| 246 |
-
|
| 247 |
return {
|
| 248 |
"task_id": task_id,
|
| 249 |
"difficulty": difficulty,
|
|
|
|
| 223 |
break
|
| 224 |
|
| 225 |
# Score strictly between 0 and 1 exclusive
|
| 226 |
+
# Score strictly between 0 and 1 exclusive — never 0.0 or 1.0
|
| 227 |
if rewards:
|
| 228 |
+
# Shift all rewards to positive range first
|
| 229 |
+
shifted = [max(0.01, r + 0.5) for r in rewards]
|
| 230 |
+
raw_score = sum(shifted) / len(shifted)
|
| 231 |
else:
|
| 232 |
+
raw_score = 0.5
|
| 233 |
|
| 234 |
score = max(0.001, min(0.999, raw_score))
|
| 235 |
success = score >= SUCCESS_SCORE_THRESHOLD
|
| 236 |
|
| 237 |
except Exception as e:
|
| 238 |
print(f"[DEBUG] Episode error: {e}", flush=True)
|
| 239 |
+
score = 0.5
|
| 240 |
success = False
|
| 241 |
|
| 242 |
finally:
|
| 243 |
+
# Ensure rewards list for log_end is never empty and never contains 0.0
|
| 244 |
+
safe_rewards = [max(0.01, r + 0.5) for r in rewards] if rewards else [0.5]
|
| 245 |
log_end(
|
| 246 |
success = success,
|
| 247 |
steps = steps,
|
| 248 |
+
rewards = safe_rewards
|
| 249 |
)
|
|
|
|
| 250 |
return {
|
| 251 |
"task_id": task_id,
|
| 252 |
"difficulty": difficulty,
|