Siddh12334 commited on
Commit
86ab1d8
·
1 Parent(s): 1388ca9

docs: add separate mini blog writeup

Browse files

Move the narrative writeup into BLOG.md and keep the README focused on submission links, results, and usage.

Made-with: Cursor

Files changed (2) hide show
  1. BLOG.md +85 -0
  2. README.md +17 -50
BLOG.md ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Teaching LLMs When Not To Trust Context
2
+
3
+ **ContextCorruption-Env** is an OpenEnv Hackathon submission by Siddh Sanghavi and Aagam Parekh.
4
+
5
+ Modern LLM applications are increasingly built around retrieval: give the model more documents, more search results, more memory, more context. That works beautifully until one of those retrieved snippets is wrong.
6
+
7
+ Then a strange thing happens. The model may already "know" the correct answer, but the moment a document says something false with enough confidence, the model often follows the document. In real systems, that failure mode is not academic. It looks like a support bot following an outdated policy, a research assistant citing a fabricated source, or an enterprise agent trusting the wrong internal note.
8
+
9
+ The problem is not that the model cannot read context. The problem is that it does not know when context deserves suspicion.
10
+
11
+ ## The Environment
12
+
13
+ ContextCorruption-Env turns that behavior into a trainable RL environment.
14
+
15
+ Each episode gives the agent:
16
+
17
+ - one factual question;
18
+ - eight retrieved documents;
19
+ - one to four deliberately corrupted documents;
20
+ - a limited interaction budget.
21
+
22
+ Some corruptions are simple: a number changes, or a year is shifted. Others are harder: an entity is swapped, a claim is inverted, or a fake authoritative sentence is inserted with a convincing institution and year.
23
+
24
+ The agent has to do two jobs at once:
25
+
26
+ 1. answer the question;
27
+ 2. identify which documents are suspicious.
28
+
29
+ This makes the task more realistic than plain QA. The agent is not only predicting an answer. It is modeling a small information world where some sources are reliable and some are not.
30
+
31
+ ## What The Agent Can Do
32
+
33
+ The action space is intentionally small:
34
+
35
+ - `read_doc`: inspect a document and spend budget;
36
+ - `flag_suspicious`: mark a document as corrupted;
37
+ - `unflag_doc`: remove a flag;
38
+ - `submit_answer`: finish with an answer and confidence.
39
+
40
+ A weak policy can guess. A better policy has to notice contradictions, avoid over-flagging clean sources, and calibrate confidence when evidence conflicts.
41
+
42
+ ## Reward Design
43
+
44
+ The reward is deterministic. There is no LLM judge.
45
+
46
+ It combines:
47
+
48
+ - answer correctness;
49
+ - recall over corrupted documents;
50
+ - precision, so flagging everything is punished;
51
+ - confidence calibration;
52
+ - a small efficiency bonus.
53
+
54
+ That matters because the reward teaches the full behavior we care about. The agent does not get maximum reward for being right by accident. It needs to be right, skeptical, and appropriately confident.
55
+
56
+ ## Training
57
+
58
+ We trained Qwen2-1.5B-Instruct with GRPO using Unsloth and Hugging Face TRL. The run was sized for hackathon constraints, so this is not meant to be a final production model. It is evidence that the environment produces a real learning signal.
59
+
60
+ The random baseline averaged **0.1302 reward** over 100 episodes.
61
+
62
+ The trained GRPO run reached a final logged reward of **0.3289**, and the reward curve moves above the baseline during training.
63
+
64
+ ![Reward curve](assets/reward_curve.png)
65
+
66
+ ![Loss curve](assets/loss_curve.png)
67
+
68
+ The trained LoRA adapter is pushed to Hugging Face Hub and is loaded by the hosted Space through `/model/infer`.
69
+
70
+ ## Why It Matters
71
+
72
+ RAG systems are becoming the default interface between LLMs and the real world. If agents are going to operate over company documents, scientific papers, policies, calendars, emails, and tool outputs, they need a learned habit of source skepticism.
73
+
74
+ ContextCorruption-Env is a compact version of that problem. It asks a simple question:
75
+
76
+ Can we train a model not just to use context, but to distrust bad context?
77
+
78
+ That capability matters for enterprise search, research workflows, legal and policy review, support automation, and personal assistant systems where the cost of blindly trusting the wrong document can be high.
79
+
80
+ ## Links
81
+
82
+ - Environment Space: https://huggingface.co/spaces/Siddh12334/context-corruption-env
83
+ - Trained checkpoint: https://huggingface.co/Siddh12334/qwen-1.5b-context-corruption
84
+ - WandB run: https://wandb.ai/siddh230505-animeta/context-corruption-env/runs/rl5jygl8
85
+ - Training logs: [`assets/training_history_rl5jygl8.csv`](assets/training_history_rl5jygl8.csv)
README.md CHANGED
@@ -15,37 +15,22 @@ license: mit
15
 
16
  **Authors:** Siddh Sanghavi, Aagam Parekh
17
 
18
- ContextCorruption-Env is an OpenEnv environment for a failure mode we kept seeing in modern AI systems: a model knows enough to answer correctly, then a retrieved document confidently tells it the wrong thing, and the model follows the document anyway.
19
 
20
- That is not just a trivia problem. It is what happens when a support bot reads a stale policy page, a research agent sees a fabricated citation, or an enterprise assistant retrieves a wrong internal note. The hard part is not reading more context. The hard part is learning when context should not be trusted.
21
 
22
- ## Mini-Blog: Teaching A Model To Distrust Bad Context
23
 
24
- Most benchmarks reward an LLM for producing the right final answer. We wanted to reward a more realistic behavior: being right **and** knowing which sources were unreliable.
25
-
26
- In each episode, the agent receives one factual question and eight short documents. Some documents are clean. Some are corrupted. At first, the corruptions are obvious: a year is shifted, a number is changed. Then they get harder: an entity is swapped, a claim is inverted, or an authoritative-looking sentence is fabricated with a fake institution and fake citation style.
27
-
28
- The agent has to do two jobs at once:
29
-
30
- - answer the original question;
31
- - flag the documents it believes are corrupted.
32
-
33
- This turns retrieval into a small world-modeling problem. The agent is not just asking "what text did I retrieve?" It has to ask "which parts of this world are reliable, which claims conflict, and how much confidence should I have before I submit?"
34
-
35
- We built this under **Theme #3.1: World Modeling / Professional Tasks** because the environment simulates a partially observable information workspace. The documents are the agent's world. Some pieces of that world lie.
36
-
37
- ## Why This Matters
38
-
39
- RAG is becoming the default way to connect LLMs to companies, tools, documents, and memories. But retrieval can amplify mistakes. If the context window contains a convincing falsehood, many models treat it as ground truth. That is dangerous in exactly the places where people want agents to be useful: enterprise search, legal review, scientific workflows, customer support, and personal assistants.
40
-
41
- ContextCorruption-Env trains the behavior we actually want from those systems:
42
-
43
- - cross-check sources instead of copying them;
44
- - preserve uncertainty when evidence conflicts;
45
- - identify suspicious context, not just produce fluent answers;
46
- - improve through an objective reward instead of an LLM judge.
47
 
48
- ## What The Environment Looks Like
49
 
50
  Each episode contains:
51
 
@@ -64,7 +49,7 @@ The agent can take four actions:
64
 
65
  The environment is intentionally simple to run but hard to master. A weak agent can guess an answer. A stronger agent must notice contradictions and avoid over-flagging clean documents.
66
 
67
- ## Reward Design
68
 
69
  The reward is deterministic and compositional. There is no hidden LLM judge.
70
 
@@ -78,11 +63,9 @@ The reward is deterministic and compositional. There is no hidden LLM judge.
78
 
79
  Reward range: **-0.5 to 1.05**.
80
 
81
- The reward is designed so that common shortcuts do not work well. Flagging every document hurts precision. Submitting a confident wrong answer is penalized. Ignoring corruption leaves recall points on the table.
82
-
83
- ## What Changed After Training
84
 
85
- We trained **Qwen2-1.5B-Instruct** with GRPO using Unsloth / TRL. The run was intentionally small enough to finish during the hackathon, but it still produced a clear signal above the random baseline.
86
 
87
  | Agent | Reward Evidence |
88
  |---|---:|
@@ -95,13 +78,7 @@ The trained LoRA adapter is pushed to the Hub and is loaded by the hosted Space
95
 
96
  ![Loss curve](assets/loss_curve.png)
97
 
98
- The important result is not that the model became perfect. It did not. The important result is that the environment produces an actionable training signal for a behavior that normal QA benchmarks miss: source skepticism.
99
-
100
- ## Live Demo
101
-
102
- Main environment Space:
103
-
104
- https://huggingface.co/spaces/Siddh12334/context-corruption-env
105
 
106
  The Space exposes the OpenEnv API and an optional model endpoint:
107
 
@@ -119,16 +96,6 @@ Verified deployment status:
119
  - trained checkpoint loads from `Siddh12334/qwen-1.5b-context-corruption`;
120
  - `/model/infer` returns a JSON-style response.
121
 
122
- ## Evidence And Artifacts
123
-
124
- - **Environment Space:** https://huggingface.co/spaces/Siddh12334/context-corruption-env
125
- - **Training Space:** https://huggingface.co/spaces/Siddh12334/context-corruption-training
126
- - **Trained LoRA checkpoint:** https://huggingface.co/Siddh12334/qwen-1.5b-context-corruption
127
- - **Finished WandB run:** https://wandb.ai/siddh230505-animeta/context-corruption-env/runs/rl5jygl8
128
- - **Training logs/history:** [`assets/training_history_rl5jygl8.csv`](assets/training_history_rl5jygl8.csv)
129
- - **Training script:** [`training/train_grpo.py`](training/train_grpo.py)
130
- - **Notebook:** [`training/ContextCorruption_GRPO.ipynb`](training/ContextCorruption_GRPO.ipynb)
131
-
132
  ## Quick Start
133
 
134
  ```python
@@ -172,13 +139,13 @@ assets/ # reward curve, loss curve, exported training logs
172
 
173
  - [x] OpenEnv environment with `reset`, `step`, `state`, schemas, and reward
174
  - [x] Hosted Hugging Face Space for the environment
 
175
  - [x] Baseline evaluation in `eval/baseline_results.json`
176
  - [x] GRPO training script using Unsloth / TRL
177
  - [x] Trained LoRA checkpoint pushed to Hugging Face Hub
178
  - [x] Reward and loss plots committed
179
  - [x] Training logs linked and exported
180
  - [x] Trained checkpoint verified through `/model/infer`
181
- - [x] Mini-blog included in this Hugging Face Space README
182
  - [ ] Optional: add a <2 minute pitch video or slide link
183
 
184
  ## Citation
 
15
 
16
  **Authors:** Siddh Sanghavi, Aagam Parekh
17
 
18
+ ContextCorruption-Env is an OpenEnv environment for training epistemic robustness in LLMs. The agent receives a factual question plus retrieved documents, some of which are deliberately corrupted. It must answer the question and flag unreliable sources.
19
 
20
+ This submission targets **Theme #3.1: World Modeling / Professional Tasks**. The environment simulates a partially observable information workspace where some evidence is trustworthy and some evidence lies.
21
 
22
+ ## Required Materials
23
 
24
+ - **Environment Space:** https://huggingface.co/spaces/Siddh12334/context-corruption-env
25
+ - **Mini-blog / writeup:** [`BLOG.md`](BLOG.md)
26
+ - **Training Space:** https://huggingface.co/spaces/Siddh12334/context-corruption-training
27
+ - **Trained LoRA checkpoint:** https://huggingface.co/Siddh12334/qwen-1.5b-context-corruption
28
+ - **Finished WandB run:** https://wandb.ai/siddh230505-animeta/context-corruption-env/runs/rl5jygl8
29
+ - **Training logs/history:** [`assets/training_history_rl5jygl8.csv`](assets/training_history_rl5jygl8.csv)
30
+ - **Training script:** [`training/train_grpo.py`](training/train_grpo.py)
31
+ - **Notebook:** [`training/ContextCorruption_GRPO.ipynb`](training/ContextCorruption_GRPO.ipynb)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
+ ## Environment Summary
34
 
35
  Each episode contains:
36
 
 
49
 
50
  The environment is intentionally simple to run but hard to master. A weak agent can guess an answer. A stronger agent must notice contradictions and avoid over-flagging clean documents.
51
 
52
+ ## Reward
53
 
54
  The reward is deterministic and compositional. There is no hidden LLM judge.
55
 
 
63
 
64
  Reward range: **-0.5 to 1.05**.
65
 
66
+ ## Results
 
 
67
 
68
+ We trained **Qwen2-1.5B-Instruct** with GRPO using Unsloth / TRL. The run was sized for hackathon constraints, but it produced a clear signal above the random baseline.
69
 
70
  | Agent | Reward Evidence |
71
  |---|---:|
 
78
 
79
  ![Loss curve](assets/loss_curve.png)
80
 
81
+ ## Live API
 
 
 
 
 
 
82
 
83
  The Space exposes the OpenEnv API and an optional model endpoint:
84
 
 
96
  - trained checkpoint loads from `Siddh12334/qwen-1.5b-context-corruption`;
97
  - `/model/infer` returns a JSON-style response.
98
 
 
 
 
 
 
 
 
 
 
 
99
  ## Quick Start
100
 
101
  ```python
 
139
 
140
  - [x] OpenEnv environment with `reset`, `step`, `state`, schemas, and reward
141
  - [x] Hosted Hugging Face Space for the environment
142
+ - [x] Separate mini-blog/writeup linked from README
143
  - [x] Baseline evaluation in `eval/baseline_results.json`
144
  - [x] GRPO training script using Unsloth / TRL
145
  - [x] Trained LoRA checkpoint pushed to Hugging Face Hub
146
  - [x] Reward and loss plots committed
147
  - [x] Training logs linked and exported
148
  - [x] Trained checkpoint verified through `/model/infer`
 
149
  - [ ] Optional: add a <2 minute pitch video or slide link
150
 
151
  ## Citation