# CACE β€” Cultural Context Arbitration Environment **RL-trained content moderation agent Β· Meta Oversight Board oracle Β· OpenEnv spec** [![Space](https://img.shields.io/badge/πŸ€—%20Demo-hsr99%2Fcace--demo-blue)](https://huggingface.co/spaces/hsr99/cace-demo) [![Model](https://img.shields.io/badge/πŸ€—%20Model-hsr99%2Fcace--final--model-orange)](https://huggingface.co/hsr99/cace-final-model) [![Environment](https://img.shields.io/badge/πŸ€—%20Env-hsr99%2Fcace--env-green)](https://huggingface.co/spaces/hsr99/cace-env) [![Dataset](https://img.shields.io/badge/πŸ€—%20Data-hsr99%2Fcace--data-yellow)](https://huggingface.co/datasets/hsr99/cace-data) --- ## What is CACE? CACE is a reinforcement learning environment for training content moderation agents on culturally ambiguous social media content. It uses Meta's Oversight Board rulings as a verifiable ground truth oracle and implements a three-track deterministic reward across cultural meaning, harm detection, and policy calibration. --- ## Repositories | Repo | Type | Description | |------|------|-------------| | [`hsr99/cace-env`](https://huggingface.co/spaces/hsr99/cace-env) | Space (Docker) | OpenEnv environment server | | [`hsr99/cace-final-model`](https://huggingface.co/hsr99/cace-final-model) | Model | Merged Llama 3.1 8B (SFT + GRPO, FP16) | | [`hsr99/cace-grpo-model`](https://huggingface.co/hsr99/cace-grpo-model) | Model | GRPO LoRA adapters | | [`hsr99/cace-sft-model`](https://huggingface.co/hsr99/cace-sft-model) | Model | SFT LoRA adapters | | [`hsr99/cace-data`](https://huggingface.co/datasets/hsr99/cace-data) | Dataset | master_dataset.json Β· reward_curve.json Β· meta_graph.json | | [`hsr99/cace-demo`](https://huggingface.co/spaces/hsr99/cace-demo) | Space (Gradio) | Live content spread monitor demo | --- ## Environment API The environment follows the OpenEnv spec. Base URL: `https://hsr99-cace-env.hf.space` ### Endpoints ``` GET /health β†’ {"status": "healthy"} POST /reset β†’ observation POST /step β†’ {observation, reward, done, info} ``` ### Reset ```bash curl -X POST https://hsr99-cace-env.hf.space/reset ``` ```json { "observation": { "post_text": "Tugeges wote ni hao", "language": "Swahili", "region": "KE", "cultural_context": "...", "adversarial_challenge": "...", "policy_anchor": "..." } } ``` ### Step ```bash curl -X POST https://hsr99-cace-env.hf.space/step \ -H "Content-Type: application/json" \ -d '{"action": {"action_int": 0, "selected_indices": [0]}}' ``` ```json { "observation": { ... }, "reward": 0.37, "done": false, "info": { "decision": "ALLOW", "ground_truth": "ALLOW", "reward_breakdown": { "t1_cultural": 72.0, "t2_harm": 45.0, "t3_policy": 60.0, "combined": 0.37 } } } ``` ### Action Space | action_int | Decision | |-----------|---------| | 0 | `ALLOW` | | 1 | `ALLOW_WITH_LABEL` | | 2 | `RESTRICT_DISTRIBUTION` | | 3 | `ESCALATE` | | 4 | `REMOVE` | --- ## Reward Function ``` R = 0.40 Γ— T1 + 0.35 Γ— T2 + 0.25 Γ— T3 ∈ [-1.0, +1.0] ``` | Track | Weight | Signal | |-------|--------|--------| | T1 β€” Cultural Meaning | 40% | Correct identification of cultural legitimacy vs. weaponisation | | T2 β€” Harm Detection | 35% | Correct harm assessment β€” asymmetric penalty for missed removals | | T3 β€” Policy Calibration | 25% | Right level of intervention β€” partial credit within Β±1 severity step | Fully deterministic. No LLM judge. --- ## Dataset **960 unified cases** across three sources: | Source | Cases | Notes | |--------|-------|-------| | Meta Oversight Board | 160 | Manually extracted, enriched via Azureβ†’Cerebras pipeline | | tweet_eval (hate speech) | 400 | Multilingual | | HatEval | 400 | English + Spanish | Enrichment pipeline: `GPT-3.5-turbo (Azure)` β†’ `llama3.1-8b (Cerebras)` β†’ cached to `pipeline_cache.json` (1,452 entries). Dataset files on [`hsr99/cace-data`](https://huggingface.co/datasets/hsr99/cace-data): ``` master_dataset.json β€” 960 unified cases final_sft_dataset.jsonl β€” 1,052 SFT training examples pipeline_cache.json β€” enrichment cache reward_curve.json β€” 120 parsed GRPO training steps meta_graph.json β€” Facebook WOSN subgraph (3,000 nodes, 288K edges) ``` --- ## Training ### Stage 1 β€” SFT ``` Base model : Llama 3.1 8B Examples : 1,052 Loss : 1.897 β†’ 0.469 Adapter : hsr99/cace-sft-model ``` ### Stage 2 β€” GRPO ``` Steps : 300 LR : 5e-5 Max steps : 300 Env : hsr99/cace-env (OpenEnv, A10G) Adapter : hsr99/cace-grpo-model Merged : hsr99/cace-final-model (FP16, save_pretrained_merged) ``` ### Run Inference ```python from transformers import AutoTokenizer, AutoModelForCausalLM import torch model_id = "hsr99/cace-final-model" tokenizer = AutoTokenizer.from_pretrained(model_id) model = AutoModelForCausalLM.from_pretrained( model_id, device_map="auto", torch_dtype=torch.float16 ) device = next(model.parameters()).device prompt = """You are a content moderation decision agent. ===== CASE ===== POST: Tugeges wote ni hao LANGUAGE: Swahili | REGION: KE ===== DECISION ===== Choose ONE: ALLOW | REMOVE | ALLOW_WITH_LABEL | ESCALATE | RESTRICT_DISTRIBUTION Decision:""" inputs = tokenizer(prompt, return_tensors="pt").to(device) with torch.no_grad(): out = model.generate(**inputs, max_new_tokens=20, temperature=0.1, do_sample=True) print(tokenizer.decode(out[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True)) ``` ## File Structure (training) ``` Master Codebase -> https://github.com/sannidhayj20/Meta-finale.git ``` ``` cace/ β”œβ”€β”€ data/ β”‚ β”œβ”€β”€ oversight_cases_1.json # 160 OB cases β”‚ β”œβ”€β”€ master_dataset.json # 960 unified cases β”‚ β”œβ”€β”€ pipeline_cache.json # enrichment cache β”‚ └── final_sft_dataset.jsonl # SFT examples β”œβ”€β”€ scripts/ β”‚ β”œβ”€β”€ precompute_pipeline.py # Azure β†’ Cerebras enrichment β”‚ └── build_unified_dataset.py β”œβ”€β”€ training/ β”‚ β”œβ”€β”€ train_sft.py β”‚ β”œβ”€β”€ train_grpo_openenv.py β”‚ └── merge_and_push.py └── cace_env/ β”œβ”€β”€ server.py # OpenEnv server β”œβ”€β”€ pipeline.py # inference pipeline β”œβ”€β”€ reward.py # 3-track reward β”œβ”€β”€ dataset.py └── models.py ```