LeNEPA Encoder trained on Aionoscope balanced dataset
Browse files- .gitattributes +1 -34
- LICENSE +399 -0
- README.md +57 -0
- __pycache__/inference.cpython-312.pyc +0 -0
- inference.py +272 -0
- lenepa_encoder.safetensors +3 -0
- lenepa_encoder_config.json +24 -0
- provenance.json +14 -0
- requirements.txt +3 -0
.gitattributes
CHANGED
|
@@ -1,35 +1,2 @@
|
|
| 1 |
-
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
-
|
| 27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LICENSE
ADDED
|
@@ -0,0 +1,399 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
| 1 |
+
Attribution-NonCommercial 4.0 International
|
| 2 |
+
|
| 3 |
+
=======================================================================
|
| 4 |
+
|
| 5 |
+
Creative Commons Corporation ("Creative Commons") is not a law firm and
|
| 6 |
+
does not provide legal services or legal advice. Distribution of
|
| 7 |
+
Creative Commons public licenses does not create a lawyer-client or
|
| 8 |
+
other relationship. Creative Commons makes its licenses and related
|
| 9 |
+
information available on an "as-is" basis. Creative Commons gives no
|
| 10 |
+
warranties regarding its licenses, any material licensed under their
|
| 11 |
+
terms and conditions, or any related information. Creative Commons
|
| 12 |
+
disclaims all liability for damages resulting from their use to the
|
| 13 |
+
fullest extent possible.
|
| 14 |
+
|
| 15 |
+
Using Creative Commons Public Licenses
|
| 16 |
+
|
| 17 |
+
Creative Commons public licenses provide a standard set of terms and
|
| 18 |
+
conditions that creators and other rights holders may use to share
|
| 19 |
+
original works of authorship and other material subject to copyright
|
| 20 |
+
and certain other rights specified in the public license below. The
|
| 21 |
+
following considerations are for informational purposes only, are not
|
| 22 |
+
exhaustive, and do not form part of our licenses.
|
| 23 |
+
|
| 24 |
+
Considerations for licensors: Our public licenses are
|
| 25 |
+
intended for use by those authorized to give the public
|
| 26 |
+
permission to use material in ways otherwise restricted by
|
| 27 |
+
copyright and certain other rights. Our licenses are
|
| 28 |
+
irrevocable. Licensors should read and understand the terms
|
| 29 |
+
and conditions of the license they choose before applying it.
|
| 30 |
+
Licensors should also secure all rights necessary before
|
| 31 |
+
applying our licenses so that the public can reuse the
|
| 32 |
+
material as expected. Licensors should clearly mark any
|
| 33 |
+
material not subject to the license. This includes other CC-
|
| 34 |
+
licensed material, or material used under an exception or
|
| 35 |
+
limitation to copyright. More considerations for licensors:
|
| 36 |
+
wiki.creativecommons.org/Considerations_for_licensors
|
| 37 |
+
|
| 38 |
+
Considerations for the public: By using one of our public
|
| 39 |
+
licenses, a licensor grants the public permission to use the
|
| 40 |
+
licensed material under specified terms and conditions. If
|
| 41 |
+
the licensor's permission is not necessary for any reason--for
|
| 42 |
+
example, because of any applicable exception or limitation to
|
| 43 |
+
copyright--then that use is not regulated by the license. Our
|
| 44 |
+
licenses grant only permissions under copyright and certain
|
| 45 |
+
other rights that a licensor has authority to grant. Use of
|
| 46 |
+
the licensed material may still be restricted for other
|
| 47 |
+
reasons, including because others have copyright or other
|
| 48 |
+
rights in the material. A licensor may make special requests,
|
| 49 |
+
such as asking that all changes be marked or described.
|
| 50 |
+
Although not required by our licenses, you are encouraged to
|
| 51 |
+
respect those requests where reasonable. More_considerations
|
| 52 |
+
for the public:
|
| 53 |
+
wiki.creativecommons.org/Considerations_for_licensees
|
| 54 |
+
|
| 55 |
+
=======================================================================
|
| 56 |
+
|
| 57 |
+
Creative Commons Attribution-NonCommercial 4.0 International Public
|
| 58 |
+
License
|
| 59 |
+
|
| 60 |
+
By exercising the Licensed Rights (defined below), You accept and agree
|
| 61 |
+
to be bound by the terms and conditions of this Creative Commons
|
| 62 |
+
Attribution-NonCommercial 4.0 International Public License ("Public
|
| 63 |
+
License"). To the extent this Public License may be interpreted as a
|
| 64 |
+
contract, You are granted the Licensed Rights in consideration of Your
|
| 65 |
+
acceptance of these terms and conditions, and the Licensor grants You
|
| 66 |
+
such rights in consideration of benefits the Licensor receives from
|
| 67 |
+
making the Licensed Material available under these terms and
|
| 68 |
+
conditions.
|
| 69 |
+
|
| 70 |
+
Section 1 -- Definitions.
|
| 71 |
+
|
| 72 |
+
a. Adapted Material means material subject to Copyright and Similar
|
| 73 |
+
Rights that is derived from or based upon the Licensed Material
|
| 74 |
+
and in which the Licensed Material is translated, altered,
|
| 75 |
+
arranged, transformed, or otherwise modified in a manner requiring
|
| 76 |
+
permission under the Copyright and Similar Rights held by the
|
| 77 |
+
Licensor. For purposes of this Public License, where the Licensed
|
| 78 |
+
Material is a musical work, performance, or sound recording,
|
| 79 |
+
Adapted Material is always produced where the Licensed Material is
|
| 80 |
+
synched in timed relation with a moving image.
|
| 81 |
+
|
| 82 |
+
b. Adapter's License means the license You apply to Your Copyright
|
| 83 |
+
and Similar Rights in Your contributions to Adapted Material in
|
| 84 |
+
accordance with the terms and conditions of this Public License.
|
| 85 |
+
|
| 86 |
+
c. Copyright and Similar Rights means copyright and/or similar rights
|
| 87 |
+
closely related to copyright including, without limitation,
|
| 88 |
+
performance, broadcast, sound recording, and Sui Generis Database
|
| 89 |
+
Rights, without regard to how the rights are labeled or
|
| 90 |
+
categorized. For purposes of this Public License, the rights
|
| 91 |
+
specified in Section 2(b)(1)-(2) are not Copyright and Similar
|
| 92 |
+
Rights.
|
| 93 |
+
d. Effective Technological Measures means those measures that, in the
|
| 94 |
+
absence of proper authority, may not be circumvented under laws
|
| 95 |
+
fulfilling obligations under Article 11 of the WIPO Copyright
|
| 96 |
+
Treaty adopted on December 20, 1996, and/or similar international
|
| 97 |
+
agreements.
|
| 98 |
+
|
| 99 |
+
e. Exceptions and Limitations means fair use, fair dealing, and/or
|
| 100 |
+
any other exception or limitation to Copyright and Similar Rights
|
| 101 |
+
that applies to Your use of the Licensed Material.
|
| 102 |
+
|
| 103 |
+
f. Licensed Material means the artistic or literary work, database,
|
| 104 |
+
or other material to which the Licensor applied this Public
|
| 105 |
+
License.
|
| 106 |
+
|
| 107 |
+
g. Licensed Rights means the rights granted to You subject to the
|
| 108 |
+
terms and conditions of this Public License, which are limited to
|
| 109 |
+
all Copyright and Similar Rights that apply to Your use of the
|
| 110 |
+
Licensed Material and that the Licensor has authority to license.
|
| 111 |
+
|
| 112 |
+
h. Licensor means the individual(s) or entity(ies) granting rights
|
| 113 |
+
under this Public License.
|
| 114 |
+
|
| 115 |
+
i. NonCommercial means not primarily intended for or directed towards
|
| 116 |
+
commercial advantage or monetary compensation. For purposes of
|
| 117 |
+
this Public License, the exchange of the Licensed Material for
|
| 118 |
+
other material subject to Copyright and Similar Rights by digital
|
| 119 |
+
file-sharing or similar means is NonCommercial provided there is
|
| 120 |
+
no payment of monetary compensation in connection with the
|
| 121 |
+
exchange.
|
| 122 |
+
|
| 123 |
+
j. Share means to provide material to the public by any means or
|
| 124 |
+
process that requires permission under the Licensed Rights, such
|
| 125 |
+
as reproduction, public display, public performance, distribution,
|
| 126 |
+
dissemination, communication, or importation, and to make material
|
| 127 |
+
available to the public including in ways that members of the
|
| 128 |
+
public may access the material from a place and at a time
|
| 129 |
+
individually chosen by them.
|
| 130 |
+
|
| 131 |
+
k. Sui Generis Database Rights means rights other than copyright
|
| 132 |
+
resulting from Directive 96/9/EC of the European Parliament and of
|
| 133 |
+
the Council of 11 March 1996 on the legal protection of databases,
|
| 134 |
+
as amended and/or succeeded, as well as other essentially
|
| 135 |
+
equivalent rights anywhere in the world.
|
| 136 |
+
|
| 137 |
+
l. You means the individual or entity exercising the Licensed Rights
|
| 138 |
+
under this Public License. Your has a corresponding meaning.
|
| 139 |
+
|
| 140 |
+
Section 2 -- Scope.
|
| 141 |
+
|
| 142 |
+
a. License grant.
|
| 143 |
+
|
| 144 |
+
1. Subject to the terms and conditions of this Public License,
|
| 145 |
+
the Licensor hereby grants You a worldwide, royalty-free,
|
| 146 |
+
non-sublicensable, non-exclusive, irrevocable license to
|
| 147 |
+
exercise the Licensed Rights in the Licensed Material to:
|
| 148 |
+
|
| 149 |
+
a. reproduce and Share the Licensed Material, in whole or
|
| 150 |
+
in part, for NonCommercial purposes only; and
|
| 151 |
+
|
| 152 |
+
b. produce, reproduce, and Share Adapted Material for
|
| 153 |
+
NonCommercial purposes only.
|
| 154 |
+
|
| 155 |
+
2. Exceptions and Limitations. For the avoidance of doubt, where
|
| 156 |
+
Exceptions and Limitations apply to Your use, this Public
|
| 157 |
+
License does not apply, and You do not need to comply with
|
| 158 |
+
its terms and conditions.
|
| 159 |
+
|
| 160 |
+
3. Term. The term of this Public License is specified in Section
|
| 161 |
+
6(a).
|
| 162 |
+
|
| 163 |
+
4. Media and formats; technical modifications allowed. The
|
| 164 |
+
Licensor authorizes You to exercise the Licensed Rights in
|
| 165 |
+
all media and formats whether now known or hereafter created,
|
| 166 |
+
and to make technical modifications necessary to do so. The
|
| 167 |
+
Licensor waives and/or agrees not to assert any right or
|
| 168 |
+
authority to forbid You from making technical modifications
|
| 169 |
+
necessary to exercise the Licensed Rights, including
|
| 170 |
+
technical modifications necessary to circumvent Effective
|
| 171 |
+
Technological Measures. For purposes of this Public License,
|
| 172 |
+
simply making modifications authorized by this Section 2(a)
|
| 173 |
+
(4) never produces Adapted Material.
|
| 174 |
+
|
| 175 |
+
5. Downstream recipients.
|
| 176 |
+
|
| 177 |
+
a. Offer from the Licensor -- Licensed Material. Every
|
| 178 |
+
recipient of the Licensed Material automatically
|
| 179 |
+
receives an offer from the Licensor to exercise the
|
| 180 |
+
Licensed Rights under the terms and conditions of this
|
| 181 |
+
Public License.
|
| 182 |
+
|
| 183 |
+
b. No downstream restrictions. You may not offer or impose
|
| 184 |
+
any additional or different terms or conditions on, or
|
| 185 |
+
apply any Effective Technological Measures to, the
|
| 186 |
+
Licensed Material if doing so restricts exercise of the
|
| 187 |
+
Licensed Rights by any recipient of the Licensed
|
| 188 |
+
Material.
|
| 189 |
+
|
| 190 |
+
6. No endorsement. Nothing in this Public License constitutes or
|
| 191 |
+
may be construed as permission to assert or imply that You
|
| 192 |
+
are, or that Your use of the Licensed Material is, connected
|
| 193 |
+
with, or sponsored, endorsed, or granted official status by,
|
| 194 |
+
the Licensor or others designated to receive attribution as
|
| 195 |
+
provided in Section 3(a)(1)(A)(i).
|
| 196 |
+
|
| 197 |
+
b. Other rights.
|
| 198 |
+
|
| 199 |
+
1. Moral rights, such as the right of integrity, are not
|
| 200 |
+
licensed under this Public License, nor are publicity,
|
| 201 |
+
privacy, and/or other similar personality rights; however, to
|
| 202 |
+
the extent possible, the Licensor waives and/or agrees not to
|
| 203 |
+
assert any such rights held by the Licensor to the limited
|
| 204 |
+
extent necessary to allow You to exercise the Licensed
|
| 205 |
+
Rights, but not otherwise.
|
| 206 |
+
|
| 207 |
+
2. Patent and trademark rights are not licensed under this
|
| 208 |
+
Public License.
|
| 209 |
+
|
| 210 |
+
3. To the extent possible, the Licensor waives any right to
|
| 211 |
+
collect royalties from You for the exercise of the Licensed
|
| 212 |
+
Rights, whether directly or through a collecting society
|
| 213 |
+
under any voluntary or waivable statutory or compulsory
|
| 214 |
+
licensing scheme. In all other cases the Licensor expressly
|
| 215 |
+
reserves any right to collect such royalties, including when
|
| 216 |
+
the Licensed Material is used other than for NonCommercial
|
| 217 |
+
purposes.
|
| 218 |
+
|
| 219 |
+
Section 3 -- License Conditions.
|
| 220 |
+
|
| 221 |
+
Your exercise of the Licensed Rights is expressly made subject to the
|
| 222 |
+
following conditions.
|
| 223 |
+
|
| 224 |
+
a. Attribution.
|
| 225 |
+
|
| 226 |
+
1. If You Share the Licensed Material (including in modified
|
| 227 |
+
form), You must:
|
| 228 |
+
|
| 229 |
+
a. retain the following if it is supplied by the Licensor
|
| 230 |
+
with the Licensed Material:
|
| 231 |
+
|
| 232 |
+
i. identification of the creator(s) of the Licensed
|
| 233 |
+
Material and any others designated to receive
|
| 234 |
+
attribution, in any reasonable manner requested by
|
| 235 |
+
the Licensor (including by pseudonym if
|
| 236 |
+
designated);
|
| 237 |
+
|
| 238 |
+
ii. a copyright notice;
|
| 239 |
+
|
| 240 |
+
iii. a notice that refers to this Public License;
|
| 241 |
+
|
| 242 |
+
iv. a notice that refers to the disclaimer of
|
| 243 |
+
warranties;
|
| 244 |
+
|
| 245 |
+
v. a URI or hyperlink to the Licensed Material to the
|
| 246 |
+
extent reasonably practicable;
|
| 247 |
+
|
| 248 |
+
b. indicate if You modified the Licensed Material and
|
| 249 |
+
retain an indication of any previous modifications; and
|
| 250 |
+
|
| 251 |
+
c. indicate the Licensed Material is licensed under this
|
| 252 |
+
Public License, and include the text of, or the URI or
|
| 253 |
+
hyperlink to, this Public License.
|
| 254 |
+
|
| 255 |
+
2. You may satisfy the conditions in Section 3(a)(1) in any
|
| 256 |
+
reasonable manner based on the medium, means, and context in
|
| 257 |
+
which You Share the Licensed Material. For example, it may be
|
| 258 |
+
reasonable to satisfy the conditions by providing a URI or
|
| 259 |
+
hyperlink to a resource that includes the required
|
| 260 |
+
information.
|
| 261 |
+
|
| 262 |
+
3. If requested by the Licensor, You must remove any of the
|
| 263 |
+
information required by Section 3(a)(1)(A) to the extent
|
| 264 |
+
reasonably practicable.
|
| 265 |
+
|
| 266 |
+
4. If You Share Adapted Material You produce, the Adapter's
|
| 267 |
+
License You apply must not prevent recipients of the Adapted
|
| 268 |
+
Material from complying with this Public License.
|
| 269 |
+
|
| 270 |
+
Section 4 -- Sui Generis Database Rights.
|
| 271 |
+
|
| 272 |
+
Where the Licensed Rights include Sui Generis Database Rights that
|
| 273 |
+
apply to Your use of the Licensed Material:
|
| 274 |
+
|
| 275 |
+
a. for the avoidance of doubt, Section 2(a)(1) grants You the right
|
| 276 |
+
to extract, reuse, reproduce, and Share all or a substantial
|
| 277 |
+
portion of the contents of the database for NonCommercial purposes
|
| 278 |
+
only;
|
| 279 |
+
|
| 280 |
+
b. if You include all or a substantial portion of the database
|
| 281 |
+
contents in a database in which You have Sui Generis Database
|
| 282 |
+
Rights, then the database in which You have Sui Generis Database
|
| 283 |
+
Rights (but not its individual contents) is Adapted Material; and
|
| 284 |
+
|
| 285 |
+
c. You must comply with the conditions in Section 3(a) if You Share
|
| 286 |
+
all or a substantial portion of the contents of the database.
|
| 287 |
+
|
| 288 |
+
For the avoidance of doubt, this Section 4 supplements and does not
|
| 289 |
+
replace Your obligations under this Public License where the Licensed
|
| 290 |
+
Rights include other Copyright and Similar Rights.
|
| 291 |
+
|
| 292 |
+
Section 5 -- Disclaimer of Warranties and Limitation of Liability.
|
| 293 |
+
|
| 294 |
+
a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
|
| 295 |
+
EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
|
| 296 |
+
AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
|
| 297 |
+
ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
|
| 298 |
+
IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
|
| 299 |
+
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
| 300 |
+
PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
|
| 301 |
+
ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
|
| 302 |
+
KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
|
| 303 |
+
ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
|
| 304 |
+
|
| 305 |
+
b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
|
| 306 |
+
TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
|
| 307 |
+
NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
|
| 308 |
+
INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
|
| 309 |
+
COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
|
| 310 |
+
USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
|
| 311 |
+
ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
|
| 312 |
+
DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
|
| 313 |
+
IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
|
| 314 |
+
|
| 315 |
+
c. The disclaimer of warranties and limitation of liability provided
|
| 316 |
+
above shall be interpreted in a manner that, to the extent
|
| 317 |
+
possible, most closely approximates an absolute disclaimer and
|
| 318 |
+
waiver of all liability.
|
| 319 |
+
|
| 320 |
+
Section 6 -- Term and Termination.
|
| 321 |
+
|
| 322 |
+
a. This Public License applies for the term of the Copyright and
|
| 323 |
+
Similar Rights licensed here. However, if You fail to comply with
|
| 324 |
+
this Public License, then Your rights under this Public License
|
| 325 |
+
terminate automatically.
|
| 326 |
+
|
| 327 |
+
b. Where Your right to use the Licensed Material has terminated under
|
| 328 |
+
Section 6(a), it reinstates:
|
| 329 |
+
|
| 330 |
+
1. automatically as of the date the violation is cured, provided
|
| 331 |
+
it is cured within 30 days of Your discovery of the
|
| 332 |
+
violation; or
|
| 333 |
+
|
| 334 |
+
2. upon express reinstatement by the Licensor.
|
| 335 |
+
|
| 336 |
+
For the avoidance of doubt, this Section 6(b) does not affect any
|
| 337 |
+
right the Licensor may have to seek remedies for Your violations
|
| 338 |
+
of this Public License.
|
| 339 |
+
|
| 340 |
+
c. For the avoidance of doubt, the Licensor may also offer the
|
| 341 |
+
Licensed Material under separate terms or conditions or stop
|
| 342 |
+
distributing the Licensed Material at any time; however, doing so
|
| 343 |
+
will not terminate this Public License.
|
| 344 |
+
|
| 345 |
+
d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
|
| 346 |
+
License.
|
| 347 |
+
|
| 348 |
+
Section 7 -- Other Terms and Conditions.
|
| 349 |
+
|
| 350 |
+
a. The Licensor shall not be bound by any additional or different
|
| 351 |
+
terms or conditions communicated by You unless expressly agreed.
|
| 352 |
+
|
| 353 |
+
b. Any arrangements, understandings, or agreements regarding the
|
| 354 |
+
Licensed Material not stated herein are separate from and
|
| 355 |
+
independent of the terms and conditions of this Public License.
|
| 356 |
+
|
| 357 |
+
Section 8 -- Interpretation.
|
| 358 |
+
|
| 359 |
+
a. For the avoidance of doubt, this Public License does not, and
|
| 360 |
+
shall not be interpreted to, reduce, limit, restrict, or impose
|
| 361 |
+
conditions on any use of the Licensed Material that could lawfully
|
| 362 |
+
be made without permission under this Public License.
|
| 363 |
+
|
| 364 |
+
b. To the extent possible, if any provision of this Public License is
|
| 365 |
+
deemed unenforceable, it shall be automatically reformed to the
|
| 366 |
+
minimum extent necessary to make it enforceable. If the provision
|
| 367 |
+
cannot be reformed, it shall be severed from this Public License
|
| 368 |
+
without affecting the enforceability of the remaining terms and
|
| 369 |
+
conditions.
|
| 370 |
+
|
| 371 |
+
c. No term or condition of this Public License will be waived and no
|
| 372 |
+
failure to comply consented to unless expressly agreed to by the
|
| 373 |
+
Licensor.
|
| 374 |
+
|
| 375 |
+
d. Nothing in this Public License constitutes or may be interpreted
|
| 376 |
+
as a limitation upon, or waiver of, any privileges and immunities
|
| 377 |
+
that apply to the Licensor or You, including from the legal
|
| 378 |
+
processes of any jurisdiction or authority.
|
| 379 |
+
|
| 380 |
+
=======================================================================
|
| 381 |
+
|
| 382 |
+
Creative Commons is not a party to its public
|
| 383 |
+
licenses. Notwithstanding, Creative Commons may elect to apply one of
|
| 384 |
+
its public licenses to material it publishes and in those instances
|
| 385 |
+
will be considered the “Licensor.” The text of the Creative Commons
|
| 386 |
+
public licenses is dedicated to the public domain under the CC0 Public
|
| 387 |
+
Domain Dedication. Except for the limited purpose of indicating that
|
| 388 |
+
material is shared under a Creative Commons public license or as
|
| 389 |
+
otherwise permitted by the Creative Commons policies published at
|
| 390 |
+
creativecommons.org/policies, Creative Commons does not authorize the
|
| 391 |
+
use of the trademark "Creative Commons" or any other trademark or logo
|
| 392 |
+
of Creative Commons without its prior written consent including,
|
| 393 |
+
without limitation, in connection with any unauthorized modifications
|
| 394 |
+
to any of its public licenses or any other arrangements,
|
| 395 |
+
understandings, or agreements concerning use of licensed material. For
|
| 396 |
+
the avoidance of doubt, this paragraph does not form part of the
|
| 397 |
+
public licenses.
|
| 398 |
+
|
| 399 |
+
Creative Commons may be contacted at creativecommons.org.
|
README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-nc-4.0
|
| 3 |
+
library_name: pytorch
|
| 4 |
+
tags:
|
| 5 |
+
- time-series
|
| 6 |
+
- ecg
|
| 7 |
+
- representation-learning
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
# LeNEPA encoder (balanced, encoder-only)
|
| 11 |
+
|
| 12 |
+
This repository contains an **encoder-only** LeNEPA checkpoint exported to `safetensors` for minimal inference.
|
| 13 |
+
|
| 14 |
+
What is included:
|
| 15 |
+
|
| 16 |
+
- `lenepa_encoder.safetensors` — **encoder weights only** (no projector, no training/probe state)
|
| 17 |
+
- `inference.py` — minimal end-to-end inference (no Hydra, no W&B)
|
| 18 |
+
- `lenepa_encoder_config.json` — fixed IO + architecture contract
|
| 19 |
+
- `provenance.json` — original `.pt` checkpoint path + W&B URL
|
| 20 |
+
|
| 21 |
+
## IO contract
|
| 22 |
+
|
| 23 |
+
Inputs:
|
| 24 |
+
|
| 25 |
+
- `x_waveform`: `torch.float32` with shape `[B, 1, 5000]`
|
| 26 |
+
- sampling frequency: `500` Hz
|
| 27 |
+
- channels: `["I"]` (so `C=1`)
|
| 28 |
+
|
| 29 |
+
Outputs:
|
| 30 |
+
|
| 31 |
+
- `patch_tokens`: `[B, 200, 192]` (post-final-norm tokens)
|
| 32 |
+
- `embedding`: `[B, 192]` (mean pooled over tokens)
|
| 33 |
+
|
| 34 |
+
## Usage
|
| 35 |
+
|
| 36 |
+
Smoke test (loads `lenepa_encoder.safetensors` from the current directory and prints output shapes):
|
| 37 |
+
|
| 38 |
+
```bash
|
| 39 |
+
python inference.py
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
Programmatic usage:
|
| 43 |
+
|
| 44 |
+
```python
|
| 45 |
+
from pathlib import Path
|
| 46 |
+
|
| 47 |
+
import torch
|
| 48 |
+
|
| 49 |
+
from inference import encode_lenepa, load_lenepa_encoder
|
| 50 |
+
|
| 51 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 52 |
+
model = load_lenepa_encoder(weights_path=Path("lenepa_encoder.safetensors"), device=device)
|
| 53 |
+
x = torch.randn(2, 1, 5000, device=device, dtype=torch.float32) # [B, C, L]
|
| 54 |
+
out = encode_lenepa(model=model, x_waveform=x)
|
| 55 |
+
print(out.embedding.shape)
|
| 56 |
+
```
|
| 57 |
+
|
__pycache__/inference.cpython-312.pyc
ADDED
|
Binary file (16.1 kB). View file
|
|
|
inference.py
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Minimal inference for the published LeNEPA *encoder* checkpoint (no projector).
|
| 2 |
+
|
| 3 |
+
Published IO contract:
|
| 4 |
+
- x_waveform: torch.float32 [B, 1, 5000] at 500 Hz, channel order: ["I"]
|
| 5 |
+
- outputs:
|
| 6 |
+
patch_tokens: [B, 200, 192]
|
| 7 |
+
embedding: [B, 192]
|
| 8 |
+
|
| 9 |
+
This code intentionally does NOT:
|
| 10 |
+
- resample / crop / pad / normalize inputs
|
| 11 |
+
- support other checkpoints or architectures
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
from __future__ import annotations
|
| 15 |
+
|
| 16 |
+
from dataclasses import dataclass
|
| 17 |
+
from pathlib import Path
|
| 18 |
+
|
| 19 |
+
import torch
|
| 20 |
+
from safetensors.torch import load_file as safetensors_load
|
| 21 |
+
from torch import nn
|
| 22 |
+
from torch.nn import functional as F
|
| 23 |
+
|
| 24 |
+
# -----------------------------
|
| 25 |
+
# Published constants (no knobs)
|
| 26 |
+
# -----------------------------
|
| 27 |
+
|
| 28 |
+
SAMPLING_FREQUENCY_HZ = 500
|
| 29 |
+
CHANNELS = ("I",)
|
| 30 |
+
|
| 31 |
+
NUM_CHANNELS = 1
|
| 32 |
+
CHANNEL_SIZE = 5000
|
| 33 |
+
PATCH_SIZE = 25
|
| 34 |
+
NUM_PATCHES = 200 # 5000 / 25
|
| 35 |
+
|
| 36 |
+
DIM = 192
|
| 37 |
+
DEPTH = 8
|
| 38 |
+
NUM_HEADS = 4
|
| 39 |
+
MLP_RATIO = 4.0
|
| 40 |
+
|
| 41 |
+
QKV_BIAS = True
|
| 42 |
+
NORM_EPS = 1e-6
|
| 43 |
+
|
| 44 |
+
ROPE_BASE = 10_000
|
| 45 |
+
QK_NORM_EPS = 1e-6
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
@dataclass(frozen=True)
|
| 49 |
+
class LeNEPAEncoderOutput:
|
| 50 |
+
"""Outputs of the published LeNEPA encoder."""
|
| 51 |
+
|
| 52 |
+
patch_tokens: torch.Tensor # [B, T=200, D=192]
|
| 53 |
+
embedding: torch.Tensor # [B, D=192]
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
class RotaryEmbedding(nn.Module):
|
| 57 |
+
"""Rotary positional embeddings (RoPE) applied to Q/K."""
|
| 58 |
+
|
| 59 |
+
def __init__(self, *, dim: int, base: int) -> None:
|
| 60 |
+
super().__init__()
|
| 61 |
+
if dim % 2 != 0:
|
| 62 |
+
raise ValueError(f"RoPE requires even head_dim, got {dim}")
|
| 63 |
+
inv_freq = 1.0 / (base ** (torch.arange(0, dim, 2, dtype=torch.float32) / dim)) # [Dh/2]
|
| 64 |
+
self.register_buffer("inv_freq", inv_freq, persistent=False)
|
| 65 |
+
self._seq_len_cached: int | None = None
|
| 66 |
+
self._cos_cached: torch.Tensor | None = None
|
| 67 |
+
self._sin_cached: torch.Tensor | None = None
|
| 68 |
+
self._device_cached: torch.device | None = None
|
| 69 |
+
self._dtype_cached: torch.dtype | None = None
|
| 70 |
+
|
| 71 |
+
def _build_cache(self, *, seq_len: int, device: torch.device, dtype: torch.dtype) -> None:
|
| 72 |
+
positions = torch.arange(seq_len, device=device, dtype=self.inv_freq.dtype) # [T]
|
| 73 |
+
freqs = torch.einsum("i,j->ij", positions, self.inv_freq) # [T, Dh/2]
|
| 74 |
+
self._cos_cached = freqs.cos().to(dtype) # [T, Dh/2]
|
| 75 |
+
self._sin_cached = freqs.sin().to(dtype) # [T, Dh/2]
|
| 76 |
+
self._seq_len_cached = seq_len
|
| 77 |
+
self._device_cached = device
|
| 78 |
+
self._dtype_cached = dtype
|
| 79 |
+
|
| 80 |
+
def _get_cos_sin(
|
| 81 |
+
self, *, seq_len: int, device: torch.device, dtype: torch.dtype
|
| 82 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 83 |
+
if (
|
| 84 |
+
self._cos_cached is None
|
| 85 |
+
or self._sin_cached is None
|
| 86 |
+
or self._seq_len_cached != seq_len
|
| 87 |
+
or self._device_cached != device
|
| 88 |
+
or self._dtype_cached != dtype
|
| 89 |
+
):
|
| 90 |
+
self._build_cache(seq_len=seq_len, device=device, dtype=dtype)
|
| 91 |
+
if self._cos_cached is None or self._sin_cached is None:
|
| 92 |
+
raise RuntimeError("RoPE cache was not built; this is a bug")
|
| 93 |
+
return self._cos_cached, self._sin_cached
|
| 94 |
+
|
| 95 |
+
def _apply_rotary(self, x: torch.Tensor, *, cos: torch.Tensor, sin: torch.Tensor) -> torch.Tensor:
|
| 96 |
+
# x: [B, H, T, Dh]
|
| 97 |
+
B, H, T, Dh = x.shape
|
| 98 |
+
x_2 = x.view(B, H, T, Dh // 2, 2) # [B, H, T, Dh/2, 2]
|
| 99 |
+
x1 = x_2[..., 0] # [B, H, T, Dh/2]
|
| 100 |
+
x2 = x_2[..., 1] # [B, H, T, Dh/2]
|
| 101 |
+
cos = cos.unsqueeze(0).unsqueeze(0) # [1, 1, T, Dh/2]
|
| 102 |
+
sin = sin.unsqueeze(0).unsqueeze(0) # [1, 1, T, Dh/2]
|
| 103 |
+
out1 = x1 * cos - x2 * sin
|
| 104 |
+
out2 = x1 * sin + x2 * cos
|
| 105 |
+
return torch.stack((out1, out2), dim=-1).flatten(-2) # [B, H, T, Dh]
|
| 106 |
+
|
| 107 |
+
def apply(self, q: torch.Tensor, k: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]:
|
| 108 |
+
"""Apply RoPE to Q/K."""
|
| 109 |
+
cos, sin = self._get_cos_sin(seq_len=q.size(-2), device=q.device, dtype=q.dtype) # [T, Dh/2]
|
| 110 |
+
return self._apply_rotary(q, cos=cos, sin=sin), self._apply_rotary(k, cos=cos, sin=sin)
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
class Attention(nn.Module):
|
| 114 |
+
"""Causal self-attention with RoPE + QK-Norm (no dropout)."""
|
| 115 |
+
|
| 116 |
+
def __init__(self) -> None:
|
| 117 |
+
super().__init__()
|
| 118 |
+
if DIM % NUM_HEADS != 0:
|
| 119 |
+
raise ValueError(f"DIM must be divisible by NUM_HEADS, got DIM={DIM} NUM_HEADS={NUM_HEADS}")
|
| 120 |
+
head_dim = DIM // NUM_HEADS
|
| 121 |
+
self.num_heads = NUM_HEADS
|
| 122 |
+
self.rope = RotaryEmbedding(dim=head_dim, base=ROPE_BASE)
|
| 123 |
+
self.qk_norm = nn.LayerNorm(head_dim, eps=QK_NORM_EPS, elementwise_affine=False)
|
| 124 |
+
self.qkv = nn.Linear(DIM, DIM * 3, bias=QKV_BIAS)
|
| 125 |
+
self.proj = nn.Linear(DIM, DIM, bias=True)
|
| 126 |
+
|
| 127 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 128 |
+
# x: [B, T, D]
|
| 129 |
+
B, T, D = x.shape
|
| 130 |
+
qkv = (
|
| 131 |
+
self.qkv(x) # [B, T, 3*D]
|
| 132 |
+
.reshape(B, T, 3, self.num_heads, D // self.num_heads) # [B, T, 3, H, Dh]
|
| 133 |
+
.permute(2, 0, 3, 1, 4) # [3, B, H, T, Dh]
|
| 134 |
+
)
|
| 135 |
+
q, k, v = qkv[0], qkv[1], qkv[2] # each [B, H, T, Dh]
|
| 136 |
+
q, k = self.rope.apply(q, k) # [B, H, T, Dh] each
|
| 137 |
+
q = self.qk_norm(q) # [B, H, T, Dh]
|
| 138 |
+
k = self.qk_norm(k) # [B, H, T, Dh]
|
| 139 |
+
attn = F.scaled_dot_product_attention(q, k, v, dropout_p=0.0, is_causal=True) # [B, H, T, Dh]
|
| 140 |
+
out = attn.transpose(1, 2).reshape(B, T, D) # [B, T, D]
|
| 141 |
+
return self.proj(out) # [B, T, D]
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
class GatedMLP(nn.Module):
|
| 145 |
+
"""SwiGLU MLP used in this checkpoint."""
|
| 146 |
+
|
| 147 |
+
def __init__(self) -> None:
|
| 148 |
+
super().__init__()
|
| 149 |
+
hidden_dim = int((2 / 3) * MLP_RATIO * DIM)
|
| 150 |
+
if hidden_dim <= 0:
|
| 151 |
+
raise ValueError(f"hidden_dim must be > 0, got {hidden_dim}")
|
| 152 |
+
self.fc1 = nn.Linear(DIM, hidden_dim * 2, bias=True)
|
| 153 |
+
self.fc2 = nn.Linear(hidden_dim, DIM, bias=True)
|
| 154 |
+
self.act = nn.SiLU()
|
| 155 |
+
|
| 156 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 157 |
+
# x: [B, T, D]
|
| 158 |
+
gate_and_value = self.fc1(x) # [B, T, 2H]
|
| 159 |
+
gate, value = gate_and_value.chunk(2, dim=-1) # each [B, T, H]
|
| 160 |
+
return self.fc2(self.act(gate) * value) # [B, T, D]
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
class Block(nn.Module):
|
| 164 |
+
"""Transformer block: LN -> Attn -> residual -> LN -> MLP -> residual."""
|
| 165 |
+
|
| 166 |
+
def __init__(self) -> None:
|
| 167 |
+
super().__init__()
|
| 168 |
+
self.norm1 = nn.LayerNorm(DIM, eps=NORM_EPS)
|
| 169 |
+
self.attn = Attention()
|
| 170 |
+
self.norm2 = nn.LayerNorm(DIM, eps=NORM_EPS)
|
| 171 |
+
self.mlp = GatedMLP()
|
| 172 |
+
|
| 173 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 174 |
+
# x: [B, T, D]
|
| 175 |
+
x = x + self.attn(self.norm1(x)) # [B, T, D]
|
| 176 |
+
x = x + self.mlp(self.norm2(x)) # [B, T, D]
|
| 177 |
+
return x
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
class PatchEmbedding(nn.Module):
|
| 181 |
+
"""Conv patch embedding: Conv1d(C->D, kernel=stride=patch_size)."""
|
| 182 |
+
|
| 183 |
+
def __init__(self) -> None:
|
| 184 |
+
super().__init__()
|
| 185 |
+
self.proj = nn.Conv1d(
|
| 186 |
+
in_channels=NUM_CHANNELS,
|
| 187 |
+
out_channels=DIM,
|
| 188 |
+
kernel_size=PATCH_SIZE,
|
| 189 |
+
stride=PATCH_SIZE,
|
| 190 |
+
bias=True,
|
| 191 |
+
)
|
| 192 |
+
|
| 193 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 194 |
+
# x: [B, C, L]
|
| 195 |
+
z_t = self.proj(x) # [B, D, T]
|
| 196 |
+
return z_t.transpose(1, 2) # [B, T, D]
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
class LeNEPAEncoder(nn.Module):
|
| 200 |
+
"""LeNEPA encoder trunk for this exact checkpoint (static conv patch embed, causal)."""
|
| 201 |
+
|
| 202 |
+
def __init__(self) -> None:
|
| 203 |
+
super().__init__()
|
| 204 |
+
if CHANNEL_SIZE % PATCH_SIZE != 0:
|
| 205 |
+
raise ValueError("CHANNEL_SIZE must be divisible by PATCH_SIZE")
|
| 206 |
+
self.patch_embed = PatchEmbedding()
|
| 207 |
+
self.blocks = nn.ModuleList([Block() for _ in range(DEPTH)])
|
| 208 |
+
self.norm = nn.LayerNorm(DIM, eps=NORM_EPS)
|
| 209 |
+
|
| 210 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 211 |
+
"""Return final-layer patch tokens (post-final-norm)."""
|
| 212 |
+
z = self.patch_embed(x) # [B, T, D]
|
| 213 |
+
for block in self.blocks:
|
| 214 |
+
z = block(z) # [B, T, D]
|
| 215 |
+
return self.norm(z) # [B, T, D]
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
@torch.inference_mode()
|
| 219 |
+
def encode_lenepa(*, model: LeNEPAEncoder, x_waveform: torch.Tensor) -> LeNEPAEncoderOutput:
|
| 220 |
+
"""Encode a batch of waveforms.
|
| 221 |
+
|
| 222 |
+
Args:
|
| 223 |
+
model: LeNEPA encoder (on the same device as x_waveform).
|
| 224 |
+
x_waveform: [B, 1, 5000] float32.
|
| 225 |
+
"""
|
| 226 |
+
if x_waveform.dtype is not torch.float32:
|
| 227 |
+
raise ValueError(f"x_waveform must be float32, got {x_waveform.dtype}")
|
| 228 |
+
if x_waveform.dim() != 3:
|
| 229 |
+
raise ValueError(f"x_waveform must be [B, C, L], got {tuple(x_waveform.shape)}")
|
| 230 |
+
B, C, L = x_waveform.shape
|
| 231 |
+
if C != NUM_CHANNELS or L != CHANNEL_SIZE:
|
| 232 |
+
raise ValueError(
|
| 233 |
+
"Input must match the published contract: "
|
| 234 |
+
f"expected [B, {NUM_CHANNELS}, {CHANNEL_SIZE}], got {tuple(x_waveform.shape)}"
|
| 235 |
+
)
|
| 236 |
+
model_device = next(model.parameters()).device
|
| 237 |
+
if x_waveform.device != model_device:
|
| 238 |
+
raise ValueError(
|
| 239 |
+
"x_waveform must be on the same device as the model. "
|
| 240 |
+
f"x_waveform.device={x_waveform.device} model.device={model_device}"
|
| 241 |
+
)
|
| 242 |
+
|
| 243 |
+
patch_tokens = model(x_waveform) # [B, T, D]
|
| 244 |
+
embedding = patch_tokens.mean(dim=1) # [B, D]
|
| 245 |
+
return LeNEPAEncoderOutput(patch_tokens=patch_tokens, embedding=embedding)
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
def load_lenepa_encoder(*, weights_path: Path, device: torch.device) -> LeNEPAEncoder:
|
| 249 |
+
"""Load the published encoder weights from a safetensors file."""
|
| 250 |
+
if not weights_path.is_file():
|
| 251 |
+
raise ValueError(f"weights_path does not exist: {str(weights_path)!r}")
|
| 252 |
+
state = safetensors_load(str(weights_path))
|
| 253 |
+
model = LeNEPAEncoder()
|
| 254 |
+
model.load_state_dict(state, strict=True)
|
| 255 |
+
model.eval()
|
| 256 |
+
model.requires_grad_(False)
|
| 257 |
+
return model.to(device)
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
def _smoke_test() -> None:
|
| 261 |
+
"""Small end-to-end smoke test (random input, prints output shapes)."""
|
| 262 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 263 |
+
here = Path(__file__).resolve().parent
|
| 264 |
+
model = load_lenepa_encoder(weights_path=here / "lenepa_encoder.safetensors", device=device)
|
| 265 |
+
x = torch.randn(2, 1, 5000, device=device, dtype=torch.float32) # [B=2, C=1, L=5000]
|
| 266 |
+
out = encode_lenepa(model=model, x_waveform=x)
|
| 267 |
+
print("patch_tokens", tuple(out.patch_tokens.shape))
|
| 268 |
+
print("embedding", tuple(out.embedding.shape))
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
if __name__ == "__main__":
|
| 272 |
+
_smoke_test()
|
lenepa_encoder.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:99d6bd0388e2376e01929e3d1524b0fb94c40a4c00f65f082b20fc7a43f6a9dd
|
| 3 |
+
size 14274312
|
lenepa_encoder_config.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bias": true,
|
| 3 |
+
"channel_size": 5000,
|
| 4 |
+
"channels": [
|
| 5 |
+
"I"
|
| 6 |
+
],
|
| 7 |
+
"depth": 8,
|
| 8 |
+
"dim": 192,
|
| 9 |
+
"format": "lenepa_encoder",
|
| 10 |
+
"format_version": 1,
|
| 11 |
+
"is_causal": true,
|
| 12 |
+
"mlp_ratio": 4.0,
|
| 13 |
+
"norm_eps": 1e-06,
|
| 14 |
+
"num_heads": 4,
|
| 15 |
+
"num_patches": 200,
|
| 16 |
+
"patch_size": 25,
|
| 17 |
+
"qk_norm_eps": 1e-06,
|
| 18 |
+
"qkv_bias": true,
|
| 19 |
+
"rope_base": 10000,
|
| 20 |
+
"sampling_frequency": 500,
|
| 21 |
+
"use_qk_norm": true,
|
| 22 |
+
"use_rope": true,
|
| 23 |
+
"use_swiglu": true
|
| 24 |
+
}
|
provenance.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"checkpoint_step": 20000,
|
| 3 |
+
"exported_at_utc": "2026-03-04T16:00:59.982056+00:00",
|
| 4 |
+
"git_commit": "7f1960a2581535b2356f757f378c98dce349b189",
|
| 5 |
+
"notes": "encoder-only export (proj.* and sigreg.* removed)",
|
| 6 |
+
"pretrain_wandb": {
|
| 7 |
+
"entity": "langotime",
|
| 8 |
+
"project": "ECG-LeJEPA",
|
| 9 |
+
"run_id": "vjtzford",
|
| 10 |
+
"run_name": "AIONO_LENEPA_SIGREGT20_L0-8_PD0_PROJ_BAL_s0",
|
| 11 |
+
"url": "https://wandb.ai/langotime/ECG-LeJEPA/runs/vjtzford"
|
| 12 |
+
},
|
| 13 |
+
"source_checkpoint_path": "pretrain/AIONO_LENEPA_SIGREGT20_L0-8_PD0_PROJ_BAL_s0/chkpt_20000.pt"
|
| 14 |
+
}
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
safetensors
|
| 3 |
+
|