lispyn 0.17.0a1__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.
- lispyn-0.17.0a1/LICENSE +202 -0
- lispyn-0.17.0a1/MANIFEST.in +6 -0
- lispyn-0.17.0a1/NOTICE +6 -0
- lispyn-0.17.0a1/PKG-INFO +305 -0
- lispyn-0.17.0a1/README.md +253 -0
- lispyn-0.17.0a1/pyproject.toml +53 -0
- lispyn-0.17.0a1/setup.cfg +4 -0
- lispyn-0.17.0a1/src/lispyn/__init__.py +7 -0
- lispyn-0.17.0a1/src/lispyn/classification.py +170 -0
- lispyn-0.17.0a1/src/lispyn/cli.py +126 -0
- lispyn-0.17.0a1/src/lispyn/compiler.py +68 -0
- lispyn-0.17.0a1/src/lispyn/data.py +185 -0
- lispyn-0.17.0a1/src/lispyn/dependencies.py +139 -0
- lispyn-0.17.0a1/src/lispyn/doctor.py +67 -0
- lispyn-0.17.0a1/src/lispyn/gallery.py +47 -0
- lispyn-0.17.0a1/src/lispyn/macros.hy +107 -0
- lispyn-0.17.0a1/src/lispyn/media.py +169 -0
- lispyn-0.17.0a1/src/lispyn/notebooks.py +232 -0
- lispyn-0.17.0a1/src/lispyn/peft_utils.py +90 -0
- lispyn-0.17.0a1/src/lispyn/plots.py +292 -0
- lispyn-0.17.0a1/src/lispyn/reproducibility.py +90 -0
- lispyn-0.17.0a1/src/lispyn/scaffold.py +58 -0
- lispyn-0.17.0a1/src/lispyn/training.py +277 -0
- lispyn-0.17.0a1/src/lispyn/workflow.py +218 -0
- lispyn-0.17.0a1/src/lispyn.egg-info/PKG-INFO +305 -0
- lispyn-0.17.0a1/src/lispyn.egg-info/SOURCES.txt +51 -0
- lispyn-0.17.0a1/src/lispyn.egg-info/dependency_links.txt +1 -0
- lispyn-0.17.0a1/src/lispyn.egg-info/entry_points.txt +2 -0
- lispyn-0.17.0a1/src/lispyn.egg-info/requires.txt +35 -0
- lispyn-0.17.0a1/src/lispyn.egg-info/top_level.txt +1 -0
- lispyn-0.17.0a1/tests/test_classification.py +136 -0
- lispyn-0.17.0a1/tests/test_compiler_env.py +48 -0
- lispyn-0.17.0a1/tests/test_core.py +84 -0
- lispyn-0.17.0a1/tests/test_curve_designs.py +123 -0
- lispyn-0.17.0a1/tests/test_dark_plotting.py +139 -0
- lispyn-0.17.0a1/tests/test_data_pipeline.py +66 -0
- lispyn-0.17.0a1/tests/test_dependencies.py +132 -0
- lispyn-0.17.0a1/tests/test_dependency_notebook.py +42 -0
- lispyn-0.17.0a1/tests/test_doctor.py +55 -0
- lispyn-0.17.0a1/tests/test_early_stopping.py +154 -0
- lispyn-0.17.0a1/tests/test_macros.py +50 -0
- lispyn-0.17.0a1/tests/test_markdown_macros.py +107 -0
- lispyn-0.17.0a1/tests/test_media_training.py +125 -0
- lispyn-0.17.0a1/tests/test_notebook_sections.py +42 -0
- lispyn-0.17.0a1/tests/test_peft_audio.py +99 -0
- lispyn-0.17.0a1/tests/test_pip_cells.py +114 -0
- lispyn-0.17.0a1/tests/test_plots.py +74 -0
- lispyn-0.17.0a1/tests/test_reproducibility.py +97 -0
- lispyn-0.17.0a1/tests/test_scaffold.py +32 -0
- lispyn-0.17.0a1/tests/test_split_dataset.py +93 -0
- lispyn-0.17.0a1/tests/test_tracking.py +126 -0
- lispyn-0.17.0a1/tests/test_training_macros.py +34 -0
- lispyn-0.17.0a1/tests/test_workflow.py +140 -0
lispyn-0.17.0a1/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
lispyn-0.17.0a1/NOTICE
ADDED
lispyn-0.17.0a1/PKG-INFO
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lispyn
|
|
3
|
+
Version: 0.17.0a1
|
|
4
|
+
Summary: Lisp-powered PyTorch experiments and Jupyter notebooks, built on Hy.
|
|
5
|
+
Author: Eduardo J. Barrios
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/edujbarrios/lispyn
|
|
8
|
+
Project-URL: Repository, https://github.com/edujbarrios/lispyn
|
|
9
|
+
Project-URL: Issues, https://github.com/edujbarrios/lispyn/issues
|
|
10
|
+
Project-URL: Documentation, https://github.com/edujbarrios/lispyn/blob/main/docs/guide.md
|
|
11
|
+
Keywords: lisp,hy,jupyter,pytorch,notebooks,machine-learning
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
License-File: NOTICE
|
|
24
|
+
Requires-Dist: hy<2.0,>=1.0
|
|
25
|
+
Requires-Dist: nbformat<6,>=5.8
|
|
26
|
+
Requires-Dist: packaging>=23
|
|
27
|
+
Provides-Extra: notebook
|
|
28
|
+
Requires-Dist: nbclient<1,>=0.9; extra == "notebook"
|
|
29
|
+
Requires-Dist: ipykernel>=6; extra == "notebook"
|
|
30
|
+
Provides-Extra: data
|
|
31
|
+
Requires-Dist: pandas>=2; extra == "data"
|
|
32
|
+
Provides-Extra: vision
|
|
33
|
+
Requires-Dist: torch; extra == "vision"
|
|
34
|
+
Requires-Dist: torchvision; extra == "vision"
|
|
35
|
+
Requires-Dist: pillow; extra == "vision"
|
|
36
|
+
Provides-Extra: audio
|
|
37
|
+
Requires-Dist: torch; extra == "audio"
|
|
38
|
+
Requires-Dist: torchaudio; extra == "audio"
|
|
39
|
+
Requires-Dist: torchcodec; extra == "audio"
|
|
40
|
+
Provides-Extra: text
|
|
41
|
+
Requires-Dist: torch; extra == "text"
|
|
42
|
+
Provides-Extra: peft
|
|
43
|
+
Requires-Dist: peft>=0.15; extra == "peft"
|
|
44
|
+
Requires-Dist: transformers<5,>=4.45; extra == "peft"
|
|
45
|
+
Provides-Extra: plots
|
|
46
|
+
Requires-Dist: matplotlib>=3.8; extra == "plots"
|
|
47
|
+
Provides-Extra: dev
|
|
48
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
49
|
+
Requires-Dist: nbclient<1,>=0.9; extra == "dev"
|
|
50
|
+
Requires-Dist: ipykernel>=6; extra == "dev"
|
|
51
|
+
Dynamic: license-file
|
|
52
|
+
|
|
53
|
+
# Lispyn
|
|
54
|
+
|
|
55
|
+
[](https://pypi.org/project/lispyn/) [](https://pypi.org/project/lispyn/) [](https://pypi.org/project/lispyn/) [](https://github.com/edujbarrios/lispyn/actions/workflows/tests.yml) [](https://github.com/edujbarrios/lispyn/blob/main/LICENSE)
|
|
56
|
+
|
|
57
|
+
**Write complex experiments. Make them easy to understand, reuse, and share.**
|
|
58
|
+
|
|
59
|
+
Great experiments deserve to be understood—not just executed. Whether you're exploring new AI models, fine-tuning neural networks, or running advanced training pipelines, you often need to **show others what you built, how it works, and what you learned**.
|
|
60
|
+
|
|
61
|
+
**Lispyn** uses Lisp-based [Hy](https://hylang.org/) macros to turn repetitive steps into **concise, reusable building blocks**. Prepare datasets, train with PyTorch, document your choices in Markdown, and generate plots—all from a readable Lisp source that becomes a standard **Python Jupyter notebook**.
|
|
62
|
+
|
|
63
|
+
Spend less time rewriting boilerplate and more time experimenting. When your dataset, model, or training strategy changes, adapt the macro and reuse the workflow. **Lisp for expressive experiments. Python for the ecosystem. Jupyter for sharing results.**
|
|
64
|
+
|
|
65
|
+
## Quick installation
|
|
66
|
+
|
|
67
|
+
Install Lispyn directly from [PyPI](https://pypi.org/project/lispyn/):
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
python -m pip install lispyn
|
|
71
|
+
|
|
72
|
+
# Recommended for notebooks and Matplotlib plots
|
|
73
|
+
python -m pip install "lispyn[notebook,plots]"
|
|
74
|
+
|
|
75
|
+
# Check your current Python and available dependencies
|
|
76
|
+
lispyn doctor
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Lispyn needs **Python 3.10+**. Basic installation includes Hy, so you can
|
|
80
|
+
import and use standard Python modules immediately. PyTorch, TorchVision,
|
|
81
|
+
and GPU-specific libraries are optional; install compatible versions for
|
|
82
|
+
your hardware before running AI training examples.
|
|
83
|
+
|
|
84
|
+
## Your first Lispyn notebook
|
|
85
|
+
|
|
86
|
+
Create a file named `hello.hy`:
|
|
87
|
+
|
|
88
|
+
```hy
|
|
89
|
+
(require lispyn.macros [md])
|
|
90
|
+
(md "# My first Lispyn experiment"
|
|
91
|
+
"Synthetic training curves, generated with reusable Lisp macros.")
|
|
92
|
+
|
|
93
|
+
(require lispyn.macros [defcurve])
|
|
94
|
+
(setv history {"train_loss" [1.4 1.0 0.7 0.5]
|
|
95
|
+
"val_loss" [1.5 1.2 0.9 0.75]})
|
|
96
|
+
(defcurve my-style :theme "docusaurus-dark"
|
|
97
|
+
:palette "turquoise-spectrum")
|
|
98
|
+
(my-style history :metric "loss"
|
|
99
|
+
:title "Training curves" :save "training.png")
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Then run:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
# Translate Lispyn/Hy into ordinary Python Jupyter cells
|
|
106
|
+
lispyn build hello.hy
|
|
107
|
+
|
|
108
|
+
# Execute the notebook, keeping its real outputs
|
|
109
|
+
lispyn execute hello.hy
|
|
110
|
+
|
|
111
|
+
# Or run a Hy file directly (without creating a notebook)
|
|
112
|
+
lispyn run hello.hy
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
`hello.ipynb` is a standard Jupyter notebook with real Markdown and Python
|
|
116
|
+
cells. The synthetic graph is written to `training.png`. All plots are
|
|
117
|
+
generated with Matplotlib; no new language interpreter or special kernel
|
|
118
|
+
is needed. After a Markdown cell, repeat `(require lispyn.macros [...])`
|
|
119
|
+
for any macros used in a later cell because Hy code cells compile independently.
|
|
120
|
+
|
|
121
|
+
**Developing Lispyn itself?** Clone the repository and use
|
|
122
|
+
`python -m pip install -e ".[dev,notebook,plots]"` instead.
|
|
123
|
+
See the [technical guide](https://github.com/edujbarrios/lispyn/blob/main/docs/guide.md)
|
|
124
|
+
and [release instructions](https://github.com/edujbarrios/lispyn/blob/main/docs/releasing.md).
|
|
125
|
+
## Matplotlib with reusable Lisp macros
|
|
126
|
+
|
|
127
|
+
Define a design once and apply it to any recorded history. This short example
|
|
128
|
+
uses a dark gray background inspired by Docusaurus and the seven-color
|
|
129
|
+
**turquoise-spectrum** palette:
|
|
130
|
+
|
|
131
|
+
```hy
|
|
132
|
+
(require lispyn.macros [defcurve compare-curves])
|
|
133
|
+
(setv history {"train_loss" [1.5 1.1 0.8 0.55]
|
|
134
|
+
"val_loss" [1.6 1.2 0.95 0.76]})
|
|
135
|
+
(defcurve turquoise-dark
|
|
136
|
+
:theme "docusaurus-dark"
|
|
137
|
+
:palette "turquoise-spectrum"
|
|
138
|
+
:train-color "#40E0D0" :val-color "#8CF0EB"
|
|
139
|
+
:title-size 18 :line-width 2.8 :fill-alpha 0.08)
|
|
140
|
+
(turquoise-dark history
|
|
141
|
+
:metric "loss" :title "Training dynamics"
|
|
142
|
+
:subtitle "Synthetic example · 4 epochs"
|
|
143
|
+
:save "training.png")
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
**Generated from Lispyn + Matplotlib using synthetic values, not a trained model.**
|
|
147
|
+
|
|
148
|
+

|
|
149
|
+
|
|
150
|
+
The same Lisp file can compare several named runs, automatically assigning
|
|
151
|
+
distinct colors from the palette:
|
|
152
|
+
|
|
153
|
+

|
|
154
|
+
|
|
155
|
+
Full reproducible source: [synthetic_curves.hy](https://github.com/edujbarrios/lispyn/blob/main/examples/synthetic_curves.hy)
|
|
156
|
+
· [generated Jupyter notebook](https://github.com/edujbarrios/lispyn/blob/main/example_generated_notebooks/synthetic_curves.ipynb).
|
|
157
|
+
Regenerate the figures with `lispyn run examples/synthetic_curves.hy`.
|
|
158
|
+
|
|
159
|
+
Classification reports are equally concise: the new `defconfusion` macro
|
|
160
|
+
creates a reusable dark-themed confusion matrix from actual and predicted labels.
|
|
161
|
+
See the [Lisp example](https://github.com/edujbarrios/lispyn/blob/main/examples/confusion_matrix.hy)
|
|
162
|
+
and its [generated figure](https://github.com/edujbarrios/lispyn/blob/main/docs/images/synthetic_confusion_matrix.png).
|
|
163
|
+
The example uses **synthetic class labels**, not real model predictions.
|
|
164
|
+
|
|
165
|
+
## Train smarter with one Lisp macro
|
|
166
|
+
|
|
167
|
+
Long PyTorch experiments can stop when a selected validation metric stops
|
|
168
|
+
improving. The new `train-until` macro handles this policy while keeping
|
|
169
|
+
checkpoints, histories, and the exact number of completed epochs:
|
|
170
|
+
|
|
171
|
+
```hy
|
|
172
|
+
(require lispyn.macros [train-until])
|
|
173
|
+
(setv run
|
|
174
|
+
(train-until model training-data 8
|
|
175
|
+
:validation validation-data
|
|
176
|
+
:loss-fn loss-function
|
|
177
|
+
:epochs 300
|
|
178
|
+
:min-delta 0.0005
|
|
179
|
+
:experiment-dir "runs/experiment"))
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
`300` is the maximum: if the monitored loss does not improve by more
|
|
183
|
+
than `min-delta` for eight consecutive epochs, training stops early.
|
|
184
|
+
With an experiment directory, the run records `best.pt`, `last.pt`,
|
|
185
|
+
`history.json`, and a summary of the completed epochs in `manifest.json`.
|
|
186
|
+
The model returned by the run remains at the **last** epoch; the best
|
|
187
|
+
weights can be restored explicitly with `load_checkpoint`.
|
|
188
|
+
|
|
189
|
+
Try the [offline early-stopping notebook](https://github.com/edujbarrios/lispyn/blob/main/example_generated_notebooks/early_stopping.ipynb)
|
|
190
|
+
or its [Lisp source](https://github.com/edujbarrios/lispyn/blob/main/examples/early_stopping.hy).
|
|
191
|
+
|
|
192
|
+
## Full experiment — ResNet18, two-stage fine-tuning
|
|
193
|
+
|
|
194
|
+
The following is the complete source of [`examples/resnet_finetune_300.hy`](https://github.com/edujbarrios/lispyn/blob/main/examples/resnet_finetune_300.hy), including its Markdown cells. Put your images in `examples/data/resnet_images/<class_name>/*.jpg` (or `.png`); each class needs multiple images. The first stage trains the classifier for **10 epochs**, then the second unfreezes all layers for **300 epochs**.
|
|
195
|
+
|
|
196
|
+
```clojure
|
|
197
|
+
; ResNet18 experiment: all results are Python/Jupyter notebook cells.
|
|
198
|
+
; Required actual images: examples/data/resnet_images/class_name/*.jpg or *.png
|
|
199
|
+
; This source is NOT executed in CI (300 epochs need a real dataset/GPU).
|
|
200
|
+
(require lispyn.macros [md])
|
|
201
|
+
|
|
202
|
+
(md "# ResNet18 — transfer learning + full fine-tuning"
|
|
203
|
+
"An end-to-end **PyTorch** experiment written in Lispyn. It loads labeled images, splits by class, runs head-only tuning, then unfreezes the backbone for **300 epochs**, and produces publication-ready curves."
|
|
204
|
+
"**Author:** Eduardo J. Barrios · **Source:** Lispyn.")
|
|
205
|
+
|
|
206
|
+
(md "## Install required libraries"
|
|
207
|
+
"The **pip-install** macro generates a dedicated Python notebook setup cell. Already available packages report *Requirement already installed in this environment*; only missing packages are installed in the current kernel."
|
|
208
|
+
"Python standard-library modules such as `math` need no installation. For CUDA/accelerator setups, install matching PyTorch/TorchVision builds beforehand. Installing native packages may require a kernel restart.")
|
|
209
|
+
|
|
210
|
+
(require lispyn.macros [pip-install])
|
|
211
|
+
(pip-install "torch" "torchvision" "matplotlib>=3.8")
|
|
212
|
+
|
|
213
|
+
(require lispyn.macros [use-package])
|
|
214
|
+
(setv math (use-package "math" :install False))
|
|
215
|
+
(print "math.sqrt(16):" (math.sqrt 16))
|
|
216
|
+
|
|
217
|
+
(md "## Load and split the image dataset"
|
|
218
|
+
"Use the original TorchVision preprocessing for the pretrained ResNet18 weights. Classes come from your own image folders; samples are split reproducibly into training and validation.")
|
|
219
|
+
(import torch)
|
|
220
|
+
(import torchvision)
|
|
221
|
+
(import lispyn.media [image-folder])
|
|
222
|
+
(import lispyn.data [split-dataset])
|
|
223
|
+
(import lispyn.reproducibility [seed-all])
|
|
224
|
+
|
|
225
|
+
(seed-all 42)
|
|
226
|
+
(setv weights torchvision.models.ResNet18_Weights.DEFAULT)
|
|
227
|
+
(setv dataset (image-folder "data/resnet_images" :transform (weights.transforms)))
|
|
228
|
+
(setv groups (split-dataset dataset :stratify True :validation-fraction 0.2 :seed 42))
|
|
229
|
+
(setv training (get groups 0))
|
|
230
|
+
(setv validation (get groups 1))
|
|
231
|
+
(setv model (torchvision.models.resnet18 :weights weights))
|
|
232
|
+
(setv model.fc (torch.nn.Linear model.fc.in_features (len dataset.classes)))
|
|
233
|
+
(print "Classes:" dataset.classes)
|
|
234
|
+
(print "Train/validation:" (len training) (len validation))
|
|
235
|
+
|
|
236
|
+
(md "## Phase 1 — classifier fine-tuning"
|
|
237
|
+
"Freeze the pretrained ResNet18 backbone and optimize only `model.fc` for **10 epochs**. The class split is reproducible and separate from the training set."
|
|
238
|
+
"**Note:** This example needs at least two labeled images per class. For correlated images from the same subject, use a *group-aware split* instead.")
|
|
239
|
+
|
|
240
|
+
(require lispyn.macros [head-tune])
|
|
241
|
+
(setv head-run
|
|
242
|
+
(head-tune model training "fc"
|
|
243
|
+
:validation validation
|
|
244
|
+
:loss-fn (torch.nn.CrossEntropyLoss)
|
|
245
|
+
:epochs 10
|
|
246
|
+
:batch-size 16
|
|
247
|
+
:lr 0.001
|
|
248
|
+
:seed 42
|
|
249
|
+
:metrics "accuracy"
|
|
250
|
+
:experiment-dir "runs/resnet/head"))
|
|
251
|
+
(print "Head validation accuracy:" (get head-run.history "val_accuracy"))
|
|
252
|
+
|
|
253
|
+
(md "## Phase 2 — deep/full fine-tuning: 300 epochs"
|
|
254
|
+
"Unfreeze **every ResNet18 layer**, create a new optimizer with a smaller learning rate, and train for **300 epochs**. This is full fine-tuning of pretrained weights, **not** training from scratch."
|
|
255
|
+
"A real 300-epoch run may take hours and require a GPU. Run it only with your own dataset and appropriate resources.")
|
|
256
|
+
|
|
257
|
+
(require lispyn.macros [full-tune])
|
|
258
|
+
(setv deep-run
|
|
259
|
+
(full-tune head-run.model training
|
|
260
|
+
:validation validation
|
|
261
|
+
:loss-fn (torch.nn.CrossEntropyLoss)
|
|
262
|
+
:epochs 300
|
|
263
|
+
:batch-size 16
|
|
264
|
+
:lr 0.00001
|
|
265
|
+
:seed 42
|
|
266
|
+
:metrics "accuracy"
|
|
267
|
+
:experiment-dir "runs/resnet/deep"))
|
|
268
|
+
(print "Full tuning best accuracy:" (max (get deep-run.history "val_accuracy")))
|
|
269
|
+
|
|
270
|
+
(md "## Curves and export"
|
|
271
|
+
"Use one Lisp macro to define a consistent Matplotlib style for **both** training curves. The best checkpoints and JSON histories are saved under `runs/resnet/`.")
|
|
272
|
+
|
|
273
|
+
(require lispyn.macros [defcurve])
|
|
274
|
+
(defcurve resnet-curve
|
|
275
|
+
:theme "paper"
|
|
276
|
+
:train-color "#2563EB"
|
|
277
|
+
:val-color "#D97706"
|
|
278
|
+
:xlabel "Epoch"
|
|
279
|
+
:train-label "Train"
|
|
280
|
+
:val-label "Validation"
|
|
281
|
+
:figsize [9 4])
|
|
282
|
+
|
|
283
|
+
(resnet-curve deep-run :metric "loss"
|
|
284
|
+
:title "ResNet18 — 300-epoch loss"
|
|
285
|
+
:ylabel "Cross-entropy loss"
|
|
286
|
+
:save "runs/resnet/deep/loss.png")
|
|
287
|
+
|
|
288
|
+
(resnet-curve deep-run :metric "accuracy"
|
|
289
|
+
:title "ResNet18 — 300-epoch accuracy"
|
|
290
|
+
:ylabel "Top-1 accuracy"
|
|
291
|
+
:save "runs/resnet/deep/accuracy.png")
|
|
292
|
+
(print "Saved ResNet18 plots, histories, and best checkpoints.")
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
## Generated notebook
|
|
296
|
+
|
|
297
|
+
**[Open the generated ResNet18 notebook](https://github.com/edujbarrios/lispyn/blob/main/example_generated_notebooks/resnet_finetune_300.ipynb)** in [`example_generated_notebooks/`](https://github.com/edujbarrios/lispyn/tree/main/example_generated_notebooks/). It contains real Markdown and translated Python code cells, but **no simulated losses or training outputs**. Use `lispyn gallery` to regenerate the examples without running training.
|
|
298
|
+
|
|
299
|
+
To install Lispyn from this repository, use `python -m pip install -e ".[notebook,plots]"`. Run `lispyn build examples/resnet_finetune_300.hy` to regenerate the notebook, or `lispyn execute examples/resnet_finetune_300.hy -o example_generated_notebooks/resnet_finetune_300.ipynb` to **actually train** and save the outputs.
|
|
300
|
+
|
|
301
|
+
The `pip-install` macro creates a dedicated dependency cell that checks availability when the notebook **runs**, not when it compiles. Available packages print *Requirement already installed in this environment*. Missing named packages can be installed through the notebook kernel’s Python interpreter. Python's standard-library `math` module requires no pip install. GPU-compatible PyTorch builds should normally be installed separately in advance; installing packages into a running kernel may require a restart.
|
|
302
|
+
|
|
303
|
+
**This experiment has not been trained for 300 epochs in CI.** It needs an image dataset and may require substantial compute. Stratified sample-level splitting is not group-aware; use a grouped split when images come from the same subjects, patients or sessions.
|
|
304
|
+
|
|
305
|
+
More capabilities, examples and package options are in the [technical guide](https://github.com/edujbarrios/lispyn/blob/main/docs/guide.md). Created by **Eduardo J. Barrios**. Apache-2.0 licensed; see [LICENSE](https://github.com/edujbarrios/lispyn/blob/main/LICENSE) and [NOTICE](https://github.com/edujbarrios/lispyn/blob/main/NOTICE).
|