Spaces:
Sleeping
Sleeping
new changes realted to grader 1
Browse filesFiles changed (2)
- openenv.yaml+23-16
- server/app.py+81-1
123456 unmodified lines121314151617181920212223242526272829303132333435363738394041name: SocialStreamModerationEnvversion: 1.0.0graders:- id: basic_safety_graderdescription: "Grader for basic safety checks"6 unmodified linesentry_point: envs.social_stream_moderation.graders:FairnessBiasGradertasks:- id: "Task 1: Basic Safety"difficulty: easydescription: "Moderate a stream of social posts with obvious violations and safe content."grader_id: basic_safety_grader- id: "Task 2: Context & Nuance"difficulty: mediumdescription: "Handle sarcastic content and quotes of harmful material with condemnation."grader_id: context_nuance_grader- id: "Task 3: Fairness & Bias"difficulty: harddescription: "Ensure fairness across user groups and adhere to stricter policy regimes."grader_id: fairness_bias_grader# Legacy aliases used by validate_submission.py- id: clear_cut_moderationdifficulty: easydescription: "Alias for Task 1: Basic Safety"grader_id: basic_safety_grader- id: nuanced_sarcasticdifficulty: mediumdescription: "Alias for Task 2: Context & Nuance"grader_id: context_nuance_grader- id: policy_fairnessdifficulty: harddescription: "Alias for Task 3: Fairness & Bias"grader_id: fairness_bias_graderschemas:123456789101112131415161718192021226 unmodified lines2930313233343536373839404142434445464748name: SocialStreamModerationEnvversion: 1.0.0description: >A content-moderation RL environment where an agent must classify social-mediaposts as safe or harmful under varying policy regimes, with tasks spanningbasic safety, contextual nuance, and fairness.endpoints:reset: /resetstep: /stepstate: /statetasks: /tasksgrader: /gradergraders: /gradershealth: /healthmetadata: /metadataschema: /schemabaseline: /predict_and_stepgraders:- id: basic_safety_graderdescription: "Grader for basic safety checks"6 unmodified linesentry_point: envs.social_stream_moderation.graders:FairnessBiasGradertasks:- id: clear_cut_moderationname: "Task 1: Basic Safety"difficulty: easydescription: "Moderate a stream of social posts with obvious violations and safe content."grader_id: basic_safety_grader- id: nuanced_sarcasticname: "Task 2: Context & Nuance"difficulty: mediumdescription: "Handle sarcastic content and quotes of harmful material with condemnation."grader_id: context_nuance_grader- id: policy_fairnessname: "Task 3: Fairness & Bias"difficulty: harddescription: "Ensure fairness across user groups and adhere to stricter policy regimes."grader_id: fairness_bias_graderschemas:
9 unmodified lines10111213141516752 unmodified lines7697707717727737747757767777787797806 unmodified lines7877887897907917929 unmodified linesfrom enum import Enumfrom envs.social_stream_moderation.environment import SocialStreamModerationEnvfrom envs.social_stream_moderation.models import State, ModerationActionfrom envs.social_stream_moderation.graders import list_graders as _list_graders, get_graderfrom envs.social_stream_moderation.tasks import TASKS# Enums for Swagger Dropdowns752 unmodified linesexcept ValueError as e:raise HTTPException(status_code=400, detail=str(e))@app.get("/tasks", tags=["π€ Automated Benchmarking"])async def list_tasks():"""Returns the list of tasks available in the environment for discovery."""return [{"id": task_cfg.name,"difficulty": task_cfg.difficulty,"description": f"Episode length: {task_cfg.episode_length} posts. Policy mode: {task_cfg.policy_mode.value}.","grader_id": task_cfg.grader_id,6 unmodified lines"""Returns the list of graders available in the environment for discovery."""return _list_graders()@app.post("/evaluate", tags=["π§ͺ Interactive Lab"], summary="Test Model Logic (XAI Insight)")async def evaluate_text(req: EvaluateRequest,9 unmodified lines10111213141516752 unmodified lines7697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388396 unmodified lines8468478488498508518528538548558568578588598608618628638648658668678688698708718729 unmodified linesfrom enum import Enumfrom envs.social_stream_moderation.environment import SocialStreamModerationEnvfrom envs.social_stream_moderation.models import State, ModerationActionfrom envs.social_stream_moderation.graders import list_graders as _list_graders, get_grader, grade_episodefrom envs.social_stream_moderation.tasks import TASKS# Enums for Swagger Dropdowns752 unmodified linesexcept ValueError as e:raise HTTPException(status_code=400, detail=str(e))@app.get("/health", tags=["π System Monitoring"])def health_check():"""Health check endpoint required by OpenEnv runtime validation."""return {"status": "healthy"}@app.get("/metadata", tags=["π System Monitoring"])def metadata():"""Returns environment metadata required by OpenEnv runtime validation."""return {"name": "SocialStreamModerationEnv","description": ("A content-moderation RL environment where an agent must classify ""social-media posts as safe or harmful under varying policy regimes, ""with tasks spanning basic safety, contextual nuance, and fairness."),"version": "1.2.0","tasks": list(TASKS.keys()),}@app.get("/schema", tags=["π System Monitoring"])def schema():"""Returns action, observation, and state schemas for OpenEnv validation."""return {"action": {"type": "string","enum": [a.value for a in ModerationAction],},"observation": {"type": "object","properties": {"post_id": {"type": "string"},"text": {"type": "string"},"user_history_summary": {"type": "string"},"context_type": {"type": "string"},"platform_policy_mode": {"type": "string"},"user_group": {"type": "string"},"step_index": {"type": "integer"},"total_steps": {"type": "integer"},},},"state": {"type": "object","properties": {"post_id": {"type": "string"},"text": {"type": "string"},"context_type": {"type": "string"},"platform_policy_mode": {"type": "string"},"user_group": {"type": "string"},"step_index": {"type": "integer"},"total_steps": {"type": "integer"},},},}@app.get("/tasks", tags=["π€ Automated Benchmarking"])async def list_tasks():"""Returns the list of tasks available in the environment for discovery."""return [{"task_id": task_cfg.name,"id": task_cfg.name,"name": task_cfg.name,"difficulty": task_cfg.difficulty,"description": f"Episode length: {task_cfg.episode_length} posts. Policy mode: {task_cfg.policy_mode.value}.","grader_id": task_cfg.grader_id,6 unmodified lines"""Returns the list of graders available in the environment for discovery."""return _list_graders()@app.get("/grader", tags=["π€ Automated Benchmarking"])def grader_score():"""Returns the grader score for the current (or most recent) episode.The Scaler / OpenEnv hackathon validator calls this endpoint after runningan episode to obtain the final score. If no episode has been run yet aminimal default score is returned."""# Use the environment's last episode info to compute the scoreif env.episode_history:task = env.current_taskif task is not None:grader_inst = get_grader(task.grader_id)score = grader_inst.grade(env.episode_history)else:score = grade_episode(env.episode_history, use_fairness=False)else:score = 0.001return {"score": score}@app.post("/evaluate", tags=["π§ͺ Interactive Lab"], summary="Test Model Logic (XAI Insight)")async def evaluate_text(req: EvaluateRequest,
openenv.yaml+23-16
server/app.py+81-1