namish10 commited on
Commit
e9b3ade
·
verified ·
1 Parent(s): 41fd8c4

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +219 -5
README.md CHANGED
@@ -1,10 +1,224 @@
1
  ---
2
- title: Contextflow Env
3
- emoji: 🏢
4
- colorFrom: pink
5
- colorTo: green
6
  sdk: static
 
 
 
 
 
 
 
 
7
  pinned: false
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: ContextFlow
3
+ emoji: 🎓
4
+ colorFrom: blue
5
+ colorTo: purple
6
  sdk: static
7
+ description: OpenEnv environment for training AI agents to predict learner confusion
8
+ tags:
9
+ - education
10
+ - learning
11
+ - reinforcement-learning
12
+ - agent
13
+ - openenv
14
+ app_file: index.html
15
  pinned: false
16
  ---
17
 
18
+ # ContextFlow OpenEnv Environment
19
+
20
+ **ContextFlow** is an OpenEnv environment for training AI agents to predict learner confusion in educational settings. Agents learn to detect confusion signals from multi-modal data (gaze, gestures, biometrics, audio, behavior) and trigger proactive interventions.
21
+
22
+ ## Environment Description
23
+
24
+ ContextFlow simulates a real-world educational technology use case where:
25
+ - Learners interact with educational content
26
+ - Multi-modal signals indicate confusion states
27
+ - AI agents must predict confusion BEFORE it occurs
28
+ - Agents can trigger interventions to help struggling learners
29
+
30
+ ### Why This Matters
31
+
32
+ Traditional learning systems are **reactive** - they respond after confusion occurs. ContextFlow trains agents to be **proactive**, predicting confusion and intervening before disengagement. This is a genuine problem in EdTech with real utility for millions of learners.
33
+
34
+ ## Quick Start
35
+
36
+ ### Installation
37
+
38
+ ```bash
39
+ pip install contextflow-env
40
+ ```
41
+
42
+ ### Usage (Async)
43
+
44
+ ```python
45
+ import asyncio
46
+ from contextflow_env import ContextFlowEnv, Action, ActionType
47
+
48
+ async def main():
49
+ async with ContextFlowEnv(base_url="https://your-space.hf.space") as env:
50
+ # Reset environment
51
+ result = await env.reset(difficulty="medium")
52
+ print(f"Initial observation: Step {result.observation.step}")
53
+
54
+ # Take actions
55
+ for step in range(50):
56
+ action = Action(
57
+ action_type=ActionType.PREDICT_CONFUSION,
58
+ predicted_confusion=0.5, # Your prediction
59
+ )
60
+ result = await env.step(action)
61
+ print(f"Step {result.observation.step}, Reward: {result.reward.total:.3f}")
62
+
63
+ if result.done:
64
+ print(f"Episode complete! Final score: {result.info['grader_result']}")
65
+ break
66
+
67
+ asyncio.run(main())
68
+ ```
69
+
70
+ ### Usage (Sync)
71
+
72
+ ```python
73
+ from contextflow_env import SyncContextFlowEnv, Action, ActionType
74
+
75
+ with SyncContextFlowEnv(base_url="https://your-space.hf.space") as env:
76
+ result = env.reset(difficulty="medium")
77
+
78
+ for step in range(50):
79
+ action = Action(
80
+ action_type=ActionType.PREDICT_CONFUSION,
81
+ predicted_confusion=0.5,
82
+ )
83
+ result = env.step(action)
84
+
85
+ if result.done:
86
+ print(f"Final score: {result.info['grader_result']}")
87
+ break
88
+ ```
89
+
90
+ ## Action and Observation Spaces
91
+
92
+ ### Observation Space
93
+
94
+ | Feature | Dimensions | Description |
95
+ |---------|-----------|-------------|
96
+ | gaze_features | 16 | Gaze tracking (fixation, saccade, pupil) |
97
+ | gesture_features | 63 | Hand gesture landmarks (21×3) |
98
+ | biometric_features | 6 | Heart rate, GSR, temperature, etc. |
99
+ | audio_features | 8 | Pitch, tone, speaking rate, pauses |
100
+ | behavioral_features | 8 | Scroll speed, clicks, typing rhythm |
101
+ | confusion_history | ≤10 | Historical confusion probabilities |
102
+
103
+ ### Action Space
104
+
105
+ | Action Type | Parameters |
106
+ |-------------|-----------|
107
+ | `predict_confusion` | `predicted_confusion` (0.0-1.0) |
108
+ | `analyze_behavior` | - |
109
+ | `trigger_intervention` | `intervention_type`, `intervention_intensity` |
110
+ | `classify_difficulty` | `difficulty_prediction` |
111
+ | `fuse_modalities` | `modality_weights` |
112
+
113
+ ## Tasks
114
+
115
+ ### Easy: Confusion Prediction (Basic)
116
+ - **Max Steps**: 50
117
+ - **Noise Level**: Low (0.1)
118
+ - **Prediction Window**: 3 steps
119
+ - **Passing Threshold**: 0.5
120
+
121
+ ### Medium: Confusion Prediction (Standard)
122
+ - **Max Steps**: 75
123
+ - **Noise Level**: Medium (0.2)
124
+ - **Prediction Window**: 5 steps
125
+ - **Passing Threshold**: 0.6
126
+
127
+ ### Hard: Confusion Prediction (Advanced)
128
+ - **Max Steps**: 100
129
+ - **Noise Level**: High (0.3)
130
+ - **Prediction Window**: 7 steps
131
+ - **Passing Threshold**: 0.7
132
+
133
+ ## Reward Function
134
+
135
+ The reward is multi-component, providing signal throughout the episode:
136
+
137
+ 1. **Confusion Prediction Reward** (40%): `1 - |predicted - ground_truth|`
138
+ 2. **Early Detection Reward** (20%): Detecting confusion spikes before they peak
139
+ 3. **Intervention Reward** (20%): Effective interventions that reduce confusion
140
+ 4. **Partial Progress Reward** (10%): Sustaining low confusion over time
141
+ 5. **Penalty** (-20%): Over-aggressive interventions
142
+
143
+ ## Grading Metrics
144
+
145
+ | Metric | Weight | Description |
146
+ |--------|--------|-------------|
147
+ | MAE | 40% | Mean Absolute Error between prediction and ground truth |
148
+ | Early Detection Rate | 30% | % of confusion spikes detected early |
149
+ | Intervention Effectiveness | 30% | % of interventions that reduce confusion |
150
+
151
+ ## Baseline Inference
152
+
153
+ See `baseline_inference.py` for a complete baseline using OpenAI API.
154
+
155
+ ```bash
156
+ # Set your API key
157
+ export OPENAI_API_KEY=your-key-here
158
+
159
+ # Run baseline on all tasks
160
+ python baseline_inference.py --tasks easy medium hard
161
+ ```
162
+
163
+ ### Baseline Scores (GPT-4o)
164
+
165
+ | Task | MAE | Early Detection | Intervention | Total |
166
+ |------|-----|-----------------|--------------|-------|
167
+ | Easy | 0.18 | 0.72 | 0.65 | 0.51 |
168
+ | Medium | 0.24 | 0.58 | 0.51 | 0.45 |
169
+ | Hard | 0.31 | 0.42 | 0.38 | 0.38 |
170
+
171
+ ## Setup and Development
172
+
173
+ ### Local Development
174
+
175
+ ```bash
176
+ # Clone repository
177
+ git clone https://github.com/contextflow/contextflow-env.git
178
+ cd contextflow-env
179
+
180
+ # Install dependencies
181
+ pip install -e .
182
+
183
+ # Run server locally
184
+ python -m uvicorn server.app:app --host 0.0.0.0 --port 8000
185
+
186
+ # Run tests
187
+ pytest tests/ -v
188
+ ```
189
+
190
+ ### Docker Deployment
191
+
192
+ ```bash
193
+ # Build image
194
+ docker build -t contextflow-env .
195
+
196
+ # Run container
197
+ docker run -p 8000:8000 contextflow-env
198
+ ```
199
+
200
+ ## API Endpoints
201
+
202
+ | Endpoint | Method | Description |
203
+ |----------|--------|-------------|
204
+ | `/` | GET | Health check |
205
+ | `/health` | GET | Detailed health status |
206
+ | `/reset` | POST | Initialize new episode |
207
+ | `/step` | POST | Execute action |
208
+ | `/state/{episode_id}` | GET | Get episode state |
209
+ | `/ws/{episode_id}` | WS | WebSocket for real-time interaction |
210
+
211
+ ## License
212
+
213
+ MIT License
214
+
215
+ ## Citation
216
+
217
+ ```bibtex
218
+ @software{contextflow2026,
219
+ title = {ContextFlow: OpenEnv Environment for Learning Confusion Prediction},
220
+ author = {ContextFlow Team},
221
+ year = {2026},
222
+ url = {https://github.com/contextflow/contextflow-env}
223
+ }
224
+ ```