trainlens 0.1.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.
Files changed (87) hide show
  1. trainlens-0.1.0/.env.example +3 -0
  2. trainlens-0.1.0/.gitattributes +8 -0
  3. trainlens-0.1.0/.github/ISSUE_TEMPLATE/bug_report.md +13 -0
  4. trainlens-0.1.0/.github/ISSUE_TEMPLATE/feature_request.md +11 -0
  5. trainlens-0.1.0/.github/pull_request_template.md +5 -0
  6. trainlens-0.1.0/.github/workflows/ci.yml +24 -0
  7. trainlens-0.1.0/.gitignore +15 -0
  8. trainlens-0.1.0/CHANGELOG.md +17 -0
  9. trainlens-0.1.0/CITATION.cff +19 -0
  10. trainlens-0.1.0/CODE_OF_CONDUCT.md +5 -0
  11. trainlens-0.1.0/CONTRIBUTING.md +34 -0
  12. trainlens-0.1.0/LICENSE +158 -0
  13. trainlens-0.1.0/PKG-INFO +174 -0
  14. trainlens-0.1.0/README.md +139 -0
  15. trainlens-0.1.0/SECURITY.md +9 -0
  16. trainlens-0.1.0/docs/architecture.md +50 -0
  17. trainlens-0.1.0/docs/live-notebook-cells.md +50 -0
  18. trainlens-0.1.0/docs/plugin-authoring.md +16 -0
  19. trainlens-0.1.0/docs/release.md +50 -0
  20. trainlens-0.1.0/docs/report-sections.md +35 -0
  21. trainlens-0.1.0/docs/roadmap.md +25 -0
  22. trainlens-0.1.0/examples/basic_usage.py +26 -0
  23. trainlens-0.1.0/examples/pytorch_loop_metrics.py +51 -0
  24. trainlens-0.1.0/notebooks/README.md +23 -0
  25. trainlens-0.1.0/notebooks/clip_contrastive_report.ipynb +89 -0
  26. trainlens-0.1.0/notebooks/llm_finetune_report.ipynb +90 -0
  27. trainlens-0.1.0/notebooks/vlm_projector_report.ipynb +91 -0
  28. trainlens-0.1.0/pyproject.toml +66 -0
  29. trainlens-0.1.0/src/trainlens/__init__.py +19 -0
  30. trainlens-0.1.0/src/trainlens/analyzers/__init__.py +7 -0
  31. trainlens-0.1.0/src/trainlens/analyzers/base.py +19 -0
  32. trainlens-0.1.0/src/trainlens/analyzers/metrics.py +230 -0
  33. trainlens-0.1.0/src/trainlens/analyzers/registry.py +31 -0
  34. trainlens-0.1.0/src/trainlens/analyzers/traces.py +121 -0
  35. trainlens-0.1.0/src/trainlens/analyzers/training.py +138 -0
  36. trainlens-0.1.0/src/trainlens/heuristics/__init__.py +27 -0
  37. trainlens-0.1.0/src/trainlens/heuristics/balance.py +31 -0
  38. trainlens-0.1.0/src/trainlens/heuristics/features.py +36 -0
  39. trainlens-0.1.0/src/trainlens/heuristics/foundation.py +243 -0
  40. trainlens-0.1.0/src/trainlens/heuristics/metrics.py +48 -0
  41. trainlens-0.1.0/src/trainlens/introspection/__init__.py +6 -0
  42. trainlens-0.1.0/src/trainlens/introspection/frameworks.py +48 -0
  43. trainlens-0.1.0/src/trainlens/introspection/inspector.py +88 -0
  44. trainlens-0.1.0/src/trainlens/introspection/models.py +23 -0
  45. trainlens-0.1.0/src/trainlens/llm/__init__.py +14 -0
  46. trainlens-0.1.0/src/trainlens/llm/config.py +39 -0
  47. trainlens-0.1.0/src/trainlens/llm/context.py +77 -0
  48. trainlens-0.1.0/src/trainlens/llm/enhancer.py +30 -0
  49. trainlens-0.1.0/src/trainlens/llm/llm7.py +7 -0
  50. trainlens-0.1.0/src/trainlens/llm/openai_compatible.py +45 -0
  51. trainlens-0.1.0/src/trainlens/llm/prompts.py +116 -0
  52. trainlens-0.1.0/src/trainlens/llm/provider.py +10 -0
  53. trainlens-0.1.0/src/trainlens/magic/__init__.py +5 -0
  54. trainlens-0.1.0/src/trainlens/magic/commands.py +37 -0
  55. trainlens-0.1.0/src/trainlens/magic/extension.py +18 -0
  56. trainlens-0.1.0/src/trainlens/models/__init__.py +19 -0
  57. trainlens-0.1.0/src/trainlens/models/analysis.py +52 -0
  58. trainlens-0.1.0/src/trainlens/models/metric.py +54 -0
  59. trainlens-0.1.0/src/trainlens/models/run.py +21 -0
  60. trainlens-0.1.0/src/trainlens/models/snapshot.py +32 -0
  61. trainlens-0.1.0/src/trainlens/models/trace.py +16 -0
  62. trainlens-0.1.0/src/trainlens/notebook.py +42 -0
  63. trainlens-0.1.0/src/trainlens/pipeline.py +20 -0
  64. trainlens-0.1.0/src/trainlens/py.typed +1 -0
  65. trainlens-0.1.0/src/trainlens/renderers/__init__.py +5 -0
  66. trainlens-0.1.0/src/trainlens/renderers/markdown.py +122 -0
  67. trainlens-0.1.0/src/trainlens/renderers/rich.py +16 -0
  68. trainlens-0.1.0/src/trainlens/security.py +69 -0
  69. trainlens-0.1.0/src/trainlens/storage/__init__.py +5 -0
  70. trainlens-0.1.0/src/trainlens/storage/memory.py +52 -0
  71. trainlens-0.1.0/tests/conftest.py +8 -0
  72. trainlens-0.1.0/tests/test_foundation.py +80 -0
  73. trainlens-0.1.0/tests/test_heuristics.py +19 -0
  74. trainlens-0.1.0/tests/test_introspection.py +60 -0
  75. trainlens-0.1.0/tests/test_llm_config.py +45 -0
  76. trainlens-0.1.0/tests/test_llm_enhancer.py +47 -0
  77. trainlens-0.1.0/tests/test_magic.py +23 -0
  78. trainlens-0.1.0/tests/test_metrics.py +132 -0
  79. trainlens-0.1.0/tests/test_notebook.py +43 -0
  80. trainlens-0.1.0/tests/test_pipeline.py +40 -0
  81. trainlens-0.1.0/tests/test_prompts.py +45 -0
  82. trainlens-0.1.0/tests/test_renderer.py +32 -0
  83. trainlens-0.1.0/tests/test_security.py +28 -0
  84. trainlens-0.1.0/tests/test_storage.py +29 -0
  85. trainlens-0.1.0/tests/test_traces.py +59 -0
  86. trainlens-0.1.0/tools/trainlens_llm7.py +8 -0
  87. trainlens-0.1.0/tools/trainlens_openai_compatible.py +59 -0
@@ -0,0 +1,3 @@
1
+ TRAINLENS_LLM_BASE_URL=https://api.example.com/v1
2
+ TRAINLENS_LLM_API_KEY=your_api_key_here
3
+ TRAINLENS_LLM_MODEL=auto
@@ -0,0 +1,8 @@
1
+ * text=auto
2
+
3
+ *.md text eol=lf
4
+ *.py text eol=lf
5
+ *.toml text eol=lf
6
+ *.yml text eol=lf
7
+ *.yaml text eol=lf
8
+ *.json text eol=lf
@@ -0,0 +1,13 @@
1
+ ---
2
+ name: Bug report
3
+ about: Report something that is broken or confusing
4
+ labels: bug
5
+ ---
6
+
7
+ ## What happened?
8
+
9
+ ## Expected behavior
10
+
11
+ ## Reproduction
12
+
13
+ ## Environment
@@ -0,0 +1,11 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an analyzer, integration, or notebook UX improvement
4
+ labels: enhancement
5
+ ---
6
+
7
+ ## Problem
8
+
9
+ ## Proposed solution
10
+
11
+ ## Alternatives considered
@@ -0,0 +1,5 @@
1
+ ## Summary
2
+
3
+ ## Tests
4
+
5
+ ## Notes for reviewers
@@ -0,0 +1,24 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main, master]
6
+ pull_request:
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ python-version: ["3.11", "3.12"]
15
+ steps:
16
+ - uses: actions/checkout@v6
17
+ - uses: actions/setup-python@v6
18
+ with:
19
+ python-version: ${{ matrix.python-version }}
20
+ - run: python -m pip install --upgrade pip
21
+ - run: pip install -e ".[dev]"
22
+ - run: ruff check .
23
+ - run: mypy src/trainlens
24
+ - run: pytest --cov=trainlens --cov-report=term-missing
@@ -0,0 +1,15 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.py[cod]
4
+ .pytest_cache/
5
+ .ruff_cache/
6
+ .mypy_cache/
7
+ .coverage
8
+ htmlcov/
9
+ dist/
10
+ build/
11
+ *.egg-info/
12
+ .env
13
+ .ipynb_checkpoints/
14
+ .trainlens/
15
+ examples/generated/
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+
3
+ All notable changes to TrainLens will be documented here.
4
+
5
+ ## 0.1.0 - 2026-07-02
6
+
7
+ - initial notebook introspection engine
8
+ - training metric heuristics
9
+ - IPython magic commands
10
+ - optional OpenAI-compatible LLM explanation provider
11
+ - Markdown and Rich renderers
12
+ - in-memory run comparison
13
+ - notebook-only Markdown reporting with no GUI or image dashboard surface
14
+ - foundation-model fine-tuning profile detection for LLMs, CLIP, ViTs, projectors, and VLMs
15
+ - contrastive, adapter-rank, loss-plateau, and projector-alignment recommendations
16
+ - parameterized Jinja2 prompt templates for OpenAI-compatible ML/DL result explanations
17
+ - sensitive data redaction for prompt and notebook snapshot safety
@@ -0,0 +1,19 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use TrainLens in research, please cite it using this metadata."
3
+ type: software
4
+ title: "TrainLens"
5
+ version: "0.1.0"
6
+ date-released: "2026-07-02"
7
+ abstract: "TrainLens generates structured LLM-written reports for machine-learning training runs directly inside Jupyter notebooks."
8
+ authors:
9
+ - family-names: "Barrios"
10
+ given-names: "Eduardo J."
11
+ repository-code: "https://github.com/edujbarrios/trainlens"
12
+ url: "https://github.com/edujbarrios/trainlens"
13
+ license: "Apache-2.0"
14
+ keywords:
15
+ - "machine learning"
16
+ - "Jupyter"
17
+ - "training reports"
18
+ - "LLM"
19
+ - "research tooling"
@@ -0,0 +1,5 @@
1
+ # Code of Conduct
2
+
3
+ TrainLens follows the Contributor Covenant spirit: be respectful, collaborative, and generous with context.
4
+
5
+ Unacceptable behavior includes harassment, personal attacks, and publishing private information. Maintainers may remove comments, issues, or contributions that make the project less safe or welcoming.
@@ -0,0 +1,34 @@
1
+ # Contributing to TrainLens
2
+
3
+ Thanks for considering a contribution. TrainLens is designed to be contributor-friendly from day one.
4
+
5
+ ## Ways to help
6
+
7
+ - add analyzers for new training patterns
8
+ - improve notebook magic UX
9
+ - write example notebooks
10
+ - expand heuristic coverage
11
+ - document edge cases
12
+ - add provider adapters
13
+
14
+ ## Development
15
+
16
+ ```bash
17
+ python -m venv .venv
18
+ pip install -e ".[dev]"
19
+ pytest
20
+ ruff check .
21
+ mypy src/trainlens
22
+ ```
23
+
24
+ ## Design principles
25
+
26
+ - local heuristic behavior comes first
27
+ - LLMs may enhance language, but must not be required
28
+ - analyzers should explain their evidence
29
+ - notebook output should be concise and scannable
30
+ - integrations must avoid importing heavy ML frameworks unless the user already has them loaded
31
+
32
+ ## Pull requests
33
+
34
+ Keep pull requests focused. Include tests for new analyzers and mention any notebook UX changes in the PR description.
@@ -0,0 +1,158 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ https://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright
13
+ owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities
16
+ that control, are controlled by, or are under common control with that entity.
17
+ For the purposes of this definition, "control" means (i) the power, direct or
18
+ indirect, to cause the direction or management of such entity, whether by
19
+ contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
+ outstanding shares, or (iii) beneficial ownership of such entity.
21
+
22
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
23
+ permissions granted by this License.
24
+
25
+ "Source" form shall mean the preferred form for making modifications, including
26
+ but not limited to software source code, documentation source, and configuration
27
+ files.
28
+
29
+ "Object" form shall mean any form resulting from mechanical transformation or
30
+ translation of a Source form, including but not limited to compiled object code,
31
+ generated documentation, and conversions to other media types.
32
+
33
+ "Work" shall mean the work of authorship, whether in Source or Object form,
34
+ made available under the License, as indicated by a copyright notice that is
35
+ included in or attached to the work.
36
+
37
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
38
+ is based on (or derived from) the Work and for which the editorial revisions,
39
+ annotations, elaborations, or other modifications represent, as a whole, an
40
+ original work of authorship. For the purposes of this License, Derivative Works
41
+ shall not include works that remain separable from, or merely link (or bind by
42
+ name) to the interfaces of, the Work and Derivative Works thereof.
43
+
44
+ "Contribution" shall mean any work of authorship, including the original version
45
+ of the Work and any modifications or additions to that Work or Derivative Works
46
+ thereof, that is intentionally submitted to Licensor for inclusion in the Work
47
+ by the copyright owner or by an individual or Legal Entity authorized to submit
48
+ on behalf of the copyright owner. For the purposes of this definition,
49
+ "submitted" means any form of electronic, verbal, or written communication sent
50
+ to the Licensor or its representatives, including but not limited to
51
+ communication on electronic mailing lists, source code control systems, and
52
+ issue tracking systems that are managed by, or on behalf of, the Licensor for
53
+ the purpose of discussing and improving the Work, but excluding communication
54
+ that is conspicuously marked or otherwise designated in writing by the copyright
55
+ owner as "Not a Contribution."
56
+
57
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
58
+ of whom a Contribution has been received by Licensor and subsequently
59
+ incorporated within the Work.
60
+
61
+ 2. Grant of Copyright License. Subject to the terms and conditions of this
62
+ License, each Contributor hereby grants to You a perpetual, worldwide,
63
+ non-exclusive, no-charge, royalty-free, irrevocable copyright license to
64
+ reproduce, prepare Derivative Works of, publicly display, publicly perform,
65
+ sublicense, and distribute the Work and such Derivative Works in Source or
66
+ Object form.
67
+
68
+ 3. Grant of Patent License. Subject to the terms and conditions of this License,
69
+ each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
70
+ no-charge, royalty-free, irrevocable patent license to make, have made, use,
71
+ offer to sell, sell, import, and otherwise transfer the Work, where such license
72
+ applies only to those patent claims licensable by such Contributor that are
73
+ necessarily infringed by their Contribution(s) alone or by combination of their
74
+ Contribution(s) with the Work to which such Contribution(s) was submitted. If
75
+ You institute patent litigation against any entity (including a cross-claim or
76
+ counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated
77
+ within the Work constitutes direct or contributory patent infringement, then any
78
+ patent licenses granted to You under this License for that Work shall terminate
79
+ as of the date such litigation is filed.
80
+
81
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
82
+ Derivative Works thereof in any medium, with or without modifications, and in
83
+ Source or Object form, provided that You meet the following conditions:
84
+
85
+ (a) You must give any other recipients of the Work or Derivative Works a copy of
86
+ this License; and
87
+
88
+ (b) You must cause any modified files to carry prominent notices stating that
89
+ You changed the files; and
90
+
91
+ (c) You must retain, in the Source form of any Derivative Works that You
92
+ distribute, all copyright, patent, trademark, and attribution notices from the
93
+ Source form of the Work, excluding those notices that do not pertain to any part
94
+ of the Derivative Works; and
95
+
96
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then
97
+ any Derivative Works that You distribute must include a readable copy of the
98
+ attribution notices contained within such NOTICE file, excluding those notices
99
+ that do not pertain to any part of the Derivative Works, in at least one of the
100
+ following places: within a NOTICE text file distributed as part of the
101
+ Derivative Works; within the Source form or documentation, if provided along
102
+ with the Derivative Works; or, within a display generated by the Derivative
103
+ Works, if and wherever such third-party notices normally appear. The contents of
104
+ the NOTICE file are for informational purposes only and do not modify the
105
+ License. You may add Your own attribution notices within Derivative Works that
106
+ You distribute, alongside or as an addendum to the NOTICE text from the Work,
107
+ provided that such additional attribution notices cannot be construed as
108
+ modifying the License.
109
+
110
+ You may add Your own copyright statement to Your modifications and may provide
111
+ additional or different license terms and conditions for use, reproduction, or
112
+ distribution of Your modifications, or for any such Derivative Works as a whole,
113
+ provided Your use, reproduction, and distribution of the Work otherwise complies
114
+ with the conditions stated in this License.
115
+
116
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any
117
+ Contribution intentionally submitted for inclusion in the Work by You to the
118
+ Licensor shall be under the terms and conditions of this License, without any
119
+ additional terms or conditions. Notwithstanding the above, nothing herein shall
120
+ supersede or modify the terms of any separate license agreement you may have
121
+ executed with Licensor regarding such Contributions.
122
+
123
+ 6. Trademarks. This License does not grant permission to use the trade names,
124
+ trademarks, service marks, or product names of the Licensor, except as required
125
+ for reasonable and customary use in describing the origin of the Work and
126
+ reproducing the content of the NOTICE file.
127
+
128
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
129
+ writing, Licensor provides the Work (and each Contributor provides its
130
+ Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
131
+ KIND, either express or implied, including, without limitation, any warranties or
132
+ conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
133
+ PARTICULAR PURPOSE. You are solely responsible for determining the
134
+ appropriateness of using or redistributing the Work and assume any risks
135
+ associated with Your exercise of permissions under this License.
136
+
137
+ 8. Limitation of Liability. In no event and under no legal theory, whether in
138
+ tort (including negligence), contract, or otherwise, unless required by
139
+ applicable law (such as deliberate and grossly negligent acts) or agreed to in
140
+ writing, shall any Contributor be liable to You for damages, including any
141
+ direct, indirect, special, incidental, or consequential damages of any character
142
+ arising as a result of this License or out of the use or inability to use the
143
+ Work (including but not limited to damages for loss of goodwill, work stoppage,
144
+ computer failure or malfunction, or any and all other commercial damages or
145
+ losses), even if such Contributor has been advised of the possibility of such
146
+ damages.
147
+
148
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or
149
+ Derivative Works thereof, You may choose to offer, and charge a fee for,
150
+ acceptance of support, warranty, indemnity, or other liability obligations
151
+ and/or rights consistent with this License. However, in accepting such
152
+ obligations, You may act only on Your own behalf and on Your sole
153
+ responsibility, not on behalf of any other Contributor, and only if You agree to
154
+ indemnify, defend, and hold each Contributor harmless for any liability incurred
155
+ by, or claims asserted against, such Contributor by reason of your accepting any
156
+ such warranty or additional liability.
157
+
158
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,174 @@
1
+ Metadata-Version: 2.4
2
+ Name: trainlens
3
+ Version: 0.1.0
4
+ Summary: Open-source Jupyter AI training explainer.
5
+ Project-URL: Homepage, https://github.com/edujbarrios/trainlens
6
+ Project-URL: Repository, https://github.com/edujbarrios/trainlens
7
+ Project-URL: Issues, https://github.com/edujbarrios/trainlens/issues
8
+ Project-URL: Changelog, https://github.com/edujbarrios/trainlens/blob/main/CHANGELOG.md
9
+ Project-URL: Security, https://github.com/edujbarrios/trainlens/security
10
+ Author: Eduardo J. Barrios
11
+ License: Apache-2.0
12
+ License-File: LICENSE
13
+ Keywords: explainability,jupyter,machine-learning,notebooks,training
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Framework :: Jupyter
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Intended Audience :: Science/Research
18
+ Classifier: License :: OSI Approved :: Apache Software License
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.11
25
+ Requires-Dist: ipython>=8.12
26
+ Requires-Dist: jinja2>=3.1
27
+ Requires-Dist: rich>=13.7
28
+ Provides-Extra: dev
29
+ Requires-Dist: mypy>=1.10; extra == 'dev'
30
+ Requires-Dist: pytest-cov>=5.0; extra == 'dev'
31
+ Requires-Dist: pytest>=8.0; extra == 'dev'
32
+ Requires-Dist: ruff>=0.5; extra == 'dev'
33
+ Provides-Extra: llm
34
+ Description-Content-Type: text/markdown
35
+
36
+ # TrainLens
37
+
38
+ TrainLens generates LLM-written training reports inside the Jupyter notebook you
39
+ are already using. It reads context from memory: model, dataset, metrics, logs,
40
+ traces, hyperparameters, and notes.
41
+
42
+ [![CI](https://github.com/edujbarrios/trainlens/actions/workflows/ci.yml/badge.svg)](https://github.com/edujbarrios/trainlens/actions/workflows/ci.yml)
43
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache--2.0-yellow.svg)](LICENSE)
44
+ [![Python](https://img.shields.io/badge/python-3.11%2B-blue)](pyproject.toml)
45
+ [![PyPI](https://img.shields.io/pypi/v/trainlens.svg)](https://pypi.org/project/trainlens/)
46
+
47
+ <p align="center"><strong><em>Maintained by Eduardo J. Barrios.</em></strong></p>
48
+
49
+ It is built for research workflows with many training jobs, where you need
50
+ consistent explanations of results, datasets, and hyperparameters.
51
+
52
+ ## How It Works
53
+
54
+ TrainLens is a small notebook pipeline. Conceptually, `%explain_training` does
55
+ this:
56
+
57
+ ```python
58
+ %explain_training
59
+
60
+ # trainlens.magic.commands
61
+ # Reads the active IPython namespace from the current notebook.
62
+ namespace = get_ipython().user_ns
63
+
64
+ # trainlens.llm.context + trainlens.introspection
65
+ # Finds visible training context: model names, histories, metric logs, dataset
66
+ # notes, hyperparameters, traces, and PEFT metadata.
67
+ context = build_llm_notebook_context(namespace)
68
+
69
+ # trainlens.security
70
+ # Redacts likely secrets while values are summarized and before prompt rendering.
71
+ safe_evidence = context.markdown
72
+
73
+ # trainlens.llm.prompts
74
+ # Wraps the evidence in TrainLens' internal report-generation prompt. The prompt
75
+ # tells the LLM to explain only what the notebook supports.
76
+ prompt = render_ml_results_explanation_prompt(safe_evidence)
77
+
78
+ # trainlens.llm.openai_compatible
79
+ # Sends the evidence to the configured chat-completions endpoint; the provider
80
+ # renders the prompt and returns Markdown for display in the notebook.
81
+ report = OpenAICompatibleProvider(config).explain(safe_evidence)
82
+ display(Markdown(report))
83
+ ```
84
+
85
+ The generated report keeps a stable shape: summary, evidence, interpretation,
86
+ risks, next steps, and bottom line.
87
+
88
+ ## Install
89
+
90
+ ```bash
91
+ python -m pip install trainlens
92
+ ```
93
+
94
+ Development install:
95
+
96
+ ```bash
97
+ git clone https://github.com/edujbarrios/trainlens.git
98
+ cd trainlens
99
+ python -m pip install -e ".[dev]"
100
+ ```
101
+
102
+ ## Quickstart
103
+
104
+ ```python
105
+ import os
106
+
107
+ import trainlens
108
+
109
+ os.environ["TRAINLENS_LLM_BASE_URL"] = "https://api.openai.com/v1"
110
+ os.environ["TRAINLENS_LLM_API_KEY"] = "your-api-key"
111
+ os.environ["TRAINLENS_LLM_MODEL"] = "gpt-4.1-mini"
112
+ os.environ["TRAINLENS_LLM_TIMEOUT_SECONDS"] = "120"
113
+
114
+ dataset_name = "ag_news"
115
+ dataset_notes = "120k news titles; 4 classes; validation is balanced."
116
+ model_name = "distilbert-base-uncased"
117
+ training_params = {
118
+ "epochs": 3,
119
+ "batch_size": 32,
120
+ "learning_rate": 5e-5,
121
+ "max_length": 128,
122
+ }
123
+ history = {
124
+ "train_loss": [0.62, 0.31, 0.18],
125
+ "eval_loss": [0.48, 0.44, 0.57],
126
+ "accuracy": [0.78, 0.91, 0.96],
127
+ "val_accuracy": [0.84, 0.86, 0.85],
128
+ }
129
+
130
+ %load_ext trainlens.magic.extension
131
+ %explain_training
132
+ ```
133
+
134
+ ## Example Output
135
+
136
+ For the Quickstart run above, TrainLens returns a structured report like this:
137
+
138
+ ```markdown
139
+ ## TrainLens Report
140
+
141
+ ### Run summary
142
+ - Dataset context: `ag_news`
143
+ - Model context: `distilbert-base-uncased`
144
+ - Training params: `epochs=3`, `batch_size=32`, `learning_rate=5e-05`
145
+
146
+ ### Evidence
147
+ - Training loss decreases: `0.62 -> 0.31 -> 0.18`
148
+ - Training accuracy increases: `0.78 -> 0.91 -> 0.96`
149
+ - Validation loss improves, then worsens: `0.48 -> 0.44 -> 0.57`
150
+ - Validation accuracy improves slightly, then slips: `0.84 -> 0.86 -> 0.85`
151
+
152
+ ### Interpretation
153
+ - Optimization is working on the training set.
154
+ - Generalization peaks around epoch 2.
155
+ - Epoch 3 shows validation drift consistent with overfitting.
156
+
157
+ ### Risks and caveats
158
+ - **Overfitting risk is supported by the metrics.**
159
+ - **Calibration/confidence drift is possible** because validation loss rises
160
+ while validation accuracy changes only slightly.
161
+
162
+ ### What to do next in the notebook
163
+ - Select epoch 2 as the current best checkpoint.
164
+ - Add early stopping on validation loss.
165
+ - Test 2 epochs and a slightly lower learning rate.
166
+
167
+ ### Bottom line
168
+ - The run trained successfully, but the best generalization was reached at
169
+ **epoch 2**, not epoch 3.
170
+ ```
171
+
172
+ ## License
173
+
174
+ Apache License 2.0. See [LICENSE](LICENSE).
@@ -0,0 +1,139 @@
1
+ # TrainLens
2
+
3
+ TrainLens generates LLM-written training reports inside the Jupyter notebook you
4
+ are already using. It reads context from memory: model, dataset, metrics, logs,
5
+ traces, hyperparameters, and notes.
6
+
7
+ [![CI](https://github.com/edujbarrios/trainlens/actions/workflows/ci.yml/badge.svg)](https://github.com/edujbarrios/trainlens/actions/workflows/ci.yml)
8
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache--2.0-yellow.svg)](LICENSE)
9
+ [![Python](https://img.shields.io/badge/python-3.11%2B-blue)](pyproject.toml)
10
+ [![PyPI](https://img.shields.io/pypi/v/trainlens.svg)](https://pypi.org/project/trainlens/)
11
+
12
+ <p align="center"><strong><em>Maintained by Eduardo J. Barrios.</em></strong></p>
13
+
14
+ It is built for research workflows with many training jobs, where you need
15
+ consistent explanations of results, datasets, and hyperparameters.
16
+
17
+ ## How It Works
18
+
19
+ TrainLens is a small notebook pipeline. Conceptually, `%explain_training` does
20
+ this:
21
+
22
+ ```python
23
+ %explain_training
24
+
25
+ # trainlens.magic.commands
26
+ # Reads the active IPython namespace from the current notebook.
27
+ namespace = get_ipython().user_ns
28
+
29
+ # trainlens.llm.context + trainlens.introspection
30
+ # Finds visible training context: model names, histories, metric logs, dataset
31
+ # notes, hyperparameters, traces, and PEFT metadata.
32
+ context = build_llm_notebook_context(namespace)
33
+
34
+ # trainlens.security
35
+ # Redacts likely secrets while values are summarized and before prompt rendering.
36
+ safe_evidence = context.markdown
37
+
38
+ # trainlens.llm.prompts
39
+ # Wraps the evidence in TrainLens' internal report-generation prompt. The prompt
40
+ # tells the LLM to explain only what the notebook supports.
41
+ prompt = render_ml_results_explanation_prompt(safe_evidence)
42
+
43
+ # trainlens.llm.openai_compatible
44
+ # Sends the evidence to the configured chat-completions endpoint; the provider
45
+ # renders the prompt and returns Markdown for display in the notebook.
46
+ report = OpenAICompatibleProvider(config).explain(safe_evidence)
47
+ display(Markdown(report))
48
+ ```
49
+
50
+ The generated report keeps a stable shape: summary, evidence, interpretation,
51
+ risks, next steps, and bottom line.
52
+
53
+ ## Install
54
+
55
+ ```bash
56
+ python -m pip install trainlens
57
+ ```
58
+
59
+ Development install:
60
+
61
+ ```bash
62
+ git clone https://github.com/edujbarrios/trainlens.git
63
+ cd trainlens
64
+ python -m pip install -e ".[dev]"
65
+ ```
66
+
67
+ ## Quickstart
68
+
69
+ ```python
70
+ import os
71
+
72
+ import trainlens
73
+
74
+ os.environ["TRAINLENS_LLM_BASE_URL"] = "https://api.openai.com/v1"
75
+ os.environ["TRAINLENS_LLM_API_KEY"] = "your-api-key"
76
+ os.environ["TRAINLENS_LLM_MODEL"] = "gpt-4.1-mini"
77
+ os.environ["TRAINLENS_LLM_TIMEOUT_SECONDS"] = "120"
78
+
79
+ dataset_name = "ag_news"
80
+ dataset_notes = "120k news titles; 4 classes; validation is balanced."
81
+ model_name = "distilbert-base-uncased"
82
+ training_params = {
83
+ "epochs": 3,
84
+ "batch_size": 32,
85
+ "learning_rate": 5e-5,
86
+ "max_length": 128,
87
+ }
88
+ history = {
89
+ "train_loss": [0.62, 0.31, 0.18],
90
+ "eval_loss": [0.48, 0.44, 0.57],
91
+ "accuracy": [0.78, 0.91, 0.96],
92
+ "val_accuracy": [0.84, 0.86, 0.85],
93
+ }
94
+
95
+ %load_ext trainlens.magic.extension
96
+ %explain_training
97
+ ```
98
+
99
+ ## Example Output
100
+
101
+ For the Quickstart run above, TrainLens returns a structured report like this:
102
+
103
+ ```markdown
104
+ ## TrainLens Report
105
+
106
+ ### Run summary
107
+ - Dataset context: `ag_news`
108
+ - Model context: `distilbert-base-uncased`
109
+ - Training params: `epochs=3`, `batch_size=32`, `learning_rate=5e-05`
110
+
111
+ ### Evidence
112
+ - Training loss decreases: `0.62 -> 0.31 -> 0.18`
113
+ - Training accuracy increases: `0.78 -> 0.91 -> 0.96`
114
+ - Validation loss improves, then worsens: `0.48 -> 0.44 -> 0.57`
115
+ - Validation accuracy improves slightly, then slips: `0.84 -> 0.86 -> 0.85`
116
+
117
+ ### Interpretation
118
+ - Optimization is working on the training set.
119
+ - Generalization peaks around epoch 2.
120
+ - Epoch 3 shows validation drift consistent with overfitting.
121
+
122
+ ### Risks and caveats
123
+ - **Overfitting risk is supported by the metrics.**
124
+ - **Calibration/confidence drift is possible** because validation loss rises
125
+ while validation accuracy changes only slightly.
126
+
127
+ ### What to do next in the notebook
128
+ - Select epoch 2 as the current best checkpoint.
129
+ - Add early stopping on validation loss.
130
+ - Test 2 epochs and a slightly lower learning rate.
131
+
132
+ ### Bottom line
133
+ - The run trained successfully, but the best generalization was reached at
134
+ **epoch 2**, not epoch 3.
135
+ ```
136
+
137
+ ## License
138
+
139
+ Apache License 2.0. See [LICENSE](LICENSE).
@@ -0,0 +1,9 @@
1
+ # Security Policy
2
+
3
+ Please report suspected vulnerabilities privately by opening a GitHub security advisory or emailing the maintainer.
4
+
5
+ TrainLens is notebook software and may inspect objects in the active Python namespace. It does not send data to external services unless optional LLM explanation is explicitly requested and configured by the user.
6
+
7
+ ## Supported versions
8
+
9
+ TrainLens is pre-1.0. Security fixes will target the main branch until the first stable release.