Spaces:
Sleeping
Sleeping
|
Download docs/VIBE_CODING_GUIDE.md from rk147/federated_learning_model: direct link, hf CLI and curl.
- Browser
- Download file 4.25 kB
-
https://huggingface.co/spaces/rk147/federated_learning_model/resolve/main/docs/VIBE_CODING_GUIDE.md
- Command line
-
hf download hf://spaces/rk147/federated_learning_model/docs/VIBE_CODING_GUIDE.md
-
curl -L -o VIBE_CODING_GUIDE.md https://huggingface.co/spaces/rk147/federated_learning_model/resolve/main/docs/VIBE_CODING_GUIDE.md
4.25 kB
| # Vibe-coding guide: take this repo further with ANY coding AI (Claude, Cursor, ChatGPT, Gemini, Copilot) | |
| The codebase in this folder already runs. Use the AI to adapt, extend or fix it, not to start over. | |
| ## Rules for you | |
| 1. Give the AI the **whole repo** (zip, or paste files in this order: README.md, fl/fed.py, fl/dp.py, fl/data.py, fl/vision.py, fl/experiment.py, app.py) plus the MASTER PROMPT below. | |
| 2. One change per message. After each, run `python tests/smoke_test.py`. If it fails, paste the full traceback back. | |
| 3. Never let the AI "simplify" the DP or fairness code. Those are your dissertation. | |
| 4. Deploy loop: edit file -> upload to the Space -> check the Space **Logs** tab -> paste errors back to the AI. | |
| ## MASTER PROMPT (copy everything in the box) | |
| ``` | |
| You are a senior ML engineer. I am handing you a working repo (attached) for a dissertation: | |
| "Privacy-preserving federated learning for early multi-disease risk prediction with fairness | |
| constraints using image processing". It deploys as a Gradio app on a FREE Hugging Face CPU Space. | |
| HARD CONSTRAINTS | |
| - Free tools only. CPU only. Python 3.10. No network access at runtime except Hugging Face datasets and torchvision weights. | |
| - The federated core in fl/fed.py, fl/dp.py is pure NumPy and must stay torch-free so tests run anywhere. | |
| - Do NOT replace DP-SGD with "add noise to final weights". Keep: Poisson sampling, per-example clipping, | |
| Gaussian noise sigma*C, RDP accounting in fl/dp.py. Public fairness weights are applied AFTER clipping | |
| and are <= 1 so sensitivity stays C. Do not break this invariant. | |
| - Backbone = frozen ImageNet MobileNetV2 (1280-d). No deep training. Features are cached in cache/*.npz. | |
| - Keep every existing file path and function name unless I ask. Keep tests/smoke_test.py passing. | |
| - Output complete files (not diffs) for every file you change, each in its own code block with the path as a header. | |
| - If you are unsure about a Hugging Face dataset column name, make the loader auto-detect it and log the columns; never hard-fail silently. | |
| ARCHITECTURE (do not change) | |
| images -> fl/vision.py (OpenCV preprocessing, CLAHE or Ben-Graham, MobileNetV2 embedding, cached) | |
| -> fl/data.py (standardise, shared random projection to 128-d, non-IID Dirichlet split into hospitals) | |
| -> fl/fed.py (local DP-SGD, FedAvg, fairness multipliers, metrics) | |
| -> fl/experiment.py (3 modes: Baseline, +DP, +DP+Fairness; table and plots) | |
| -> app.py (Gradio: experiment tab, single-image prediction tab) | |
| WORKFLOW FOR EACH MY REQUEST | |
| 1. Restate the change in one line and list the files you will touch. | |
| 2. Make the change. Keep it minimal. | |
| 3. Say exactly what command to run to verify, and what output I should see. | |
| 4. List any new risk to privacy accounting or fairness metrics, or write "none". | |
| FIRST TASKS (do them one by one, wait for my "next"): | |
| A. Read the repo and tell me in 10 lines what it does and any bugs you see. Do not edit yet. | |
| B. Add a sweep script experiments/sweep.py that runs epsilon in {1,2,4,8,inf} and 5 seeds for both diseases | |
| and writes results/sweep.csv plus results/sweep.png (mean +- std AUC, TPR gap vs epsilon). | |
| C. Add a centralized (non-federated) and a local-only baseline to fl/experiment.py and to the results table. | |
| D. Add per-seed confidence intervals (5 seeds) to the app results table. | |
| E. Add a "Download results CSV" button to app.py. | |
| F. Write docs/REPORT.md: abstract, method (with equations), experiments, results table placeholders, limitations. | |
| ``` | |
| ## Fast fixes cheat-sheet (tell the AI the symptom) | |
| | Symptom | Likely cause | Ask the AI to | | |
| |---|---|---| | |
| | "no dataset worked for task" in the status box | dataset schema differs | print `first.keys()` and adapt `_heart_label_fn` / `_dr_label_fn` in fl/vision.py | | |
| | Status says SYNTHETIC | real loading failed (see log lines) | fix loader using the logged columns, or use prepare_features.py in Colab | | |
| | Space build fails on torch | wheel version | pin torch/torchvision to versions available on download.pytorch.org/whl/cpu | | |
| | First run times out | too many images | lower "Images per class" to 80 or pre-build cache | | |
| | Fairness gap not shrinking | groups tiny or noisy | raise `fair_eta`, more rounds, check group sizes in the log | | |