Download alea/envs/base.py from Akahsizrr/alea-runs: direct link, hf CLI and curl.
- Browser
- Download file 2.48 kB
-
https://huggingface.co/datasets/Akahsizrr/alea-runs/resolve/a1deb2f2d09f5e3aaf53931fad57728c8ff3ae2e/alea/envs/base.py
- Command line
-
hf download hf://datasets/Akahsizrr/alea-runs@a1deb2f2d09f5e3aaf53931fad57728c8ff3ae2e/alea/envs/base.py
-
curl -L -o base.py https://huggingface.co/datasets/Akahsizrr/alea-runs/resolve/a1deb2f2d09f5e3aaf53931fad57728c8ff3ae2e/alea/envs/base.py
2.48 kB
| """DecisionEnv protocol for Alea RL environments. | |
| Every env produces a stream of DECISION POINTS. At each one it emits a | |
| (state_text, questions) observation in Alea's packed-request format, the | |
| policy answers, and the env scores it. | |
| Two reward modes, env-dependent: | |
| - "dense": env.action_rewards() returns an exact per-action reward vector | |
| (regret-normalized so the optimal action = 1.0). GRPO samples k actions | |
| and scores each exactly — no rollout branching needed. | |
| - "outcome": env.step() returns only the realized scalar reward; terminal | |
| returns are assigned to every decision in the episode (GRPO over k | |
| full-episode trajectories via clone()). | |
| An env may also emit REPORT questions (score/regress/noul with exact | |
| targets — e.g., "what is your belief over hidden states?") alongside the | |
| action question. Report targets come from oracle_targets() and are scored | |
| with the supervised proper-scoring losses — a variance-free calibration | |
| signal no generative model can match. | |
| """ | |
| from __future__ import annotations | |
| import copy | |
| from dataclasses import dataclass | |
| from ..packing import QuestionSpec | |
| ACT_QID = "act" | |
| class Decision: | |
| """One decision point.""" | |
| state: str # text/JSON the model reads | |
| questions: list # [QuestionSpec]; must contain qid=ACT_QID | |
| n_legal: int # how many leading options are legal | |
| class DecisionEnv: | |
| """Base class. Subclasses implement reset/observe/step.""" | |
| name = "base" | |
| dense = False # True -> action_rewards() available | |
| def reset(self, rng): | |
| raise NotImplementedError | |
| def observe(self) -> Decision: | |
| """Current state + questions. questions[0] must be the action | |
| question (qid=ACT_QID); its options are the action labels.""" | |
| raise NotImplementedError | |
| def action_rewards(self): | |
| """Dense mode only: exact reward per legal action, normalized so | |
| max == 1.0 (optimal). Return None if unavailable.""" | |
| return None | |
| def oracle_targets(self) -> dict: | |
| """Exact targets for REPORT questions (qid -> target), and optionally | |
| the optimal action distribution under key ACT_QID.""" | |
| return {} | |
| def step(self, action_idx: int): | |
| """Apply action -> (reward, done).""" | |
| raise NotImplementedError | |
| def clone(self): | |
| return copy.deepcopy(self) | |
| def done(self): | |
| return self._done | |