mltrackr 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,358 @@
1
+ Metadata-Version: 2.4
2
+ Name: mltrackr
3
+ Version: 0.3.0
4
+ Summary: Zero-setup ML experiment tracker with live dashboard, anomaly detection, and hyperparameter suggestions
5
+ License: MIT
6
+ Project-URL: Homepage, https://github.com/naialorente/datalog
7
+ Project-URL: Issues, https://github.com/naialorente/datalog/issues
8
+ Keywords: machine-learning,experiment-tracking,mlops,data-science,pytorch,scikit-learn,keras,huggingface,tensorflow,hyperparameter-tuning,model-monitoring,local-first,research,jupyter,kaggle,anomaly-detection,dashboard,experiment-logger,ml-tracker,training-monitor
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Intended Audience :: Education
13
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
14
+ Classifier: Topic :: Scientific/Engineering :: Visualization
15
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
+ Classifier: Topic :: Database
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Operating System :: OS Independent
25
+ Classifier: Environment :: Console
26
+ Classifier: Environment :: Web Environment
27
+ Requires-Python: >=3.8
28
+ Description-Content-Type: text/markdown
29
+ Requires-Dist: flask>=2.0
30
+ Requires-Dist: click>=8.0
31
+ Requires-Dist: rich>=13.0
32
+
33
+ # trainlog
34
+
35
+ > Track ML experiments in 2 lines of code. No server. No account. No config.
36
+
37
+ [![CI](https://github.com/NaiaLorente/datalog/actions/workflows/ci.yml/badge.svg)](https://github.com/NaiaLorente/datalog/actions/workflows/ci.yml)
38
+ [![PyPI](https://img.shields.io/pypi/v/mltrackr)](https://pypi.org/project/mltrackr/)
39
+ [![Python](https://img.shields.io/pypi/pyversions/mltrackr)](https://pypi.org/project/mltrackr/)
40
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
41
+ [![Stars](https://img.shields.io/github/stars/NaiaLorente/datalog?style=social)](https://github.com/NaiaLorente/datalog)
42
+
43
+ You're running a training loop. You want to know which hyperparameters worked best. You don't want to:
44
+
45
+ - Set up a tracking server
46
+ - Create an account on any service
47
+ - Write to a cloud API
48
+ - Configure environment variables
49
+ - Install 47 dependencies
50
+
51
+ **trainlog is the answer.** Install it, wrap your loop, open a beautiful local dashboard. Done.
52
+
53
+ ---
54
+
55
+ ## Quickstart (5 steps)
56
+
57
+ **1. Install**
58
+ ```bash
59
+ pip install mltrackr
60
+ ```
61
+ > This installs the `trainlog` command and `import trainlog` Python package.
62
+
63
+ **2. Generate a ready-to-run example**
64
+ ```bash
65
+ python -m trainlog.cli init --framework plain -o demo.py
66
+ ```
67
+ > On most systems `trainlog init` works directly. If not, use `python -m trainlog.cli` instead.
68
+
69
+ **3. Run the demo (creates 6 fake training runs)**
70
+ ```bash
71
+ python demo.py
72
+ ```
73
+
74
+ **4. Inspect results in the terminal**
75
+ ```bash
76
+ python -m trainlog.cli list
77
+ python -m trainlog.cli best accuracy
78
+ python -m trainlog.cli suggest accuracy
79
+ ```
80
+
81
+ **5. Open the visual dashboard**
82
+ ```bash
83
+ python -m trainlog.cli ui
84
+ ```
85
+ Then open **http://localhost:7000** in your browser. Press `Ctrl+C` to stop.
86
+
87
+ ---
88
+
89
+ ## Your first real experiment
90
+
91
+ ```python
92
+ import trainlog
93
+
94
+ with trainlog.run("resnet-baseline", tags=["cv", "baseline"]):
95
+ trainlog.log(lr=1e-3, batch_size=64, optimizer="adam")
96
+
97
+ for epoch in range(50):
98
+ loss, acc = train_one_epoch(model, dataloader)
99
+ trainlog.log(loss=loss, accuracy=acc, epoch=epoch)
100
+
101
+ trainlog.note("Solid baseline - try lr=5e-4 next")
102
+ ```
103
+
104
+ ```bash
105
+ # If 'trainlog' works directly on your system:
106
+ trainlog ui
107
+ trainlog list
108
+ trainlog best accuracy
109
+ trainlog suggest accuracy
110
+ trainlog report
111
+
112
+ # If not (e.g. Windows), use:
113
+ python -m trainlog.cli ui
114
+ python -m trainlog.cli list
115
+ python -m trainlog.cli best accuracy
116
+ ```
117
+
118
+ Everything is saved locally in `~/.trainlog/experiments.db`. A single SQLite file. Copy it, back it up, open it in any SQLite browser.
119
+
120
+ ---
121
+
122
+ ## Why trainlog?
123
+
124
+ **The real problem:** you're hacking on a model, you want to log some metrics, but setting up MLflow takes 15 minutes and W&B wants you to create an account and send your data to the cloud. So you end up writing metrics to a text file or just... not tracking anything. Then you forget which hyperparameters worked. Then you run the same failed experiment again.
125
+
126
+ **trainlog is the experiment tracker that's actually available when you need it.**
127
+
128
+ | | **trainlog** | **MLflow** | **Weights & Biases** |
129
+ |---|---|---|---|
130
+ | Setup time | **5 seconds** | ~15 minutes | ~5 minutes |
131
+ | Requires account | ❌ No | ❌ No | ✅ Yes |
132
+ | Requires running server | ❌ No | ✅ Yes | ❌ No (cloud) |
133
+ | Works offline | ✅ Always | ⚠️ Partial | ❌ No |
134
+ | Data stays local | ✅ Always | ✅ Yes | ❌ No |
135
+ | Live anomaly detection | ✅ Built-in | ❌ No | ⚠️ Paid |
136
+ | Hyperparameter suggestions | ✅ Built-in | ❌ No | ⚠️ Paid |
137
+ | Auto-generated reports | ✅ Built-in | ❌ No | ❌ No |
138
+ | Free forever | ✅ MIT | ✅ Apache | ⚠️ Usage limits |
139
+
140
+ ---
141
+
142
+ ## Features you'll actually use
143
+
144
+ ### ✅ Zero-friction tracking
145
+ Wrap any loop. Log any value. Works with every framework.
146
+ ```python
147
+ import trainlog
148
+
149
+ with trainlog.run("gpt-finetune", tags=["nlp", "v3"]):
150
+ trainlog.log(lr=2e-5, epochs=3, model="gpt2")
151
+ for step, batch in enumerate(dataloader):
152
+ loss = model.train_step(batch)
153
+ trainlog.log(loss=loss.item(), step=step)
154
+ ```
155
+
156
+ ### ✅ Beautiful live dashboard
157
+ ```bash
158
+ trainlog ui
159
+ ```
160
+ Opens at `http://localhost:7000` — a fast, dark-mode single-page app with:
161
+ - Searchable run list with **inline sparkline charts** in the sidebar
162
+ - **Trend indicators** (↑ ↓) showing whether each metric is improving
163
+ - **Side-by-side comparison** of any runs you select (best value highlighted)
164
+ - **Auto-generated time-series charts** with gradient fills
165
+ - **Metric progress bars** showing where the latest value sits in its historical range
166
+ - Global statistics view — success rate, most-logged metrics, run timeline
167
+ - Auto-refresh every 5 seconds — open while training, watch it update
168
+
169
+ ### ✅ Live anomaly detection — catch bad runs early
170
+ ```python
171
+ trainlog.configure_watch(nan_check=True, divergence_window=5, plateau_window=15)
172
+
173
+ with trainlog.run("training"):
174
+ for epoch in range(100):
175
+ trainlog.log(loss=compute_loss())
176
+ # Automatically warns if: loss → NaN, loss diverges for 5 epochs,
177
+ # loss plateaus for 15 epochs (and suggests adjusting LR)
178
+ ```
179
+ Stop wasting GPU hours on runs that are already failing.
180
+
181
+ ### ✅ Hyperparameter suggestions
182
+ ```bash
183
+ trainlog suggest accuracy
184
+ ```
185
+ Analyzes your run history and tells you which hyperparameter values are statistically correlated with better results. No black box — plain English insights like:
186
+ ```
187
+ Best config: lr=0.001 → avg accuracy 0.943 (vs 0.871 for other values, +8.2%)
188
+ Next experiment: try batch_size=128 — larger batches correlated with +5.1% accuracy
189
+ ```
190
+
191
+ ### ✅ Auto-generated experiment reports
192
+ ```bash
193
+ trainlog report --output results.md
194
+ ```
195
+ Generates a thesis-ready markdown report with:
196
+ - Summary statistics (total runs, completion rate, best configurations)
197
+ - Chronological experiment timeline
198
+ - Key findings (computed automatically)
199
+ - Notes from all your runs
200
+ - Optional AI narrative: `trainlog report --ai` (uses local Ollama, no API keys)
201
+
202
+ ### ✅ Generate a ready-to-run example
203
+ ```bash
204
+ trainlog init # plain Python example
205
+ trainlog init --framework pytorch # PyTorch training loop
206
+ trainlog init --framework sklearn # scikit-learn grid search
207
+ trainlog init --framework keras # Keras callback
208
+ ```
209
+ Generates a complete working script you can run immediately.
210
+
211
+ ### ✅ Works with every framework
212
+
213
+ | Framework | How |
214
+ |-----------|-----|
215
+ | **PyTorch** | `trainlog.log(loss=loss.item(), acc=acc)` inside the training loop |
216
+ | **scikit-learn** | `trainlog.log(**params, cv_score=score)` in your hyperparam loop |
217
+ | **Keras / TF** | One-file `TrainlogCallback` for `model.fit()` |
218
+ | **HuggingFace** | Custom `TrainerCallback` — see `examples/huggingface_example.py` |
219
+ | **XGBoost / LightGBM** | Log in the eval callback |
220
+ | **JAX / Flax** | Log at end of each training step |
221
+ | **Plain Python** | Anything that produces a number |
222
+
223
+ ---
224
+
225
+ ## Full API reference
226
+
227
+ ### Python API
228
+
229
+ ```python
230
+ import trainlog
231
+
232
+ # ── Tracking ──────────────────────────────────────────────────────────────────
233
+ with trainlog.run("name", tags=["tag1", "tag2"]) as run_id:
234
+ trainlog.log(accuracy=0.95, loss=0.05) # log any key-value pairs
235
+ trainlog.note("Cosine LR schedule helped a lot") # attach plain-text notes
236
+
237
+ trainlog.tag(run_id, "production") # add tags after the fact
238
+ trainlog.tag("experiment-name", "best") # also works by name
239
+
240
+ # ── Querying ──────────────────────────────────────────────────────────────────
241
+ runs = trainlog.get_runs() # all runs, newest first
242
+ best = trainlog.get_best_run("accuracy") # highest final value
243
+ best_low = trainlog.get_best_run("loss", mode="min") # lowest final value
244
+ cmp = trainlog.compare_runs(1, 2, 3) # list of run dicts
245
+
246
+ # ── Anomaly detection ─────────────────────────────────────────────────────────
247
+ trainlog.configure_watch(
248
+ nan_check=True, # warn on NaN/Inf values
249
+ divergence_window=5, # warn if metric diverges for N steps
250
+ plateau_window=15, # warn if metric plateaus for N steps
251
+ enabled=True,
252
+ )
253
+
254
+ # Or temporarily with a context manager:
255
+ with trainlog.watch(divergence_window=3):
256
+ # stricter watch for this block
257
+ trainlog.log(loss=0.5)
258
+
259
+ # ── Export & analysis ─────────────────────────────────────────────────────────
260
+ trainlog.export_csv("results.csv")
261
+ trainlog.export_json("results.json")
262
+ trainlog.generate_report("report.md", use_ollama=False)
263
+ suggestions = trainlog.suggest("accuracy", mode="max", top_n=3)
264
+ trainlog.clear_all() # deletes everything (irreversible)
265
+ ```
266
+
267
+ ### CLI reference
268
+
269
+ ```bash
270
+ # Dashboard
271
+ trainlog ui # open at localhost:7000
272
+ trainlog ui --port 8080 --no-browser # custom port, no auto-open
273
+
274
+ # Inspect runs
275
+ trainlog list # rich table, newest first
276
+ trainlog list --limit 50
277
+ trainlog compare 1 2 3 # side-by-side metric comparison
278
+ trainlog best accuracy # best run for a metric
279
+ trainlog best loss --mode min
280
+
281
+ # Annotate
282
+ trainlog tag 42 production tuned # add tags to run #42
283
+ trainlog note 42 "Try cosine annealing" # add note to run #42
284
+
285
+ # Analyse
286
+ trainlog stats # aggregate statistics
287
+ trainlog suggest accuracy # hyperparameter recommendations
288
+ trainlog suggest loss --mode min --top 5
289
+
290
+ # Generate
291
+ trainlog report # write report.md
292
+ trainlog report -o results.md --ai # with Ollama AI narrative
293
+ trainlog init --framework pytorch # generate example script
294
+
295
+ # Export / clean
296
+ trainlog export --format csv -o data.csv
297
+ trainlog export --format json -o data.json
298
+ trainlog clear # delete all (asks confirmation)
299
+ ```
300
+
301
+ ---
302
+
303
+ ## How it works
304
+
305
+ - **SQLite** — `~/.trainlog/experiments.db`. One file. No server. Inspect it with any SQLite browser. Back it up with `cp`.
306
+ - **Flask** — the dashboard is a local Flask server. Vanilla JS, Chart.js, zero npm, zero build step.
307
+ - **Thread-local state** — each training job in its own thread gets an isolated run context. Concurrent experiments just work.
308
+ - **Git-aware** — captures the current commit hash via `git rev-parse HEAD`. Silently skipped outside a git repo.
309
+ - **Watch hooks** — anomaly detection runs inside every `log()` call. Zero external services, works offline.
310
+
311
+ ---
312
+
313
+ ## Quickstart with examples
314
+
315
+ ```bash
316
+ trainlog init --framework pytorch -o train.py
317
+ python train.py
318
+ trainlog ui
319
+ ```
320
+
321
+ That's the whole flow. Five commands. Zero config.
322
+
323
+ ---
324
+
325
+ ## Roadmap
326
+
327
+ **Done ✅**
328
+ - Live anomaly detection (`configure_watch`)
329
+ - Auto-generated experiment reports (`trainlog report`, Ollama support)
330
+ - Hyperparameter suggestions (`trainlog suggest`)
331
+ - Quick-start example generator (`trainlog init`)
332
+ - Sparkline charts in sidebar with trend indicators
333
+ - Metric progress bars and trend arrows in detail view
334
+ - Framework examples: PyTorch, scikit-learn, Keras, HuggingFace
335
+
336
+ **Coming up**
337
+ - [ ] `trainlog.log_artifact("model.pt")` — save file paths alongside metrics
338
+ - [ ] Native PyTorch `TrainlogCallback` (pip-installable plugin)
339
+ - [ ] VS Code extension — inline run summary on hover
340
+ - [ ] `trainlog serve` — shareable read-only dashboard URL (ngrok/localtunnel)
341
+ - [ ] Team sync via shared git-tracked SQLite
342
+ - [ ] Slack / Discord webhook on run completion
343
+
344
+ Have an idea? [Open a feature request](https://github.com/NaiaLorente/datalog/issues/new) — or submit a PR.
345
+
346
+ ---
347
+
348
+ ## Contributing
349
+
350
+ See [CONTRIBUTING.md](CONTRIBUTING.md). TL;DR: `pip install -e .`, make your change, open a PR.
351
+
352
+ All contributions welcome — typos, docs, features, bug fixes.
353
+
354
+ ---
355
+
356
+ ## License
357
+
358
+ MIT — use it however you want, forever.
@@ -0,0 +1,326 @@
1
+ # trainlog
2
+
3
+ > Track ML experiments in 2 lines of code. No server. No account. No config.
4
+
5
+ [![CI](https://github.com/NaiaLorente/datalog/actions/workflows/ci.yml/badge.svg)](https://github.com/NaiaLorente/datalog/actions/workflows/ci.yml)
6
+ [![PyPI](https://img.shields.io/pypi/v/mltrackr)](https://pypi.org/project/mltrackr/)
7
+ [![Python](https://img.shields.io/pypi/pyversions/mltrackr)](https://pypi.org/project/mltrackr/)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
9
+ [![Stars](https://img.shields.io/github/stars/NaiaLorente/datalog?style=social)](https://github.com/NaiaLorente/datalog)
10
+
11
+ You're running a training loop. You want to know which hyperparameters worked best. You don't want to:
12
+
13
+ - Set up a tracking server
14
+ - Create an account on any service
15
+ - Write to a cloud API
16
+ - Configure environment variables
17
+ - Install 47 dependencies
18
+
19
+ **trainlog is the answer.** Install it, wrap your loop, open a beautiful local dashboard. Done.
20
+
21
+ ---
22
+
23
+ ## Quickstart (5 steps)
24
+
25
+ **1. Install**
26
+ ```bash
27
+ pip install mltrackr
28
+ ```
29
+ > This installs the `trainlog` command and `import trainlog` Python package.
30
+
31
+ **2. Generate a ready-to-run example**
32
+ ```bash
33
+ python -m trainlog.cli init --framework plain -o demo.py
34
+ ```
35
+ > On most systems `trainlog init` works directly. If not, use `python -m trainlog.cli` instead.
36
+
37
+ **3. Run the demo (creates 6 fake training runs)**
38
+ ```bash
39
+ python demo.py
40
+ ```
41
+
42
+ **4. Inspect results in the terminal**
43
+ ```bash
44
+ python -m trainlog.cli list
45
+ python -m trainlog.cli best accuracy
46
+ python -m trainlog.cli suggest accuracy
47
+ ```
48
+
49
+ **5. Open the visual dashboard**
50
+ ```bash
51
+ python -m trainlog.cli ui
52
+ ```
53
+ Then open **http://localhost:7000** in your browser. Press `Ctrl+C` to stop.
54
+
55
+ ---
56
+
57
+ ## Your first real experiment
58
+
59
+ ```python
60
+ import trainlog
61
+
62
+ with trainlog.run("resnet-baseline", tags=["cv", "baseline"]):
63
+ trainlog.log(lr=1e-3, batch_size=64, optimizer="adam")
64
+
65
+ for epoch in range(50):
66
+ loss, acc = train_one_epoch(model, dataloader)
67
+ trainlog.log(loss=loss, accuracy=acc, epoch=epoch)
68
+
69
+ trainlog.note("Solid baseline - try lr=5e-4 next")
70
+ ```
71
+
72
+ ```bash
73
+ # If 'trainlog' works directly on your system:
74
+ trainlog ui
75
+ trainlog list
76
+ trainlog best accuracy
77
+ trainlog suggest accuracy
78
+ trainlog report
79
+
80
+ # If not (e.g. Windows), use:
81
+ python -m trainlog.cli ui
82
+ python -m trainlog.cli list
83
+ python -m trainlog.cli best accuracy
84
+ ```
85
+
86
+ Everything is saved locally in `~/.trainlog/experiments.db`. A single SQLite file. Copy it, back it up, open it in any SQLite browser.
87
+
88
+ ---
89
+
90
+ ## Why trainlog?
91
+
92
+ **The real problem:** you're hacking on a model, you want to log some metrics, but setting up MLflow takes 15 minutes and W&B wants you to create an account and send your data to the cloud. So you end up writing metrics to a text file or just... not tracking anything. Then you forget which hyperparameters worked. Then you run the same failed experiment again.
93
+
94
+ **trainlog is the experiment tracker that's actually available when you need it.**
95
+
96
+ | | **trainlog** | **MLflow** | **Weights & Biases** |
97
+ |---|---|---|---|
98
+ | Setup time | **5 seconds** | ~15 minutes | ~5 minutes |
99
+ | Requires account | ❌ No | ❌ No | ✅ Yes |
100
+ | Requires running server | ❌ No | ✅ Yes | ❌ No (cloud) |
101
+ | Works offline | ✅ Always | ⚠️ Partial | ❌ No |
102
+ | Data stays local | ✅ Always | ✅ Yes | ❌ No |
103
+ | Live anomaly detection | ✅ Built-in | ❌ No | ⚠️ Paid |
104
+ | Hyperparameter suggestions | ✅ Built-in | ❌ No | ⚠️ Paid |
105
+ | Auto-generated reports | ✅ Built-in | ❌ No | ❌ No |
106
+ | Free forever | ✅ MIT | ✅ Apache | ⚠️ Usage limits |
107
+
108
+ ---
109
+
110
+ ## Features you'll actually use
111
+
112
+ ### ✅ Zero-friction tracking
113
+ Wrap any loop. Log any value. Works with every framework.
114
+ ```python
115
+ import trainlog
116
+
117
+ with trainlog.run("gpt-finetune", tags=["nlp", "v3"]):
118
+ trainlog.log(lr=2e-5, epochs=3, model="gpt2")
119
+ for step, batch in enumerate(dataloader):
120
+ loss = model.train_step(batch)
121
+ trainlog.log(loss=loss.item(), step=step)
122
+ ```
123
+
124
+ ### ✅ Beautiful live dashboard
125
+ ```bash
126
+ trainlog ui
127
+ ```
128
+ Opens at `http://localhost:7000` — a fast, dark-mode single-page app with:
129
+ - Searchable run list with **inline sparkline charts** in the sidebar
130
+ - **Trend indicators** (↑ ↓) showing whether each metric is improving
131
+ - **Side-by-side comparison** of any runs you select (best value highlighted)
132
+ - **Auto-generated time-series charts** with gradient fills
133
+ - **Metric progress bars** showing where the latest value sits in its historical range
134
+ - Global statistics view — success rate, most-logged metrics, run timeline
135
+ - Auto-refresh every 5 seconds — open while training, watch it update
136
+
137
+ ### ✅ Live anomaly detection — catch bad runs early
138
+ ```python
139
+ trainlog.configure_watch(nan_check=True, divergence_window=5, plateau_window=15)
140
+
141
+ with trainlog.run("training"):
142
+ for epoch in range(100):
143
+ trainlog.log(loss=compute_loss())
144
+ # Automatically warns if: loss → NaN, loss diverges for 5 epochs,
145
+ # loss plateaus for 15 epochs (and suggests adjusting LR)
146
+ ```
147
+ Stop wasting GPU hours on runs that are already failing.
148
+
149
+ ### ✅ Hyperparameter suggestions
150
+ ```bash
151
+ trainlog suggest accuracy
152
+ ```
153
+ Analyzes your run history and tells you which hyperparameter values are statistically correlated with better results. No black box — plain English insights like:
154
+ ```
155
+ Best config: lr=0.001 → avg accuracy 0.943 (vs 0.871 for other values, +8.2%)
156
+ Next experiment: try batch_size=128 — larger batches correlated with +5.1% accuracy
157
+ ```
158
+
159
+ ### ✅ Auto-generated experiment reports
160
+ ```bash
161
+ trainlog report --output results.md
162
+ ```
163
+ Generates a thesis-ready markdown report with:
164
+ - Summary statistics (total runs, completion rate, best configurations)
165
+ - Chronological experiment timeline
166
+ - Key findings (computed automatically)
167
+ - Notes from all your runs
168
+ - Optional AI narrative: `trainlog report --ai` (uses local Ollama, no API keys)
169
+
170
+ ### ✅ Generate a ready-to-run example
171
+ ```bash
172
+ trainlog init # plain Python example
173
+ trainlog init --framework pytorch # PyTorch training loop
174
+ trainlog init --framework sklearn # scikit-learn grid search
175
+ trainlog init --framework keras # Keras callback
176
+ ```
177
+ Generates a complete working script you can run immediately.
178
+
179
+ ### ✅ Works with every framework
180
+
181
+ | Framework | How |
182
+ |-----------|-----|
183
+ | **PyTorch** | `trainlog.log(loss=loss.item(), acc=acc)` inside the training loop |
184
+ | **scikit-learn** | `trainlog.log(**params, cv_score=score)` in your hyperparam loop |
185
+ | **Keras / TF** | One-file `TrainlogCallback` for `model.fit()` |
186
+ | **HuggingFace** | Custom `TrainerCallback` — see `examples/huggingface_example.py` |
187
+ | **XGBoost / LightGBM** | Log in the eval callback |
188
+ | **JAX / Flax** | Log at end of each training step |
189
+ | **Plain Python** | Anything that produces a number |
190
+
191
+ ---
192
+
193
+ ## Full API reference
194
+
195
+ ### Python API
196
+
197
+ ```python
198
+ import trainlog
199
+
200
+ # ── Tracking ──────────────────────────────────────────────────────────────────
201
+ with trainlog.run("name", tags=["tag1", "tag2"]) as run_id:
202
+ trainlog.log(accuracy=0.95, loss=0.05) # log any key-value pairs
203
+ trainlog.note("Cosine LR schedule helped a lot") # attach plain-text notes
204
+
205
+ trainlog.tag(run_id, "production") # add tags after the fact
206
+ trainlog.tag("experiment-name", "best") # also works by name
207
+
208
+ # ── Querying ──────────────────────────────────────────────────────────────────
209
+ runs = trainlog.get_runs() # all runs, newest first
210
+ best = trainlog.get_best_run("accuracy") # highest final value
211
+ best_low = trainlog.get_best_run("loss", mode="min") # lowest final value
212
+ cmp = trainlog.compare_runs(1, 2, 3) # list of run dicts
213
+
214
+ # ── Anomaly detection ─────────────────────────────────────────────────────────
215
+ trainlog.configure_watch(
216
+ nan_check=True, # warn on NaN/Inf values
217
+ divergence_window=5, # warn if metric diverges for N steps
218
+ plateau_window=15, # warn if metric plateaus for N steps
219
+ enabled=True,
220
+ )
221
+
222
+ # Or temporarily with a context manager:
223
+ with trainlog.watch(divergence_window=3):
224
+ # stricter watch for this block
225
+ trainlog.log(loss=0.5)
226
+
227
+ # ── Export & analysis ─────────────────────────────────────────────────────────
228
+ trainlog.export_csv("results.csv")
229
+ trainlog.export_json("results.json")
230
+ trainlog.generate_report("report.md", use_ollama=False)
231
+ suggestions = trainlog.suggest("accuracy", mode="max", top_n=3)
232
+ trainlog.clear_all() # deletes everything (irreversible)
233
+ ```
234
+
235
+ ### CLI reference
236
+
237
+ ```bash
238
+ # Dashboard
239
+ trainlog ui # open at localhost:7000
240
+ trainlog ui --port 8080 --no-browser # custom port, no auto-open
241
+
242
+ # Inspect runs
243
+ trainlog list # rich table, newest first
244
+ trainlog list --limit 50
245
+ trainlog compare 1 2 3 # side-by-side metric comparison
246
+ trainlog best accuracy # best run for a metric
247
+ trainlog best loss --mode min
248
+
249
+ # Annotate
250
+ trainlog tag 42 production tuned # add tags to run #42
251
+ trainlog note 42 "Try cosine annealing" # add note to run #42
252
+
253
+ # Analyse
254
+ trainlog stats # aggregate statistics
255
+ trainlog suggest accuracy # hyperparameter recommendations
256
+ trainlog suggest loss --mode min --top 5
257
+
258
+ # Generate
259
+ trainlog report # write report.md
260
+ trainlog report -o results.md --ai # with Ollama AI narrative
261
+ trainlog init --framework pytorch # generate example script
262
+
263
+ # Export / clean
264
+ trainlog export --format csv -o data.csv
265
+ trainlog export --format json -o data.json
266
+ trainlog clear # delete all (asks confirmation)
267
+ ```
268
+
269
+ ---
270
+
271
+ ## How it works
272
+
273
+ - **SQLite** — `~/.trainlog/experiments.db`. One file. No server. Inspect it with any SQLite browser. Back it up with `cp`.
274
+ - **Flask** — the dashboard is a local Flask server. Vanilla JS, Chart.js, zero npm, zero build step.
275
+ - **Thread-local state** — each training job in its own thread gets an isolated run context. Concurrent experiments just work.
276
+ - **Git-aware** — captures the current commit hash via `git rev-parse HEAD`. Silently skipped outside a git repo.
277
+ - **Watch hooks** — anomaly detection runs inside every `log()` call. Zero external services, works offline.
278
+
279
+ ---
280
+
281
+ ## Quickstart with examples
282
+
283
+ ```bash
284
+ trainlog init --framework pytorch -o train.py
285
+ python train.py
286
+ trainlog ui
287
+ ```
288
+
289
+ That's the whole flow. Five commands. Zero config.
290
+
291
+ ---
292
+
293
+ ## Roadmap
294
+
295
+ **Done ✅**
296
+ - Live anomaly detection (`configure_watch`)
297
+ - Auto-generated experiment reports (`trainlog report`, Ollama support)
298
+ - Hyperparameter suggestions (`trainlog suggest`)
299
+ - Quick-start example generator (`trainlog init`)
300
+ - Sparkline charts in sidebar with trend indicators
301
+ - Metric progress bars and trend arrows in detail view
302
+ - Framework examples: PyTorch, scikit-learn, Keras, HuggingFace
303
+
304
+ **Coming up**
305
+ - [ ] `trainlog.log_artifact("model.pt")` — save file paths alongside metrics
306
+ - [ ] Native PyTorch `TrainlogCallback` (pip-installable plugin)
307
+ - [ ] VS Code extension — inline run summary on hover
308
+ - [ ] `trainlog serve` — shareable read-only dashboard URL (ngrok/localtunnel)
309
+ - [ ] Team sync via shared git-tracked SQLite
310
+ - [ ] Slack / Discord webhook on run completion
311
+
312
+ Have an idea? [Open a feature request](https://github.com/NaiaLorente/datalog/issues/new) — or submit a PR.
313
+
314
+ ---
315
+
316
+ ## Contributing
317
+
318
+ See [CONTRIBUTING.md](CONTRIBUTING.md). TL;DR: `pip install -e .`, make your change, open a PR.
319
+
320
+ All contributions welcome — typos, docs, features, bug fixes.
321
+
322
+ ---
323
+
324
+ ## License
325
+
326
+ MIT — use it however you want, forever.