Spaces:
Sleeping
Sleeping
joshua400 commited on
Commit ยท
6a50d4f
1
Parent(s): 5fdf073
๐ FINAL SUBMISSION: Fair-GRPO-RLVR (Full Truth Overhaul)
Browse files- build_notebook_user.py +3 -10
build_notebook_user.py
CHANGED
|
@@ -110,7 +110,7 @@ code("""# =========================================
|
|
| 110 |
# =========================================
|
| 111 |
def build_prompt(obs):
|
| 112 |
zones_str = '\\n'.join([f"Zone {z.zone_id}: damage={z.damage:.2f}, vulnerable={z.vulnerable_ratio:.2f}" for z in obs.zones])
|
| 113 |
-
return f
|
| 114 |
Prioritize Zone 4 (high damage, high vulnerability) over Zone 0 (low damage).
|
| 115 |
Respond ONLY with a JSON action like: {{"action_type": "analyze", "critical_zones": [4, 3]}}
|
| 116 |
|
|
@@ -119,7 +119,7 @@ Zones:
|
|
| 119 |
{zones_str}
|
| 120 |
Fairness Score: {obs.fairness_score}
|
| 121 |
|
| 122 |
-
What is your next action?
|
| 123 |
|
| 124 |
def parse_action(text, stage):
|
| 125 |
if isinstance(text, list):
|
|
@@ -144,18 +144,15 @@ def reward_fn(prompts, completions, **kwargs):
|
|
| 144 |
rewards = []
|
| 145 |
|
| 146 |
for prompt, output in zip(prompts, completions):
|
| 147 |
-
# 1. Scenario Variation (Curriculum Learning)
|
| 148 |
difficulty = random.choice(["easy", "medium", "hard"])
|
| 149 |
env, obs = reset_env(difficulty=difficulty)
|
| 150 |
|
| 151 |
# FIX: Run the FULL episode using the model's parsed actions.
|
| 152 |
-
# This ensures the model is rewarded for its OWN logic, not a heuristic.
|
| 153 |
action_dict = parse_action(output, obs.step_stage)
|
| 154 |
|
| 155 |
for _ in range(MAX_STEPS):
|
| 156 |
obs = step_env(env, action_dict)
|
| 157 |
if obs.done: break
|
| 158 |
-
# Re-parse from completion for subsequent stages (stage-specific parsing)
|
| 159 |
action_dict = parse_action(output, obs.step_stage)
|
| 160 |
|
| 161 |
# 2. Research-Level Fairness Metric (Inverse Service Disparity)
|
|
@@ -166,7 +163,7 @@ def reward_fn(prompts, completions, **kwargs):
|
|
| 166 |
|
| 167 |
# 3. Multi-objective Components
|
| 168 |
utility = mean_service
|
| 169 |
-
safety = max(0.0, 1.0 - obs.info.get("violations", 0) / 10.0)
|
| 170 |
|
| 171 |
# 4. Total Reward with Curriculum Scaling
|
| 172 |
total = (0.4 * utility + 0.4 * fairness + 0.2 * safety)
|
|
@@ -361,10 +358,6 @@ plt.show()
|
|
| 361 |
code("""# =========================================
|
| 362 |
# 13. SUMMARY
|
| 363 |
# =========================================
|
| 364 |
-
print("\\n=== FINAL RESULTS (Fair-GRPO-RLVR) ===")
|
| 365 |
-
print("๐ง Method: Fair-GRPO-RLVR")
|
| 366 |
-
print("Multi-objective RL with fairness, safety, and utility optimization")
|
| 367 |
-
|
| 368 |
b_r = df['baseline_reward'].mean()
|
| 369 |
t_r = df['trained_reward'].mean()
|
| 370 |
b_f = df['baseline_fairness'].mean()
|
|
|
|
| 110 |
# =========================================
|
| 111 |
def build_prompt(obs):
|
| 112 |
zones_str = '\\n'.join([f"Zone {z.zone_id}: damage={z.damage:.2f}, vulnerable={z.vulnerable_ratio:.2f}" for z in obs.zones])
|
| 113 |
+
return f'''System: You are an AI allocating disaster resources fairly using the Fair-GRPO-RLVR framework.
|
| 114 |
Prioritize Zone 4 (high damage, high vulnerability) over Zone 0 (low damage).
|
| 115 |
Respond ONLY with a JSON action like: {{"action_type": "analyze", "critical_zones": [4, 3]}}
|
| 116 |
|
|
|
|
| 119 |
{zones_str}
|
| 120 |
Fairness Score: {obs.fairness_score}
|
| 121 |
|
| 122 |
+
What is your next action?'''
|
| 123 |
|
| 124 |
def parse_action(text, stage):
|
| 125 |
if isinstance(text, list):
|
|
|
|
| 144 |
rewards = []
|
| 145 |
|
| 146 |
for prompt, output in zip(prompts, completions):
|
|
|
|
| 147 |
difficulty = random.choice(["easy", "medium", "hard"])
|
| 148 |
env, obs = reset_env(difficulty=difficulty)
|
| 149 |
|
| 150 |
# FIX: Run the FULL episode using the model's parsed actions.
|
|
|
|
| 151 |
action_dict = parse_action(output, obs.step_stage)
|
| 152 |
|
| 153 |
for _ in range(MAX_STEPS):
|
| 154 |
obs = step_env(env, action_dict)
|
| 155 |
if obs.done: break
|
|
|
|
| 156 |
action_dict = parse_action(output, obs.step_stage)
|
| 157 |
|
| 158 |
# 2. Research-Level Fairness Metric (Inverse Service Disparity)
|
|
|
|
| 163 |
|
| 164 |
# 3. Multi-objective Components
|
| 165 |
utility = mean_service
|
| 166 |
+
safety = max(0.0, 1.0 - obs.info.get("violations", 0) / 10.0)
|
| 167 |
|
| 168 |
# 4. Total Reward with Curriculum Scaling
|
| 169 |
total = (0.4 * utility + 0.4 * fairness + 0.2 * safety)
|
|
|
|
| 358 |
code("""# =========================================
|
| 359 |
# 13. SUMMARY
|
| 360 |
# =========================================
|
|
|
|
|
|
|
|
|
|
|
|
|
| 361 |
b_r = df['baseline_reward'].mean()
|
| 362 |
t_r = df['trained_reward'].mean()
|
| 363 |
b_f = df['baseline_fairness'].mean()
|