Spaces:
Sleeping
Sleeping
Merge pull request #2 from Gamucopia-Creatives/feature/new-changes
Browse files
envs/social_stream_moderation/environment.py
CHANGED
|
@@ -3,7 +3,7 @@ import os
|
|
| 3 |
import random
|
| 4 |
from typing import List, Dict, Any, Tuple, Optional
|
| 5 |
from .models import HarmLabel, ModerationAction, State, PolicyMode, Post, UserGroup
|
| 6 |
-
from .tasks import TASKS, TaskConfig
|
| 7 |
from .graders import compute_per_post_reward, grade_episode, get_grader
|
| 8 |
|
| 9 |
class SocialStreamModerationEnv:
|
|
@@ -30,10 +30,10 @@ class SocialStreamModerationEnv:
|
|
| 30 |
if seed is not None:
|
| 31 |
random.seed(seed)
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
| 34 |
raise ValueError(f"Task {task_name} not found in TASKS.")
|
| 35 |
-
|
| 36 |
-
self.current_task = TASKS[task_name]
|
| 37 |
data_path = os.path.join(self.data_dir, self.current_task.data_file)
|
| 38 |
|
| 39 |
with open(data_path, "r") as f:
|
|
|
|
| 3 |
import random
|
| 4 |
from typing import List, Dict, Any, Tuple, Optional
|
| 5 |
from .models import HarmLabel, ModerationAction, State, PolicyMode, Post, UserGroup
|
| 6 |
+
from .tasks import TASKS, TaskConfig, resolve_task
|
| 7 |
from .graders import compute_per_post_reward, grade_episode, get_grader
|
| 8 |
|
| 9 |
class SocialStreamModerationEnv:
|
|
|
|
| 30 |
if seed is not None:
|
| 31 |
random.seed(seed)
|
| 32 |
|
| 33 |
+
try:
|
| 34 |
+
self.current_task = resolve_task(task_name)
|
| 35 |
+
except KeyError:
|
| 36 |
raise ValueError(f"Task {task_name} not found in TASKS.")
|
|
|
|
|
|
|
| 37 |
data_path = os.path.join(self.data_dir, self.current_task.data_file)
|
| 38 |
|
| 39 |
with open(data_path, "r") as f:
|
envs/social_stream_moderation/tasks.py
CHANGED
|
@@ -40,3 +40,22 @@ TASKS = {
|
|
| 40 |
grader_id="fairness_bias_grader"
|
| 41 |
)
|
| 42 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
grader_id="fairness_bias_grader"
|
| 41 |
)
|
| 42 |
}
|
| 43 |
+
|
| 44 |
+
# Legacy aliases used by validate_submission.py and inference.py CLI.
|
| 45 |
+
# Kept in a separate dict so that TASKS.values() only yields the 3 canonical
|
| 46 |
+
# entries (avoids duplicates in the /tasks API endpoint).
|
| 47 |
+
TASK_ALIASES = {
|
| 48 |
+
"clear_cut_moderation": "Task 1: Basic Safety",
|
| 49 |
+
"nuanced_sarcastic": "Task 2: Context & Nuance",
|
| 50 |
+
"policy_fairness": "Task 3: Fairness & Bias",
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def resolve_task(name: str) -> TaskConfig:
|
| 55 |
+
"""Look up a task by canonical name or legacy alias."""
|
| 56 |
+
if name in TASKS:
|
| 57 |
+
return TASKS[name]
|
| 58 |
+
canonical = TASK_ALIASES.get(name)
|
| 59 |
+
if canonical and canonical in TASKS:
|
| 60 |
+
return TASKS[canonical]
|
| 61 |
+
raise KeyError(f"Unknown task: {name}")
|
openenv.yaml
CHANGED
|
@@ -24,6 +24,19 @@ tasks:
|
|
| 24 |
difficulty: hard
|
| 25 |
description: "Ensure fairness across user groups and adhere to stricter policy regimes."
|
| 26 |
grader_id: fairness_bias_grader
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
schemas:
|
| 29 |
state:
|
|
|
|
| 24 |
difficulty: hard
|
| 25 |
description: "Ensure fairness across user groups and adhere to stricter policy regimes."
|
| 26 |
grader_id: fairness_bias_grader
|
| 27 |
+
# Legacy aliases used by validate_submission.py
|
| 28 |
+
- id: clear_cut_moderation
|
| 29 |
+
difficulty: easy
|
| 30 |
+
description: "Alias for Task 1: Basic Safety"
|
| 31 |
+
grader_id: basic_safety_grader
|
| 32 |
+
- id: nuanced_sarcastic
|
| 33 |
+
difficulty: medium
|
| 34 |
+
description: "Alias for Task 2: Context & Nuance"
|
| 35 |
+
grader_id: context_nuance_grader
|
| 36 |
+
- id: policy_fairness
|
| 37 |
+
difficulty: hard
|
| 38 |
+
description: "Alias for Task 3: Fairness & Bias"
|
| 39 |
+
grader_id: fairness_bias_grader
|
| 40 |
|
| 41 |
schemas:
|
| 42 |
state:
|