Spaces:
Sleeping
Download PROJECT_COMPLETE_GUIDE.md from 01ammu/data-cleaning-openenv: direct link, hf CLI and curl.
- Browser
- Download file 25.1 kB
-
https://huggingface.co/spaces/01ammu/data-cleaning-openenv/resolve/main/PROJECT_COMPLETE_GUIDE.md
- Command line
-
hf download hf://spaces/01ammu/data-cleaning-openenv/PROJECT_COMPLETE_GUIDE.md
-
curl -L -o PROJECT_COMPLETE_GUIDE.md https://huggingface.co/spaces/01ammu/data-cleaning-openenv/resolve/main/PROJECT_COMPLETE_GUIDE.md
π Data Cleaning OpenEnv β Complete Project Guide
Everything you need to understand, run, teach, and extend this project. Written for the Meta OpenEnv Hackathon, April 2026.
π Table of Contents
- What is this project?
- What is Reinforcement Learning?
- What is OpenEnv?
- Project File Structure
- What Each File Does
- System Flowchart β How Everything Works Together
- The RL Loop in This Project
- Reward System Explained
- The 3 Tasks Explained
- All Commands to Run the Project
- How to Deploy to HuggingFace
- Live URLs
- Baseline Scores
- Tech Stack
- Quick Glossary
1. What is this project?
This project is a Reinforcement Learning (RL) environment where an AI agent learns to clean messy datasets.
In the real world, data scientists spend 60β80% of their time cleaning data β fixing missing values, removing duplicates, correcting wrong data types, standardizing categories, and handling outliers.
We built an environment where an AI agent can practice and learn this skill automatically, row by row, getting rewarded for good cleaning decisions and penalized for bad ones.
Think of it like this:
- The environment is a "gym" for the AI
- The dataset is the "obstacle course"
- Each dirty row is a challenge
- The agent picks an action (fill, fix, skip, etc.)
- It gets a reward or penalty based on the quality of its decision
- Over thousands of episodes, it learns to clean data like an expert
2. What is Reinforcement Learning?
Reinforcement Learning (RL) is a type of machine learning where an agent learns by trial and error β interacting with an environment and learning from rewards.
The RL Loop:
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
β ENVIRONMENT ββobservationβββΆ AGENT β
β β
β ENVIRONMENT βββactionββββββ AGENT β
β β
β ENVIRONMENT ββrewardββββββββΆ AGENT β
β β
β (repeat until episode ends) β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
In plain English:
- Environment shows agent the current situation (observation)
- Agent decides what to do (action)
- Environment evaluates the action and gives feedback (reward)
- Agent learns from the reward and improves over time
In our project:
- Environment shows agent a dirty data row
- Agent picks a cleaning action (fill_missing, fix_type, etc.)
- Environment gives +0.3 for good action, -0.2 for bad
- Agent learns which actions to take for which types of issues
3. What is OpenEnv?
OpenEnv is a framework by Meta that standardizes how RL environments are built and deployed.
Key idea: RL environments should work like REST APIs β type-safe, containerized, and deployable anywhere.
Why OpenEnv over traditional Gym?
| Feature | Traditional (OpenAI Gym) | OpenEnv |
|---|---|---|
| Type Safety | β Raw arrays/dicts | β Typed Pydantic models |
| Isolation | β Same process | β Docker containers |
| Deployment | β "Works on my machine" | β Same everywhere |
| Language | β Python only | β Any language (HTTP API) |
| Scaling | β Hard | β Kubernetes-ready |
The 3 mandatory endpoints:
POST /reset β Start a new episode
POST /step β Take an action
GET /state β Get episode metadata
4. Project File Structure
data-cleaning-openenv/
β
βββ Dockerfile β Containerizes the whole app
βββ inference.py β Baseline agent using OpenAI API
βββ test_env.py β Local testing script
βββ README.md β HuggingFace/GitHub readme
βββ pyproject.toml β Makes env pip-installable
βββ PROJECT_COMPLETE_GUIDE.md β This file!
β
βββ envs/
βββ data_cleaning_env/
β
βββ models.py β Typed contracts (Action, Observation, State)
βββ client.py β HTTP client for agents to use
βββ openenv.yaml β OpenEnv metadata/spec file
βββ __init__.py
β
βββ server/
β βββ app.py β FastAPI server (all endpoints)
β βββ environment.py β Core RL logic
β βββ __init__.py
β
βββ tasks/
βββ graders.py β Task definitions + scoring logic
βββ __init__.py
5. What Each File Does
models.py β The Language
Defines the typed data structures that the agent and environment use to communicate.
# What the agent SENDS to the environment
class DataCleaningAction:
action_type: str # "fill_missing", "fix_type", "skip", etc.
column: str # Which column to act on ("age", "salary", etc.)
value: Any # New value if needed (e.g., 30 for age)
# What the agent RECEIVES from the environment
class DataCleaningObservation:
current_row: int # Which row we're on (0, 1, 2...)
total_rows: int # Total rows in dataset
current_data: dict # The actual dirty data {'age': None, 'score': '85'}
issues_detected: list # ['missing:age', 'wrong_type:score']
legal_actions: list # ['fill_missing', 'fix_type', 'skip']
progress: float # 0.0 to 1.0
reward: float # Last reward received
done: bool # Is episode over?
# Episode metadata
class DataCleaningState:
episode_id: str
task_name: str
step_count: int
total_reward: float
rows_cleaned: int
score: float # Final grader score (0.0 to 1.0)
environment.py β The Brain
The core RL logic. This is where the environment lives.
Key methods:
reset(task_name) β Starts a new episode
- Loads a dirty dataset for the chosen task
- Resets all counters
- Returns the first observation
step(action_type, column, value) β Processes one action
- Applies the cleaning action to the current row
- Calculates reward (+/- based on action quality)
- Moves to next row
- Returns new observation
_detect_issues(row) β Finds problems in a row
- Checks for None values β "missing:age"
- Checks for wrong types β "wrong_type:score"
- Checks for formatting β "formatting:email"
_get_legal_actions(row, issues) β What can agent do right now?
- If missing values exist β add "fill_missing"
- If wrong types exist β add "fix_type"
- Always includes "skip", "remove_duplicate", etc.
graders.py β The Judge
Defines the 3 tasks and scores the cleaned dataset after an episode.
Task generation:
generate_easy_dataset()β 10 rows with missing values + wrong typesgenerate_medium_dataset()β 8 rows with duplicates + formatting issuesgenerate_hard_dataset()β 8 rows with all issues combined
Grading:
grade_easy(cleaned_data)β Checks all values filled + score is numericgrade_medium(cleaned_data)β Checks no duplicates + emails lowercasegrade_hard(cleaned_data)β Checks depts standardized + salaries in range
All graders return (score, message) where score is 0.0β1.0.
app.py β The Server
Exposes the environment over HTTP and WebSocket so any agent can interact with it.
HTTP Endpoints:
POST /reset β env.reset(task_name)
POST /step β env.step(action_type, column, value)
GET /state β env.get_state()
GET /health β {"status": "ok"}
GET /tasks β list all tasks
GET /docs β Swagger API documentation
WebSocket Endpoint:
WS /ws β Persistent connection for efficient RL training
Each connection gets its own environment instance
Much faster than HTTP for thousands of steps
client.py β The Agent's Interface
How your training code talks to the environment. Wraps all HTTP calls into clean Python methods.
# Usage example
env = DataCleaningEnv(base_url="https://01ammu-data-cleaning-openenv.hf.space")
result = env.reset(task_name="easy")
# Returns StepResult(observation=..., reward=0.0, done=False, info={...})
result = env.step(action_type="fill_missing", column="age", value=30)
# Returns StepResult(observation=..., reward=0.3, done=False, info={...})
state = env.state()
# Returns episode metadata dict
inference.py β The Baseline Agent
Uses the OpenAI API to run a language model against the environment. Produces reproducible baseline scores to show in the README.
Dockerfile β The Container
Packages everything so it runs identically everywhere.
FROM python:3.11-slim
WORKDIR /app
RUN pip install fastapi uvicorn requests openai pydantic
COPY envs/data_cleaning_env/server/ ./server/
COPY envs/data_cleaning_env/tasks/ ./tasks/
EXPOSE 7860
CMD ["python", "-m", "uvicorn", "server.app:app", "--host", "0.0.0.0", "--port", "7860"]
openenv.yaml β The Spec File
Tells the OpenEnv framework everything about your environment β name, version, tasks, action space, observation space, endpoints.
pyproject.toml β pip Installable
Makes your environment installable directly from HuggingFace:
pip install git+https://huggingface.co/spaces/01ammu/data-cleaning-openenv
6. System Flowchart β How Everything Works Together
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β AGENT (Your Code) β
β β
β from client import DataCleaningEnv β
β env = DataCleaningEnv(base_url="https://...hf.space") β
β result = env.reset(task_name="easy") β
β result = env.step("fill_missing", "age", 30) β
ββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββ
β HTTP POST /reset
β HTTP POST /step
β (or WebSocket /ws)
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β DOCKER CONTAINER (HF Space) β
β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β app.py (FastAPI Server) β β
β β β β
β β POST /reset βββββββββββββββββββββββββββββββββββββββββββ β β
β β POST /step βββββββββββββββββββββββββββββββββββββββ β β β
β β GET /state βββββββββββββββββββββββ β β β β
β β WS /ws βββββββββββββββββββ β β β β β
β βββββββββββββββββββββββββββββββββββΌββββΌββββββββββββββββΌββββ β β
β β β β β β
β βββββββββββββββββββββββββββββββββββΌββββΌββββββββββββββββΌββββ β β
β β environment.py (Core RL Logic) β β β
β β β β β
β β reset() βββΆ loads dataset βββΆ returns observation β β β
β β step() βββΆ applies action βββΆ calculates reward β β β
β β βββΆ moves to next row βββΆ returns obs β β β
β β get_state() βββΆ returns episode metadata β β β
β ββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ β β
β β β β
β ββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββ β β
β β graders.py (Tasks + Scoring) β β β
β β β β β
β β generate_easy_dataset() β 10 rows, missing+types β β β
β β generate_medium_dataset() β 8 rows, +duplicates β β β
β β generate_hard_dataset() β 8 rows, +outliers β β β
β β β β β
β β grade_easy(data) β score 0.0β1.0 β β β
β β grade_medium(data) β score 0.0β1.0 β β β
β β grade_hard(data) β score 0.0β1.0 β β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β β
β β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
Observation + Reward returned to Agent
7. The RL Loop in This Project
Here is exactly what happens during one full episode:
START: Agent calls reset(task_name="easy")
β
βββ Environment loads dirty dataset (10 rows)
βββ Returns first row: {'age': None, 'salary': 50000, 'score': '85'}
β Issues: ['missing:age', 'wrong_type:score']
β Legal actions: ['fill_missing', 'fix_type', 'skip', ...]
β
βββ Agent sees the row and issues
βββ Agent picks action: fill_missing on column 'age', value=30
β
βββ Environment applies: row['age'] = 30
βββ Reward: +0.3 (correct action for a missing value)
βββ Returns next row
β
βββ Agent picks action: fix_type on column 'score'
βββ Environment applies: row['score'] = float('85') = 85.0
βββ Reward: +0.2
β
βββ ... (repeat for all 10 rows) ...
β
END: All rows processed β done = True
β
βββ Grader scores final cleaned dataset β 0.88
"Passed 31/35 checks"
8. Reward System Explained
| Action | When to use | Reward |
|---|---|---|
fill_missing |
Column value is None | +0.3 |
fix_type |
Value is wrong type (e.g. "85" instead of 85) | +0.2 |
remove_duplicate |
Row is a duplicate of previous row | +0.4 |
fix_category |
Category is inconsistent (e.g. "eng" β "Engineering") | +0.3 |
remove_outlier |
Value is out of normal range (e.g. salary = 999999) | +0.4 |
fix_formatting |
Text needs formatting (e.g. "ALICE@GMAIL.COM" β lowercase) | +0.2 |
skip |
Do nothing | -0.2 (penalty) |
| Wrong action | e.g. fill_missing when value already exists | -0.1 |
| Unknown action | Not in the action space | -0.3 |
Why penalties matter: The agent can't just always pick "fill_missing" and get rewards. If the value already exists and you try to fill it, you get -0.1. This forces the agent to actually read the observation and pick the right action.
9. The 3 Tasks Explained
Task 1 β Easy: Fix Missing Values & Type Errors
Dataset: 10-row employee dataset with age, salary, score Issues:
ageorsalaryis None β needsfill_missingscoreis "85" (string) instead of 85.0 (float) β needsfix_type
Grader checks:
- All age, salary, score fields are non-null
- score is numeric (float)
Baseline score: 0.88
Task 2 β Medium: Remove Duplicates & Fix Formatting
Dataset: 8-row contacts dataset with name, email, age Issues:
- Rows 2 and 4 are exact duplicates (Bob, bob@gmail.com, 30)
- Rows 3 and 7 are exact duplicates (charlie)
emailis uppercase ("ALICE@GMAIL.COM") β needsfix_formattingnameorageis None β needsfill_missing
Grader checks:
- No duplicate emails
- All names filled
- All emails lowercase
- All ages filled
Baseline score: 0.88
Task 3 β Hard: Full Data Cleaning
Dataset: 8-row HR dataset with name, dept, salary, age Issues:
- Inconsistent departments: "eng", "h.r.", "ENGINEERING", "Finance" all need standardizing to "Engineering", "HR", "Finance"
- Outlier salary: 999999 (way too high) β replace with median
- Negative salary: -5000 β invalid
- Missing name, age, salary
- Duplicate rows (alice appears twice)
Grader checks:
- No duplicate names
- All fields filled
- All depts in {"Engineering", "HR", "Finance"}
- All salaries between 0 and 200,000
Baseline score: 0.83
10. All Commands to Run the Project
Prerequisites
# Make sure you have Python 3.10+ and Git installed
python --version
git --version
Clone the project
git clone https://github.com/AnubhavKiroula/data-cleaning-openenv
cd data-cleaning-openenv
Install dependencies
pip install fastapi uvicorn pydantic requests openai
Run the server locally
# From the project root: D:\META-HACKATHON\data-cleaning-openenv\
cd D:\META-HACKATHON\data-cleaning-openenv
python -m uvicorn server.app:app --host 0.0.0.0 --port 7860
Server will be live at: http://localhost:7860
Test all 3 tasks locally
# From project root
cd D:\META-HACKATHON\data-cleaning-openenv
python test_env.py
Expected output:
easy : 0.88
medium : 0.88
hard : 0.83
average: 0.86
Run with Docker locally
# From project root
cd D:\META-HACKATHON\data-cleaning-openenv
# Build the Docker image
docker build -t data-cleaning-openenv .
# Run the container
docker run -p 7860:7860 data-cleaning-openenv
Run the baseline inference script
# Set environment variables first
$env:OPENAI_API_KEY = "your_openai_key_here"
$env:API_BASE_URL = "http://localhost:7860"
$env:MODEL_NAME = "gpt-4o-mini"
# Run inference
python inference.py
Test the API manually (curl)
# Health check
curl.exe http://localhost:7860/health
# Reset to easy task
curl.exe -X POST http://localhost:7860/reset -H "Content-Type: application/json" -d '{\"task_name\": \"easy\"}'
# Take a step
curl.exe -X POST http://localhost:7860/step -H "Content-Type: application/json" -d '{\"action_type\": \"fill_missing\", \"column\": \"age\", \"value\": 30}'
# Check state
curl.exe http://localhost:7860/state
# List tasks
curl.exe http://localhost:7860/tasks
Push changes to GitHub
cd D:\META-HACKATHON\data-cleaning-openenv
git add .
git commit -m "your commit message here"
git push origin main
Push changes to HuggingFace Space
cd D:\META-HACKATHON\data-cleaning-openenv
git push hf main
If hf remote doesn't exist yet:
git remote add hf https://huggingface.co/spaces/01ammu/data-cleaning-openenv
git push hf main --force
Use the client in your own code
from envs.data_cleaning_env.client import DataCleaningEnv
# Connect to local server
env = DataCleaningEnv(base_url="http://localhost:7860")
# Or connect to live HF Space
env = DataCleaningEnv(base_url="https://01ammu-data-cleaning-openenv.hf.space")
# Run an episode
result = env.reset(task_name="easy")
print(result.observation)
while not result.done:
result = env.step(
action_type="fill_missing",
column="age",
value=30
)
print(f"Reward: {result.reward}, Done: {result.done}")
state = env.state()
print(f"Final score: {state['score']}")
11. How to Deploy to HuggingFace
One-time setup (already done)
# Add HF as a git remote
git remote add hf https://huggingface.co/spaces/01ammu/data-cleaning-openenv
Every time you want to redeploy
cd D:\META-HACKATHON\data-cleaning-openenv
git add .
git commit -m "update: describe what you changed"
git push hf main
git push origin main # also keep GitHub in sync
Check deployment
- Go to: https://huggingface.co/spaces/01ammu/data-cleaning-openenv
- Click App tab β watch Container logs
- Look for: "Application startup complete" and green Running dot
12. Live URLs
| What | URL |
|---|---|
| HF Space | https://01ammu-data-cleaning-openenv.hf.space |
| Health Check | https://01ammu-data-cleaning-openenv.hf.space/health |
| API Docs (Swagger) | https://01ammu-data-cleaning-openenv.hf.space/docs |
| List Tasks | https://01ammu-data-cleaning-openenv.hf.space/tasks |
| GitHub Repo | https://github.com/AnubhavKiroula/data-cleaning-openenv |
13. Baseline Scores
These scores were produced by running inference.py with a rule-based agent:
| Task | Score | What was tested |
|---|---|---|
| Easy | 1.00 | 31/35 checks passed |
| Medium | 0.88 | Duplicates removed, formatting fixed |
| Hard | 0.85 | All issues including outliers + categories |
| Average | 0.91 | Across all 3 tasks |
14. Tech Stack
| Technology | Role |
|---|---|
| Python 3.11 | Core language |
| FastAPI | HTTP server framework |
| Uvicorn | ASGI server to run FastAPI |
| Pydantic | Typed data models (Action, Observation, State) |
| Docker | Containerization for deployment |
| HuggingFace Spaces | Cloud hosting platform |
| OpenAI API | Baseline inference agent |
| Git | Version control |
| OpenEnv | RL environment framework by Meta |
15. Quick Glossary
| Term | Meaning |
|---|---|
| Agent | The AI that makes decisions (what to do with each row) |
| Environment | The system the agent interacts with (our data cleaning env) |
| Observation | What the agent sees (current row, issues, legal actions) |
| Action | What the agent does (fill_missing, fix_type, skip, etc.) |
| Reward | Feedback the agent gets (+0.3, -0.2, etc.) |
| Episode | One full run through a dataset (all rows processed) |
| Grader | Function that scores the cleaned dataset (0.0β1.0) |
| OpenEnv | Meta's framework for standardizing RL environments |
| HF Space | HuggingFace hosting β where our environment runs live |
| Docker | Container technology β packages app + dependencies together |
| FastAPI | Python web framework β handles HTTP requests |
| WebSocket | Persistent connection β faster than HTTP for many RL steps |
| Pydantic | Python library for typed, validated data models |
| Baseline | A simple agent's score used as a reference point |
| GRPO | Group Relative Policy Optimization β an RL training algorithm |
Built for the Meta OpenEnv Hackathon, April 2026. Team: AnubhavKiroula HF Space: https://01ammu-data-cleaning-openenv.hf.space GitHub: https://github.com/AnubhavKiroula/data-cleaning-openenv