Dhrona1421/multimodal-content-moderation
0
1"""2tasks.py — Task registry and factory for the Content Moderation Environment.3"""4from __future__ import annotations5from typing import Any, Dict6from env import ContentModerationEnv7 8TASKS: Dict[str, Dict[str, Any]] = {9 "easy": {10 "name": "Easy Moderation",11 "description": (12 "Obvious cases only. All modality signals align. "13 "Strong keyword-matching baselines score well here."14 ),15 "difficulty": "easy",16 "max_steps": 12,17 "reward_range": [0.0001, 0.9999],18 "dataset_subset": "12 sampled from 14 easy posts",19 "expected_baseline_score": 0.88,20 },21 "medium": {22 "name": "Intermediate Moderation",23 "description": (24 "Contextual reasoning required. Coded hate speech, "25 "health misinformation, trust-level signals matter."26 ),27 "difficulty": "medium",28 "max_steps": 12,29 "reward_range": [0.0001, 0.9999],30 "dataset_subset": "12 sampled from 13 medium posts",31 "expected_baseline_score": 0.68,32 },33 "hard": {34 "name": "Expert Moderation",35 "description": (36 "Adversarial edge cases with conflicting signals: "37 "safe text + harmful image, trusted users spreading misinfo, "38 "suspicious users with innocent content."39 ),40 "difficulty": "hard",41 "max_steps": 12,42 "reward_range": [0.0001, 0.9999],43 "dataset_subset": "12 sampled from 14 hard posts",44 "expected_baseline_score": 0.52,45 },46}47 48 49def make_task(50 task_name: str,51 dataset_path: str = "moderation_dataset.json",52 seed: int = 42,53) -> ContentModerationEnv:54 if task_name not in TASKS:55 raise ValueError(f"Unknown task '{task_name}'. Available: {list(TASKS.keys())}")56 cfg = TASKS[task_name]57 return ContentModerationEnv(58 dataset_path=dataset_path,59 task=cfg["difficulty"],60 max_steps=cfg["max_steps"],61 seed=seed,62 )63 64 65def list_tasks() -> Dict[str, Dict[str, Any]]:66 return {name: dict(cfg) for name, cfg in TASKS.items()}67 68 69def describe_task(task_name: str) -> str:70 if task_name not in TASKS:71 raise ValueError(f"Unknown task '{task_name}'.")72 cfg = TASKS[task_name]73 return (74 f"Task : {cfg['name']}\n"75 f"Difficulty : {cfg['difficulty'].upper()}\n"76 f"Max Steps : {cfg['max_steps']}\n"77 f"Dataset : {cfg['dataset_subset']}\n"78 f"Reward : {cfg['reward_range']}\n"79 f"Description : {cfg['description']}\n"80 )81 82 83if __name__ == "__main__":84 for name in TASKS:85 print(describe_task(name))86 print()87 