huggingworld commited on
Commit
c49fca7
Β·
verified Β·
1 Parent(s): 29a6f55

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +298 -3
README.md CHANGED
@@ -1,3 +1,298 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language:
4
+ - en
5
+ pretty_name: Clinvar Annotations
6
+ ---
7
+
8
+ part of
9
+
10
+ # 🧬 Genomic Reasoning Agent
11
+ ### LLM-driven agentic system for personal genomic variant interpretation
12
+
13
+ [![HuggingFace](https://img.shields.io/badge/πŸ€—_HuggingFace-Space-yellow)](https://huggingface.co/spaces/mioulin/genomic-reasoning-agent)
14
+ [![Dataset](https://img.shields.io/badge/πŸ€—_Dataset-genomic--qa-blue)](https://huggingface.co/datasets/mioulin/genomic-reasoning-qa)
15
+ [![Model](https://img.shields.io/badge/πŸ€—_Model-genomic--reasoning--llm-green)](https://huggingface.co/mioulin/genomic-reasoning-grpo)
16
+ [![License: MIT](https://img.shields.io/badge/License-MIT-purple)](LICENSE)
17
+
18
+ ---
19
+
20
+ ## Overview
21
+
22
+ This project builds a **multi-step reasoning agent** that interprets personal genomic data from 23andMe against biomedical knowledge databases (ClinVar, GWAS Catalog, gnomAD). The agent is trained with **GRPO** (Group Relative Policy Optimization) using fully verifiable reward signals β€” no human labelers needed.
23
+
24
+ The core insight mirrors DeepSeek-R1's approach to mathematics: **genomic variant interpretation has verifiable ground truth** (ClinVar classifications, GWAS p-values, population frequencies), making it ideal for RL-based reasoning training.
25
+
26
+ ```
27
+ 23andMe SNPs (631K)
28
+ ↓
29
+ ClinVar Annotation ← rs1801133 β†’ MTHFR β†’ Pathogenic
30
+ ↓
31
+ Tool-Using LLM Agent ← 5 tools: lookup / scan / haplotype / stats / reward
32
+ ↓
33
+ GRPO Training Loop ← verifiable reward from ClinVar ground truth
34
+ ↓
35
+ Reasoning Model ← factual Β· calibrated Β· evidence-grounded
36
+ ↓
37
+ HF Spaces Demo ← upload 23andMe β†’ ask questions β†’ reasoning trace
38
+ ```
39
+
40
+ ---
41
+
42
+ ## Motivation
43
+
44
+ Standard LLMs hallucinate on genomic questions. This project trains a model that:
45
+
46
+ - **Cites sources** (ClinVar review status, GWAS p-values, PubMed IDs)
47
+ - **Shows reasoning chains** (mechanism β†’ evidence β†’ conclusion)
48
+ - **Calibrates uncertainty** (risk factor β‰  diagnosis)
49
+ - **Uses tools** to look up live databases rather than relying on memorised weights
50
+
51
+ The training signal is 100% verifiable β€” reward is computed by checking responses against ClinVar annotations, not scored by humans.
52
+
53
+ ---
54
+
55
+ ## Repository Structure
56
+
57
+ ```
58
+ genomic-reasoning-agent/
59
+ β”œβ”€β”€ genomic_pipeline.py # Step 1: Parse 23andMe .txt β†’ DataFrame
60
+ β”œβ”€β”€ clinvar_pipeline_full.py # Step 2: Annotate variants via ClinVar API
61
+ β”œβ”€β”€ genomic_agent_huggingface.py # Step 3: smolagents tool-using agent (5 tools)
62
+ β”œβ”€β”€ train_grpo.py # Step 4: GRPO training with TRL
63
+ β”œβ”€β”€ app.py # HF Spaces Gradio UI
64
+ β”œβ”€β”€ data/
65
+ β”‚ β”œβ”€β”€ clinvar_annotations.json # 12 variants with full ClinVar metadata
66
+ β”‚ └── genomic_qa_dataset.json # 36 Q&A pairs (3 task types Γ— 12 variants)
67
+ └── README.md
68
+ ```
69
+
70
+ ---
71
+
72
+ ## Pipeline: Step by Step
73
+
74
+ ### Step 1 β€” Parse 23andMe
75
+
76
+ Reads the raw `.txt` export (Build GRCh37) into a DataFrame of 631,455 SNPs.
77
+
78
+ ```python
79
+ from genomic_pipeline import parse_23andme
80
+ df = parse_23andme("genome_23andme.txt")
81
+ # β†’ 631,455 SNPs across chromosomes 1–22, X, Y, MT
82
+ # β†’ 104,617 heterozygous (16.6%) | 522,909 homozygous (82.8%)
83
+ ```
84
+
85
+ ### Step 2 β€” ClinVar Annotation
86
+
87
+ Queries NCBI E-utilities and GWAS Catalog for each rsID. Builds a Q&A dataset with verifiable answers.
88
+
89
+ ```python
90
+ from clinvar_pipeline_full import query_clinvar_batch, build_qa_dataset
91
+ annotations = query_clinvar_batch(rsids, email="your@email.com")
92
+ qa_dataset = build_qa_dataset(annotations, genome_df)
93
+ # β†’ 12 variants annotated
94
+ # β†’ 36 Q&A pairs: variant_interpretation / genotype_interpretation / pathway_reasoning
95
+ ```
96
+
97
+ **Sample annotation:**
98
+
99
+ | rsID | Gene | Genotype | Significance | Condition |
100
+ |------|------|----------|-------------|-----------|
101
+ | rs1801133 | MTHFR | GG | Pathogenic/Likely pathogenic | Homocystinuria |
102
+ | rs429358 + rs7412 | APOE | TT / CC | risk factor | Alzheimer disease |
103
+ | rs9939609 | FTO | AT | risk factor | Obesity |
104
+ | rs762551 | CYP1A2 | AC | drug response | Caffeine metabolism |
105
+
106
+ ### Step 3 β€” Tool-Using Agent (smolagents)
107
+
108
+ A `ToolCallingAgent` with 5 tools that plans multi-step queries across databases.
109
+
110
+ ```python
111
+ from smolagents import ToolCallingAgent, InferenceClientModel
112
+ from genomic_agent_huggingface import (
113
+ VariantLookupTool, # rsID β†’ ClinVar + genotype
114
+ GeneScannerTool, # gene/trait β†’ all patient variants
115
+ HaplotypeCallerTool, # APOE Ξ΅2/Ξ΅3/Ξ΅4 from two SNPs
116
+ GenomeStatsTool, # 631K SNPs overview
117
+ RewardEvaluatorTool, # GRPO reward score (used during training)
118
+ )
119
+ model = InferenceClientModel("meta-llama/Llama-3.1-8B-Instruct")
120
+ agent = ToolCallingAgent(tools=[...], model=model, max_steps=10)
121
+ answer = agent.run("What is my APOE haplotype and what does it mean?")
122
+ ```
123
+
124
+ **6-step reasoning trace for "Give me a genomic health summary":**
125
+
126
+ ```
127
+ Step 1 [genome_stats] β†’ 631,455 SNPs | 16.6% heterozygous
128
+ Step 2 [variant_lookup] β†’ rs1801133 | MTHFR | GG | Pathogenic
129
+ Step 3 [call_haplotype] β†’ APOE Ξ΅3/Ξ΅3 | Neutral Alzheimer's risk
130
+ Step 4 [scan_gene_variants] β†’ dopamine: ANKK1 GG (risk), COMT GG (Val/Val)
131
+ Step 5 [scan_gene_variants] β†’ caffeine: CYP1A2 AC (intermediate), ADORA2A CT
132
+ Step 6 [evaluate_reasoning] β†’ reward: 0.93 / 1.00 (excellent)
133
+ ```
134
+
135
+ ### Step 4 β€” GRPO Training
136
+
137
+ Trains the base LLM to reason better about genomic questions using reinforcement learning with verifiable rewards β€” no human annotation required.
138
+
139
+ ```python
140
+ from train_grpo import train, TrainingConfig
141
+ config = TrainingConfig(
142
+ model_name="meta-llama/Llama-3.1-8B-Instruct",
143
+ num_epochs=3,
144
+ num_generations=4, # G: completions per question
145
+ beta=0.04, # KL penalty
146
+ use_lora=True,
147
+ )
148
+ trainer = train(config)
149
+ ```
150
+
151
+ **Reward function β€” 6 verifiable components:**
152
+
153
+ | Component | Weight | Verifiable against |
154
+ |-----------|--------|--------------------|
155
+ | Factual accuracy | 0.35 | ClinVar clinical significance |
156
+ | Condition coverage | 0.25 | ClinVar associated conditions |
157
+ | Gene mention | 0.15 | ClinVar gene annotation |
158
+ | Reasoning chain | 0.15 | Presence of causal language |
159
+ | Uncertainty calibration | 0.05 | Hedging language |
160
+ | Response completeness | 0.05 | Word count |
161
+
162
+ **Training progression (simulated):**
163
+
164
+ ```
165
+ untrained reward=0.06 |β–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘|
166
+ epoch_1 reward=0.56 |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘|
167
+ epoch_3 reward=0.71 |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘|
168
+ epoch_5 reward=0.93 |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘|
169
+ epoch_10 reward=1.00 |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ|
170
+ ```
171
+
172
+ **GRPO advantage formula:**
173
+
174
+ ```
175
+ advantage_i = (reward_i βˆ’ mean(rewards)) / std(rewards)
176
+ No critic network. No value function. No human labeler.
177
+ Just relative comparison within each group of G=4 completions.
178
+ ```
179
+
180
+ ---
181
+
182
+ ## Key Results from Real Genome Data
183
+
184
+ Running the full pipeline on a real 23andMe export (Zalina Dezhina, v5 chip):
185
+
186
+ | Variant | Gene | Genotype | Clinical Note |
187
+ |---------|------|----------|---------------|
188
+ | πŸ”΄ rs1801133 | MTHFR | GG | Pathogenic β€” folate metabolism (p.Ala222Val) |
189
+ | 🟑 rs9939609 | FTO | **AT** | Risk factor β€” obesity, 1 risk allele (40.4% population) |
190
+ | 🧠 APOE | β€” | **Ξ΅3/Ξ΅3** | Neutral β€” most common haplotype, no elevated AD risk |
191
+ | πŸ’Š rs762551 | CYP1A2 | **AC** | Drug response β€” intermediate caffeine metabolizer |
192
+ | 🟑 rs1800497 | ANKK1 | GG | Risk factor β€” reward pathway / DRD2 association |
193
+ | 🟒 rs6265 | BDNF | CC | Benign (Val/Val) β€” better episodic memory |
194
+
195
+ > ⚠️ This is a research and portfolio project, not medical advice.
196
+ > All interpretations are for educational purposes only.
197
+
198
+ ---
199
+
200
+ ## Tech Stack
201
+
202
+ | Layer | Technology |
203
+ |-------|-----------|
204
+ | Genome parsing | pandas, Python |
205
+ | Variant annotation | NCBI E-utilities (ClinVar), EBI GWAS Catalog |
206
+ | Agentic framework | [smolagents](https://github.com/huggingface/smolagents) (HuggingFace) |
207
+ | RL training | [TRL](https://github.com/huggingface/trl) GRPOTrainer |
208
+ | Fine-tuning | LoRA (PEFT) + 4-bit quantization (bitsandbytes) |
209
+ | Base model | meta-llama/Llama-3.1-8B-Instruct |
210
+ | Demo UI | Gradio (HF Spaces) |
211
+ | Evaluation | Per-task reward breakdown, 3 task types |
212
+
213
+ ---
214
+
215
+ ## HuggingFace Deployment
216
+
217
+ **Spaces (interactive demo):**
218
+ ```
219
+ 1. Create new Space β†’ Gradio SDK
220
+ 2. Upload: genomic_agent_huggingface.py, app.py, data/
221
+ 3. Add secret: HF_TOKEN
222
+ 4. Upload your 23andMe .txt β†’ ask questions in chat
223
+ ```
224
+
225
+ **Model Hub (trained weights):**
226
+ ```python
227
+ trainer.push_to_hub("mioulin/genomic-reasoning-llm")
228
+ ```
229
+
230
+ **Dataset Hub:**
231
+ ```python
232
+ from datasets import Dataset
233
+ Dataset.from_list(qa_dataset).push_to_hub("mioulin/genomic-reasoning-qa")
234
+ ```
235
+
236
+ ---
237
+
238
+ ## Connection to ML Scientist Role
239
+
240
+ This project was built to demonstrate the exact skills required for ML Scientist roles in AIΓ—biology:
241
+
242
+ - **Agentic systems** β€” 5-tool ToolCallingAgent with multi-step planning
243
+ - **RL/RLHF training** β€” GRPO with verifiable reward, no human labelers
244
+ - **Biomedical data integration** β€” ClinVar, GWAS Catalog, gnomAD, PubMed
245
+ - **Evaluation framework** β€” 6-component reward breakdown across 3 task types
246
+ - **Real scientific domain** β€” 631,455 SNPs from real 23andMe genome
247
+ - **Reasoning over evidence** β€” multi-hop: SNP β†’ gene β†’ pathway β†’ phenotype
248
+
249
+ ---
250
+
251
+ ## Running Locally
252
+
253
+ ```bash
254
+ git clone https://huggingface.co/spaces/mioulin/genomic-reasoning-agent
255
+ cd genomic-reasoning-agent
256
+ pip install smolagents trl transformers accelerate peft datasets gradio
257
+ # Annotate your genome
258
+ python clinvar_pipeline_full.py \
259
+ --genome your_23andme.txt \
260
+ --output data/clinvar_annotations.json \
261
+ --email your@email.com
262
+ # Run agent (requires HF token for model inference)
263
+ export HF_TOKEN=hf_...
264
+ python genomic_agent_huggingface.py
265
+ # Train with GRPO (requires GPU)
266
+ python train_grpo.py \
267
+ --model meta-llama/Llama-3.1-8B-Instruct \
268
+ --epochs 3 --lora --G 4
269
+ ```
270
+
271
+ ---
272
+
273
+ ## Author
274
+
275
+ **Zalina Dezhina, PhD**
276
+ [![HuggingFace](https://img.shields.io/badge/πŸ€—-mioulin-yellow)](https://huggingface.co/mioulin)
277
+
278
+ ## Citation
279
+
280
+ ```bibtex
281
+ @misc{dezhina2026genomic,
282
+ title = {Genomic Reasoning Agent: GRPO Training on Personal SNP Data},
283
+ author = {Dezhina, Zalina},
284
+ year = {2026},
285
+ url = {https://huggingface.co/spaces/mioulin/genomic-reasoning-agent}
286
+ }
287
+ ```
288
+
289
+ ---
290
+
291
+ ## License
292
+
293
+ MIT β€” research and educational use only.
294
+ Not intended for clinical or medical decision-making.
295
+
296
+ ---
297
+
298
+ *Built with 🧬 smolagents · TRL · HuggingFace · ClinVar · 23andMe*