heavycoderhh commited on
Commit
c01f14d
·
verified ·
1 Parent(s): d6d0e0f

Restore Space README metadata

Browse files
Files changed (1) hide show
  1. README.md +332 -17
README.md CHANGED
@@ -1,25 +1,340 @@
1
- # Counsel-Env
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- Counsel-Env is an OpenEnv courtroom environment where an LLM learns to cross-examine a deterministic witness: make the witness commit to a claim, then present the exhibit that proves the claim false.
4
 
5
- Public submission links:
6
 
7
- - Hugging Face Space: https://huggingface.co/spaces/heavycoderhh/counsel-env
8
- - Live demo: https://heavycoderhh-counsel-env.hf.space/demo
9
- - Official checkpoint: https://huggingface.co/heavycoderhh/counsel-env-qwen3-8b-qlora-sft-run4b
10
- - Expanded 150-seed eval: https://huggingface.co/heavycoderhh/counsel-env-qwen3-8b-qlora-sft-run4b/tree/main/eval_150
11
 
12
- Start with the full Space README here:
 
 
13
 
14
- - [counsel_env/README.md](counsel_env/README.md)
15
 
16
- Submission evidence:
17
 
18
- - [SUBMISSION.md](SUBMISSION.md)
19
- - [counsel_env/BENCHMARKS.md](counsel_env/BENCHMARKS.md)
20
- - [counsel_env/TRAINING_PROOF.md](counsel_env/TRAINING_PROOF.md)
21
- - [counsel_env/EVAL150_STATUS.md](counsel_env/EVAL150_STATUS.md)
22
- - [assets/demo/blog_draft.md](assets/demo/blog_draft.md)
23
- - [assets/demo/video_script.md](assets/demo/video_script.md)
24
 
25
- Key result: run4b reaches `0.864` average reward and `0.943` primary/surface rate on the expanded 150-seed evaluation, with zero invalid tool calls.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: "Counsel Env: Cross-Examination Arena"
3
+ emoji: "⚖️"
4
+ colorFrom: indigo
5
+ colorTo: yellow
6
+ sdk: docker
7
+ pinned: false
8
+ app_port: 8000
9
+ base_path: /web
10
+ tags:
11
+ - openenv
12
+ - rl
13
+ - multi-agent
14
+ - theory-of-mind
15
+ - adversarial-dialogue
16
+ - procgen
17
+ models:
18
+ - heavycoderhh/counsel-env-qwen3-8b-qlora-sft-run4b
19
+ - Qwen/Qwen3-8B
20
+ ---
21
 
22
+ # Cross-Examination Arena
23
 
24
+ We built a courtroom where an LLM learns to catch lies under a question budget.
25
 
26
+ Counsel-Env trains an agent to act like a sharper trial lawyer: make a deterministic witness commit to a claim, then present the exhibit that proves the claim false. It is built for OpenEnv and GRPO-style post-training on multi-agent, partially observable dialogue.
 
 
 
27
 
28
+ > Baseline behavior: vague questions, early evidence, zero reward.
29
+ >
30
+ > Target behavior: trigger sealed claim, present matching exhibit, surface contradiction.
31
 
32
+ ## Try It Now
33
 
34
+ Open the live Space demo:
35
 
36
+ ```text
37
+ https://heavycoderhh-counsel-env.hf.space/demo
38
+ ```
 
 
 
39
 
40
+ What to try:
41
+
42
+ 1. Reset an easy case.
43
+ 2. Ask the witness the oracle-hint question to make them commit to a sealed claim.
44
+ 3. Present the hinted exhibit.
45
+ 4. Rest the case and watch primary reward appear.
46
+
47
+ The hint is intentionally exposed for the demo. The training task is to make a model learn that sequence from observations, evidence descriptions, and reward.
48
+
49
+ Judge-facing cards included in this Space:
50
+
51
+ - [`BENCHMARKS.md`](BENCHMARKS.md): held-out baseline and reward-hacking audit.
52
+ - [`DEMO_SCRIPT.md`](DEMO_SCRIPT.md): 90-second video script and shot list.
53
+ - [`TRAINING_PROOF.md`](TRAINING_PROOF.md): tiny GRPO dry-run path with spend guardrails.
54
+ - [`assets/demo/blog_draft.md`](assets/demo/blog_draft.md): mini-blog draft ready to publish.
55
+ - [`assets/training_curves/run4b_training_loss.png`](assets/training_curves/run4b_training_loss.png): real run4b training loss plot from HF job logs.
56
+ - [`assets/training_curves/run4b_eval_rewards.png`](assets/training_curves/run4b_eval_rewards.png): trained-vs-baseline reward plot.
57
+
58
+ ## Why This Is Hard
59
+
60
+ The agent must track another actor's commitments. Presenting evidence too early fails; asking generic questions fails; keyword spam can trigger a claim but does not prove anything. Reward only becomes strong when the agent sequences the cross-examination correctly.
61
+
62
+ ```mermaid
63
+ flowchart LR
64
+ A[Procgen Case Generator] --> B[Deterministic Witness]
65
+ B --> C[Agent Tools]
66
+ C --> D[Transcript + State Tracker]
67
+ D --> E[Weighted Reward Rubric]
68
+ E --> F[GRPO Training Loop]
69
+ ```
70
+
71
+ ## Environment Design
72
+
73
+ Each episode is a procedurally generated case with:
74
+
75
+ - a public case brief
76
+ - deterministic witness story
77
+ - hidden contradiction objects
78
+ - evidence exhibits with descriptions visible to the agent
79
+ - a 15-question budget
80
+ - replayable seeds for before/after evaluation
81
+
82
+ A contradiction is surfaced only when both steps happen in order:
83
+
84
+ 1. The agent asks a trigger question and the witness gives a sealed claim.
85
+ 2. The agent presents the matching disprover exhibit.
86
+
87
+ The witness is deterministic by design. That keeps reward verification fast, cheap, reproducible, and non-LLM-judged.
88
+
89
+ ## Actions
90
+
91
+ | Tool | Field | Purpose |
92
+ | --- | --- | --- |
93
+ | `ask_question` | `text` | Ask the witness a question. |
94
+ | `present_evidence` | `exhibit_id` | Present an exhibit from `available_evidence`. |
95
+ | `make_objection` | `reason` | Currently penalized unless an objection window exists. |
96
+ | `rest_case` | none | End the episode and receive final reward. |
97
+
98
+ ## Reward
99
+
100
+ Primary reward remains binary per contradiction:
101
+
102
+ ```text
103
+ primary_reward = contradictions_surfaced / contradictions_total
104
+ ```
105
+
106
+ Auxiliary shaping reduces sparsity while staying secondary:
107
+
108
+ ```text
109
+ auxiliary =
110
+ +0.2 * contradictions_triggered
111
+ +0.1 * trigger_keyword_questions
112
+ +0.1 * correctly_timed_evidence
113
+ -0.05 * duplicate_or_irrelevant_questions
114
+ -0.05 * blind_evidence
115
+ -0.1 * inadmissible_actions
116
+
117
+ total_reward = 0.8 * primary_reward + 0.2 * auxiliary
118
+ ```
119
+
120
+ Diagnostics log primary, auxiliary, and total reward separately.
121
+
122
+ ## Reward-Hacking Audit
123
+
124
+ The expanded evaluator compares four baselines plus the trained checkpoint across 150 deterministic seeds:
125
+
126
+ | Agent | Avg Reward | Primary Reward | Trigger Rate | Surface Rate |
127
+ | --- | ---: | ---: | ---: | ---: |
128
+ | random | 0.000 | 0.000 | 0.000 | 0.000 |
129
+ | keyword_spam | 0.066 | 0.000 | 0.650 | 0.000 |
130
+ | present_all | 0.000 | 0.000 | 0.000 | 0.000 |
131
+ | trained_qwen3_8b_qlora_sft_run4b_eval150 | 0.864 | 0.943 | 0.943 | 0.943 |
132
+ | scripted_oracle | 0.901 | 0.957 | 0.957 | 0.957 |
133
+
134
+ This shows the obvious hacks do not get primary reward: keyword spam can trigger claims, and present-all can burn exhibits, but neither surfaces contradictions.
135
+
136
+ The trained run4b checkpoint (`heavycoderhh/counsel-env-qwen3-8b-qlora-sft-run4b`) uses `Qwen/Qwen3-8B` with 4-bit QLoRA SFT and assistant-only oracle next-action labels. It surfaces contradictions on held-out cases much more reliably than run 3, while staying below the scripted oracle ceiling.
137
+
138
+ The 150-seed expansion also breaks the trained score down by difficulty: easy primary/surface `1.000`, medium `0.903`, hard `0.939`, with `0` invalid tool calls. That diagnosis does not justify spending credits on run4c yet; medium is the weakest slice, but still comfortably above the submission target.
139
+
140
+ The same benchmark table is embedded in the live demo so judges can see the failure modes without cloning the repo.
141
+
142
+ ## Training Evidence
143
+
144
+ Run4b was a real 4-bit QLoRA SFT run on `Qwen/Qwen3-8B`, launched as Hugging Face job `69edb014d2c8bd8662bcf5ba`. It trained on 1,460 assistant-only next-action rows generated from the environment curriculum and uploaded the PEFT adapter to `heavycoderhh/counsel-env-qwen3-8b-qlora-sft-run4b`.
145
+
146
+ ![Run4b training loss](assets/training_curves/run4b_training_loss.png)
147
+
148
+ The logged SFT loss dropped rapidly during the 220-step run; final `train_loss` was `0.0565` with runtime `1287.7s`.
149
+
150
+ ![Run4b held-out reward](assets/training_curves/run4b_eval_rewards.png)
151
+
152
+ The reward plot compares the trained checkpoint against random, keyword-spam, present-all, the previous run3 checkpoint, and the scripted oracle.
153
+
154
+ ## Demo Walkthrough
155
+
156
+ The fastest way to understand the environment is the same-seed demo:
157
+
158
+ ```text
159
+ assets/demo/demo_case.md
160
+ assets/transcripts/before_after_pairs.md
161
+ ```
162
+
163
+ In the demo case, the random baseline presents timestamped surveillance evidence before the witness has committed to a false time, so the witness gives no useful reaction. The successful strategy first asks about time, gets the witness to claim the assault happened at the wrong hour, then presents the timestamped footage.
164
+
165
+ That sequence is the capability we want training to amplify.
166
+
167
+ ## Curriculum
168
+
169
+ `generate_case()` supports:
170
+
171
+ - `difficulty="easy"`: 1 contradiction, obvious trigger language
172
+ - `difficulty="medium"`: 2 contradictions, overlapping trigger language
173
+ - `difficulty="hard"`: 3+ contradictions, distractor evidence
174
+ - `curriculum_stage` and custom sampling distributions
175
+
176
+ ## Local Validation
177
+
178
+ From the repo root:
179
+
180
+ ```bash
181
+ python pre_hf_validate.py
182
+ python -m pytest -p no:cacheprovider -q
183
+ ```
184
+
185
+ Latest local result:
186
+
187
+ ```text
188
+ 21 passed
189
+ ```
190
+
191
+ The preflight also checks local FastAPI + WebSocket reset/step/state, Docker-style imports, notebook credit guards, rollout diagnostics, and held-out evaluation artifacts.
192
+
193
+ ## Diagnostics
194
+
195
+ Generate a no-credit local diagnostic sample:
196
+
197
+ ```bash
198
+ python -m counsel_env.server.diagnostics
199
+ ```
200
+
201
+ Generate held-out baseline artifacts:
202
+
203
+ ```bash
204
+ python scripts/run_local_eval.py --episodes 30 --output-dir assets
205
+ ```
206
+
207
+ Outputs:
208
+
209
+ - `assets/heldout_eval.jsonl`
210
+ - `assets/heldout_eval_summary.json`
211
+ - `assets/plots/baseline_vs_oracle.svg`
212
+ - `assets/plots/rubric_breakdown.svg`
213
+ - `assets/transcripts/before_after_pairs.md`
214
+ - `assets/demo/demo_case.md`
215
+ - `assets/demo/video_script.md`
216
+ - `assets/demo/blog_draft.md`
217
+
218
+ ## Training
219
+
220
+ The notebook is at:
221
+
222
+ ```text
223
+ counsel_env/notebooks/train_counsel.ipynb
224
+ ```
225
+
226
+ It is credit-safe by default:
227
+
228
+ - `RUN_TRAINING=0`
229
+ - `push_to_hub=False`
230
+ - `report_to="none"`
231
+
232
+ GRPO exploration settings:
233
+
234
+ - `num_generations=6`
235
+ - `temperature=0.8`
236
+ - `top_p=0.95`
237
+ - `max_completion_length=1024`
238
+
239
+ Tiny approved dry-run mode:
240
+
241
+ ```bash
242
+ RUN_TRAINING=1 COUNSEL_MODEL=Qwen/Qwen3-0.6B COUNSEL_MAX_STEPS=5 COUNSEL_DATASET_SIZE=12
243
+ ```
244
+
245
+ Fast 8B QLoRA SFT path used for the current best checkpoint:
246
+
247
+ ```bash
248
+ COUNSEL_MODEL=Qwen/Qwen3-8B \
249
+ COUNSEL_ARTIFACT_REPO=heavycoderhh/counsel-env-qwen3-8b-qlora-sft-run4b \
250
+ COUNSEL_SFT_DATASET_SIZE=480 \
251
+ COUNSEL_SFT_MAX_STEPS=220 \
252
+ COUNSEL_MAX_SFT_LENGTH=1536 \
253
+ COUNSEL_SFT_LEARNING_RATE=1e-4 \
254
+ COUNSEL_LORA_R=16 \
255
+ COUNSEL_LORA_ALPHA=32 \
256
+ COUNSEL_GRAD_ACCUM=4 \
257
+ COUNSEL_INCLUDE_REST_ROWS=0 \
258
+ python counsel_env/scripts/run_qlora_sft_training_job.py
259
+ ```
260
+
261
+ The repo also includes TRL GRPO training paths that connect to the live OpenEnv server instead of a static-only dataset:
262
+
263
+ ```text
264
+ counsel_env/scripts/run_grpo_training_job.py
265
+ counsel_env/scripts/run_sft_grpo_training_job.py
266
+ ```
267
+
268
+ Run3 used the SFT+GRPO path as an ablation, and run4b is the stronger official checkpoint.
269
+
270
+ The current Space deployment does not start a paid GPU job. Before running remote training, approve the spend. Estimated costs:
271
+
272
+ - A10G dry run: about `$0.50`
273
+ - Full A100 GRPO run: about `$6-$10`
274
+
275
+ Published training artifact:
276
+
277
+ ```text
278
+ https://huggingface.co/heavycoderhh/counsel-env-qwen3-8b-qlora-sft-run4b
279
+ ```
280
+
281
+ Held-out evaluation artifacts are in:
282
+
283
+ ```text
284
+ https://huggingface.co/heavycoderhh/counsel-env-qwen3-8b-qlora-sft-run4b/tree/main/eval
285
+ https://huggingface.co/heavycoderhh/counsel-env-qwen3-8b-qlora-sft-run4b/tree/main/eval_150
286
+ ```
287
+
288
+ The same trained eval files are mirrored locally for offline review:
289
+
290
+ ```text
291
+ assets/trained_eval/trained_eval_rows.csv
292
+ assets/trained_eval/trained_eval_rows.jsonl
293
+ assets/trained_eval/trained_eval_summary.json
294
+ assets/trained_eval/trained_eval_transcripts.md
295
+ assets/trained_eval_run3/trained_eval_rows.csv
296
+ assets/trained_eval_run3/trained_eval_rows.jsonl
297
+ assets/trained_eval_run3/trained_eval_summary.json
298
+ assets/trained_eval_run3/trained_eval_transcripts.md
299
+ assets/trained_eval_run4b_8b_sft/eval/trained_eval_rows.csv
300
+ assets/trained_eval_run4b_8b_sft/eval/trained_eval_rows.jsonl
301
+ assets/trained_eval_run4b_8b_sft/eval/trained_eval_summary.json
302
+ assets/trained_eval_run4b_8b_sft/eval/trained_eval_transcripts.md
303
+ assets/trained_eval_run4b_8b_sft/training_summary.json
304
+ assets/trained_eval_run4b_8b_sft_eval150/eval_150/trained_eval_rows.csv
305
+ assets/trained_eval_run4b_8b_sft_eval150/eval_150/trained_eval_rows.jsonl
306
+ assets/trained_eval_run4b_8b_sft_eval150/eval_150/trained_eval_summary.json
307
+ assets/trained_eval_run4b_8b_sft_eval150/eval_150/trained_eval_expanded_summary.json
308
+ assets/trained_eval_run4b_8b_sft_eval150/eval_150/trained_eval_transcripts.md
309
+ ```
310
+
311
+ ## Run Server Locally
312
+
313
+ ```bash
314
+ uvicorn counsel_env.server.app:app --host 0.0.0.0 --port 8000
315
+ ```
316
+
317
+ Client example:
318
+
319
+ ```python
320
+ from counsel_env import CounselAction, CounselEnv
321
+
322
+ with CounselEnv(base_url="http://localhost:8000").sync() as client:
323
+ result = client.reset(curriculum_stage="easy")
324
+ print(result.observation.case_brief)
325
+
326
+ result = client.step(CounselAction(tool="ask_question", text="Where were you that night?"))
327
+ print(result.observation.witness_response)
328
+ ```
329
+
330
+ ## Limitations
331
+
332
+ - The witness is rule-based, intentionally, so reward is verifiable and cheap.
333
+ - Cases are template-generated rather than open-domain.
334
+ - The environment models adversarial questioning mechanics, not full legal procedure.
335
+
336
+ Future work: self-play witness training, civil deposition templates, jurisdiction-specific admissibility rules, and larger trained-vs-baseline model ablations.
337
+
338
+ ## Status
339
+
340
+ The Hugging Face Space is deployed on free `cpu-basic` hardware with the live demo and OpenEnv API. Local validation passes. A trained Qwen3-8B QLoRA SFT checkpoint and held-out evaluation are published on Hugging Face, and the final video/blog scripts are prepared under `assets/demo/`.