goal-augment
LLM-based factorised data augmentation for health-coaching goal extraction.
goal-augment learns the patterns hidden in a small corpus of real, annotated health-coaching notes — how goals are phrased, how notes are structured, and who the patients are — then recombines those patterns to generate an unlimited supply of realistic synthetic notes with labelled goal spans. The result is training data for goal-extraction models, produced without hand-annotating hundreds of notes.
Tags: data-augmentation · synthetic-data · llm · nlp · health-coaching · goal-extraction · span-labeling · gemini · streamlit · smart-goals · back-translation · paraphrase-generation · cycle-consistency · few-shot-learning · clinical-nlp
Novelty & contributions
Most LLM data-augmentation pipelines paraphrase whole examples and hope the labels survive. goal-augment takes a different route, and that difference is the point:
| # |
Contribution |
Why it’s novel |
| 1 |
Factorised, compositional generation |
A note is decomposed into independent axes — goal attributes, structure, persona — learned separately and re-sampled. This synthesises attribute combinations that never co-occurred in the source corpus, extending coverage instead of merely rewording it. |
| 2 |
Distribution-faithful sampling |
Every axis is sampled from empirical corpus distributions (goal-type frequencies, SMART profiles, structure templates), so the synthetic set stays statistically aligned with real data rather than collapsing to an LLM’s default style. |
| 3 |
Controllable SMART-ness |
Goals are generated against explicit SMART_profile vectors (specific / measurable / time-bound / realistic), giving fine-grained control over goal quality — including deliberately under-specified goals for robustness. |
| 4 |
Label-preserving by construction |
Spans are known before generation and re-verified after via cycle consistency, sidestepping the label-drift that plagues paraphrase-based augmentation. |
| 5 |
Cycle-consistency validation |
Each generated note is re-labelled by the model and the recovered spans are compared to the intended ones (exact / partial_f1 / token_f1 / span_overlap); notes below threshold are rejected and checkpointed for later re-evaluation — no regeneration needed. |
| 6 |
Multi-strategy, one framework |
From-scratch generation, back-translation, constrained rephrasing, and contrastive style-pairs live behind a single CLI and a shared validation gauntlet, so strategies can be mixed and compared apples-to-apples. |
| 7 |
Human-in-the-loop evaluation |
A built-in blind real-vs-synthetic “evaluation game” in the Streamlit UI turns quality assessment into a measurable Turing-style test rather than a vibe check. |
| 8 |
Reproducible-by-config |
One TOML per dataset means a config deterministically maps to an output pipeline (aside from inherent LLM stochasticity), making experiments auditable and re-runnable. |
flowchart LR
subgraph Conventional["Conventional augmentation"]
direction TB
C1[Whole note] --> C2[Paraphrase] --> C3[Label drift?]
end
subgraph GoalAugment["goal-augment (factorised)"]
direction TB
G1[Goal attrs] --> G4[Compose]
G2[Structure] --> G4
G3[Persona] --> G4
G4 --> G5[Generate] --> G6[Cycle-consistency check]
end
Table of contents
Why factorised augmentation?
Real coaching notes contain reusable, separable patterns. Instead of paraphrasing whole notes (which drifts and loses labels), goal-augment factorises a note into independent axes, learns the real-world distribution of each axis, then samples and re-composes them:
| Axis |
What is learned |
Examples |
| Goal attributes |
Type, activity, frequency, duration, specificity, timeframe, conditionality, confidence, SMART scores |
“jog 30 min every Saturday for 4 weeks (confidence 75%)” |
| Structure |
Note format, section sequence, voice, tense |
numbered list · SOAP · narrative · bullet points |
| Persona |
Demographics, life circumstances, behaviour, health literacy, psychological state, barriers |
“all-or-nothing thinker, new job, tech-comfortable” |
Because the axes are sampled independently from corpus-derived distributions, the synthetic set covers combinations that never co-occurred in the original data while staying statistically faithful to it.
How it works
flowchart TD
A[Real annotated notes] --> B{Phase 1: Learn patterns}
B --> B1[enrich-goals\nGoal attributes]
B --> B2[analyze-structures\nStructure patterns]
B --> B3[extract-personas\nPersona elements]
B1 --> C[Pattern library\n+ distributions]
B2 --> C
B3 --> C
C --> D{Phase 2: Sample & compose}
D --> E[Generation config\nfactorised sample]
E --> F[Phase 3: LLM generation\ngenerate-notes]
F --> G{Phase 4: Validate}
G -->|pass| H[Synthetic annotated notes]
G -->|fail| R[Rejected checkpoints\nfor debugging]
H --> I[label-goals\nspan extraction / QA]
Phase 1 — Resource extraction (one-time). Three LLM passes over the corpus build a reusable pattern library and the distribution statistics that drive sampling.
Phase 2/3 — Sampling & generation. For each new note, a config is sampled: num_goals, a SMART_profile, per-goal attributes drawn from the corpus distributions, a structure template, and a compositional persona. The config becomes a few-shot prompt that generates the note.
Phase 4 — Validation. Each note runs a gauntlet of rule-based filters, cycle-consistency re-labelling, and structured quality checks (see Validation pipeline).
Augmentation strategies
Beyond from-scratch generation, the framework ships several complementary strategies, each with its own config:
| Strategy |
Command |
Config |
Idea |
| From-scratch generation |
generate-notes |
generator.toml |
Compose a fresh note from a factorised sample of goals, structure, and persona. |
| Back-translation |
backtranslate |
backtranslation.toml |
Round-trip a note through another language to induce natural paraphrase while preserving labels. |
| Rephrasing |
rephrase |
rephrasing.toml |
Directly reword an existing note under constraints, keeping goal spans intact. |
| Style contrast |
create-style-pairs |
style_contrast.toml |
Build contrastive pairs that hold content fixed while varying style, for robustness training. |
Repository layout
goal-augment/
├── src/
│ ├── main.py # Click CLI entry point (all commands)
│ ├── config/ # TOML config loading
│ ├── data_processing/ # Corpus loaders
│ ├── llm/ # LLM clients (base + Gemini / OpenAI-compatible)
│ ├── preprocessing/ # Phase 1: goal enricher, structure & persona analyzers
│ ├── generation/ # Sampling, prompt building, generators, validation
│ └── labeling/ # Span extraction, few-shot sampling, evaluation
├── ui/ # Streamlit app for browsing / editing / evaluating data
├── scratch/ # Analysis & debugging utilities (t-SNE, clustering, ...)
├── *.toml # One config per task (generator, enricher, labeler, ...)
├── SYSTEM_OVERVIEW.md # Deep-dive on the architecture
├── RUNNING_DATA_AUG.md # Operator / handover guide
├── Ideas.md # Design notes & the augmentation taxonomy
└── pyproject.toml # Dependencies (managed with uv)
Config files come in variants (*_newdata.toml, *_olddata.toml, *_all.toml) so a given dataset maps to a fixed, reproducible config — the same config yields the same output (aside from inherent LLM variability).
Installation
Requires Python ≥ 3.10 and uv.
# 1. Clone
git clone https://github.com/Krishita17/goal-augment.git
cd goal-augment
# 2. Install dependencies
uv sync
# 3. Configure API access (never commit this file)
cp .env.example .env # then edit with your key
Create a .env with the LLM gateway settings:
GEMINI_API_KEY=your-key-here
GATEWAY_BASE_URL=https://your-openai-compatible-gateway/v1
GATEWAY_MODEL_PREFIX=your-provider-prefix
GATEWAY_MAX_TOKENS=8192
Quickstart
sequenceDiagram
participant U as You
participant P1 as Phase 1 (learn)
participant Gen as generate-notes
participant UI as Streamlit UI
U->>P1: enrich-goals / analyze-structures / extract-personas
P1-->>U: pattern library + distributions
U->>Gen: generate-notes --target-count 100
Gen-->>U: synthetic notes + rejected checkpoints
U->>UI: inspect, highlight goals, mark rejections
# First time: build the pattern library (Phase 1)
uv run python src/main.py --config goal_span_enricher.toml enrich-goals
uv run python src/main.py --config structure_analyzer.toml analyze-structures
uv run python src/main.py --config persona_extractor.toml extract-personas
# Generate synthetic notes
uv run python src/main.py --config generator.toml generate-notes --target-count 100
# Inspect everything in the UI
cd ui && uv run streamlit run app.py
Every command supports --debug (process a single record) and --dry-run (change nothing on disk) — use them freely while iterating.
CLI reference
All commands share the form:
uv run python src/main.py --config <config>.toml [--debug] [--dry-run] <command> [options]
| Command |
Default config |
What it does |
enrich-goals |
goal_span_enricher.toml |
Extract structured goal attributes from the corpus |
analyze-structures |
structure_analyzer.toml |
Extract note structure patterns |
extract-personas |
persona_extractor.toml |
Extract compositional persona elements |
generate-notes |
generator.toml |
Generate & validate synthetic notes |
backtranslate |
backtranslation.toml |
Augment via round-trip translation |
rephrase |
rephrasing.toml |
Augment via constrained rephrasing |
create-style-pairs |
style_contrast.toml |
Build contrastive style pairs |
label-goals |
goal_span_labeler.toml |
Extract / QA goal spans from notes |
test-connection |
any |
Smoke-test the LLM gateway |
info |
any |
Print resolved config and data stats |
Selected options
| Flag |
Applies to |
Effect |
--debug |
global |
Process only the first example |
--dry-run |
global |
Do not write anything to disk |
--target-count N |
generation strategies |
Override the note count from config |
--force-recompute |
preprocessing |
Ignore checkpoints and recompute |
--batch |
most |
Use async batch mode (~50% cost) |
--recheck-rejected |
generate-notes |
Re-run validation on rejected checkpoints only |
--rejected-from N |
generate-notes |
Start rechecking from rejected_NNNN.json |
--rejected-error STR |
generate-notes |
Only recheck rejects whose error contains STR |
--promote-passed / --no-promote-passed |
generate-notes |
Promote passing rejects into accepted checkpoints |
--input-file PATH |
label-goals |
Override the input corpus file |
Configuration
Everything tunable lives in TOML — no magic numbers in code. Key sections of generator.toml:
[llm]
model = "gemini-2.5-pro" # or "gemini-2.5-flash" for faster / cheaper
[generation]
target_count = 10 # how many accepted notes to produce
[validation]
enable_cycle_consistency = true
cycle_consistency_threshold = 1.0 # lower = accept more notes
validation_metric = "partial_f1" # exact | partial_f1 | token_f1 | span_overlap
save_rejected = true # keep rejects for debugging
| Section |
Purpose |
[paths] |
Input corpus and output locations |
[llm] |
Model, temperature, token budget |
[sampling] |
Distributions for goal count, SMART profiles, attributes |
[structure] |
Structure-template sampling |
[generation] |
Target counts, few-shot settings |
[validation] |
Metric, thresholds, reject handling |
[batch] |
Async batch-mode settings |
[prompts] |
Prompt templates |
Validation pipeline
flowchart LR
N[Generated note] --> F[Rule-based filters\nlength, goal count,\nimpossible values]
F -->|reject| X[Rejected]
F -->|pass| C[Cycle consistency\nre-label & compare spans]
C -->|below threshold| X
C -->|pass| Q[Structured quality check\ntemporal / alignment / coherence]
Q -->|low score| X
Q -->|accept| A[Accepted synthetic note]
- Fast rule-based filters — reject instantly on note-too-short, missing/extra goals, or impossible values (e.g. “100x per week”).
- Cycle consistency — re-extract goal spans from the generated note and compare against the intended spans using the configured metric; accept only above
cycle_consistency_threshold.
- Structured quality check — an LLM function-call scores temporal validity, contextual alignment, confidence calibration, and structural coherence.
Rejected notes are checkpointed (when save_rejected = true) and can be re-evaluated later with --recheck-rejected without regenerating.
The Streamlit UI
cd ui && uv run streamlit run app.py
| Page |
Purpose |
| Enriched Goals |
Browse / edit goal-attribute extraction |
| Structure Analysis |
View / edit note structure patterns |
| Persona Elements |
View / edit extracted persona data |
| Generated Notes |
Inspect synthetic notes, highlight goals, mark rejections |
| Library |
View distributions (goal types, frequencies, SMART profiles) |
| Evaluation Game |
Blind real-vs-synthetic comparison |
Safe editing: original files are never modified — edits are written to separate *_edited.json files.
Outputs
output/
├── enriched_goals_all.json # goal attributes (enrich-goals)
├── structure_library.json # structure patterns (analyze-structures)
├── persona_library.json # persona frequencies (extract-personas)
├── synthetic_notes.json # generated notes (aggregated)
└── checkpoints/
├── generator/synth_NNNN.json # individual accepted notes
└── rejected/rejected_NNNN.json # rejected notes (if enabled)
output/, data/, and scratch/datasets/ are git-ignored — generated artefacts and datasets stay local.
Contributing
This is a research project maintained by a single author (see below). Issues and suggestions are welcome via the GitHub tracker. When contributing code, please keep to the project conventions: DRY, TOML config over hardcoded constants, docstrings on every function, and uv for dependency management.
License
No license is currently specified. All rights reserved by the author until a license is added; contact the maintainer before reuse.
Maintainer: Krishita Sanjay Choksi (@Krishita17)
评论