relflow 0.0.1__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.
- relflow-0.0.1/LICENSE +178 -0
- relflow-0.0.1/NOTICE +8 -0
- relflow-0.0.1/PKG-INFO +445 -0
- relflow-0.0.1/README.md +410 -0
- relflow-0.0.1/pyproject.toml +93 -0
- relflow-0.0.1/setup.cfg +4 -0
- relflow-0.0.1/src/json2vec/__init__.py +176 -0
- relflow-0.0.1/src/json2vec/architecture/__init__.py +0 -0
- relflow-0.0.1/src/json2vec/architecture/attention.py +75 -0
- relflow-0.0.1/src/json2vec/architecture/checkpoint.py +111 -0
- relflow-0.0.1/src/json2vec/architecture/contracts.py +484 -0
- relflow-0.0.1/src/json2vec/architecture/encoder.py +105 -0
- relflow-0.0.1/src/json2vec/architecture/graph.py +113 -0
- relflow-0.0.1/src/json2vec/architecture/mutations.py +446 -0
- relflow-0.0.1/src/json2vec/architecture/node.py +39 -0
- relflow-0.0.1/src/json2vec/architecture/pool.py +77 -0
- relflow-0.0.1/src/json2vec/architecture/root.py +533 -0
- relflow-0.0.1/src/json2vec/architecture/rotary.py +40 -0
- relflow-0.0.1/src/json2vec/architecture/runtime.py +274 -0
- relflow-0.0.1/src/json2vec/data/__init__.py +33 -0
- relflow-0.0.1/src/json2vec/data/datasets/__init__.py +41 -0
- relflow-0.0.1/src/json2vec/data/datasets/base.py +127 -0
- relflow-0.0.1/src/json2vec/data/datasets/custom.py +323 -0
- relflow-0.0.1/src/json2vec/data/datasets/polars.py +382 -0
- relflow-0.0.1/src/json2vec/data/datasets/streaming.py +530 -0
- relflow-0.0.1/src/json2vec/data/iterables.py +380 -0
- relflow-0.0.1/src/json2vec/data/nested.py +237 -0
- relflow-0.0.1/src/json2vec/data/processors.py +398 -0
- relflow-0.0.1/src/json2vec/distributed.py +67 -0
- relflow-0.0.1/src/json2vec/helpers/__init__.py +8 -0
- relflow-0.0.1/src/json2vec/helpers/hyperparameters.py +0 -0
- relflow-0.0.1/src/json2vec/helpers/inference.py +630 -0
- relflow-0.0.1/src/json2vec/helpers/optimizers.py +78 -0
- relflow-0.0.1/src/json2vec/helpers/trainer.py +0 -0
- relflow-0.0.1/src/json2vec/inference/__init__.py +59 -0
- relflow-0.0.1/src/json2vec/inference/callback.py +109 -0
- relflow-0.0.1/src/json2vec/inference/deployment.py +772 -0
- relflow-0.0.1/src/json2vec/logging/__init__.py +4 -0
- relflow-0.0.1/src/json2vec/logging/config.py +23 -0
- relflow-0.0.1/src/json2vec/logging/epoch.py +42 -0
- relflow-0.0.1/src/json2vec/logging/throughput.py +73 -0
- relflow-0.0.1/src/json2vec/structs/__init__.py +0 -0
- relflow-0.0.1/src/json2vec/structs/enums.py +138 -0
- relflow-0.0.1/src/json2vec/structs/experiment.py +632 -0
- relflow-0.0.1/src/json2vec/structs/packages.py +116 -0
- relflow-0.0.1/src/json2vec/structs/selectors.py +236 -0
- relflow-0.0.1/src/json2vec/structs/structure.py +247 -0
- relflow-0.0.1/src/json2vec/structs/tree.py +385 -0
- relflow-0.0.1/src/json2vec/tensorfields/__init__.py +25 -0
- relflow-0.0.1/src/json2vec/tensorfields/base.py +577 -0
- relflow-0.0.1/src/json2vec/tensorfields/extensions/__init__.py +19 -0
- relflow-0.0.1/src/json2vec/tensorfields/extensions/boolean.py +272 -0
- relflow-0.0.1/src/json2vec/tensorfields/extensions/category.py +473 -0
- relflow-0.0.1/src/json2vec/tensorfields/extensions/dateparts.py +475 -0
- relflow-0.0.1/src/json2vec/tensorfields/extensions/entity.py +347 -0
- relflow-0.0.1/src/json2vec/tensorfields/extensions/number.py +419 -0
- relflow-0.0.1/src/json2vec/tensorfields/extensions/set.py +401 -0
- relflow-0.0.1/src/json2vec/tensorfields/extensions/text.py +471 -0
- relflow-0.0.1/src/json2vec/tensorfields/extensions/vector.py +330 -0
- relflow-0.0.1/src/json2vec/tensorfields/shared/__init__.py +80 -0
- relflow-0.0.1/src/json2vec/tensorfields/shared/counter.py +189 -0
- relflow-0.0.1/src/json2vec/tensorfields/shared/vocabulary.py +449 -0
- relflow-0.0.1/src/json2vec/tensorfields/spec.py +8 -0
- relflow-0.0.1/src/relflow.egg-info/PKG-INFO +445 -0
- relflow-0.0.1/src/relflow.egg-info/SOURCES.txt +70 -0
- relflow-0.0.1/src/relflow.egg-info/dependency_links.txt +1 -0
- relflow-0.0.1/src/relflow.egg-info/requires.txt +26 -0
- relflow-0.0.1/src/relflow.egg-info/top_level.txt +1 -0
- relflow-0.0.1/tests/test_callbacks.py +43 -0
- relflow-0.0.1/tests/test_optimizers.py +78 -0
- relflow-0.0.1/tests/test_public_api.py +43 -0
- relflow-0.0.1/tests/test_schema_inference.py +326 -0
relflow-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://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,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 Grantham Taylor
|
relflow-0.0.1/NOTICE
ADDED
relflow-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: relflow
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Schema-first PyTorch models for hierarchical / nested / sequence data structures
|
|
5
|
+
Author: Grantham Taylor
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Requires-Python: >=3.12
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
License-File: NOTICE
|
|
11
|
+
Requires-Dist: beartype>=0.21.0
|
|
12
|
+
Requires-Dist: pluggy>=1.6.0
|
|
13
|
+
Requires-Dist: rich>=14.0.0
|
|
14
|
+
Requires-Dist: pydantic>=2.11.7
|
|
15
|
+
Requires-Dist: jmespath>=1.0.1
|
|
16
|
+
Requires-Dist: loguru>=0.7.3
|
|
17
|
+
Requires-Dist: anytree>=2.13.0
|
|
18
|
+
Requires-Dist: pyarrow>=21.0.0
|
|
19
|
+
Requires-Dist: polars>=1.35.2
|
|
20
|
+
Requires-Dist: numpy>=2.2.6
|
|
21
|
+
Requires-Dist: lightning>=2.6.4
|
|
22
|
+
Requires-Dist: tensordict>=0.10.0
|
|
23
|
+
Requires-Dist: torch>=2.7.1
|
|
24
|
+
Requires-Dist: torchmetrics>=1.9.0
|
|
25
|
+
Provides-Extra: serving
|
|
26
|
+
Requires-Dist: fastapi>=0.124.0; extra == "serving"
|
|
27
|
+
Requires-Dist: orjson>=3.10.0; extra == "serving"
|
|
28
|
+
Requires-Dist: pydantic-settings>=2.10.1; extra == "serving"
|
|
29
|
+
Requires-Dist: uvicorn>=0.38.0; extra == "serving"
|
|
30
|
+
Provides-Extra: text
|
|
31
|
+
Requires-Dist: transformers>=4.55.0; extra == "text"
|
|
32
|
+
Provides-Extra: docs
|
|
33
|
+
Requires-Dist: marimo>=0.23.8; extra == "docs"
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
|
|
36
|
+
<h1 align="center"><code>json2vec</code></h1>
|
|
37
|
+
|
|
38
|
+
<p align="center">
|
|
39
|
+
<img alt="Python 3.12+" src="https://img.shields.io/badge/python-3.12%2B-3776AB?logo=python&logoColor=white" />
|
|
40
|
+
<a href="LICENSE"><img alt="Apache-2.0 license" src="https://img.shields.io/badge/license-Apache--2.0-2E8B57" /></a>
|
|
41
|
+
<a href="https://json2vec.github.io/json2vec/"><img alt="Documentation" src="https://img.shields.io/badge/docs-Quarto-39729E?logo=quarto&logoColor=white" /></a>
|
|
42
|
+
<!-- discord-invite:start -->
|
|
43
|
+
<a href="https://discord.gg/DVyZUkvTFA"><img alt="Discord channel invite" src="https://img.shields.io/badge/discord-join%20the%20channel-5865F2?logo=discord&logoColor=white" /></a>
|
|
44
|
+
<!-- discord-invite:end -->
|
|
45
|
+
</p>
|
|
46
|
+
|
|
47
|
+
`json2vec` builds PyTorch/Lightning models directly from JSON-like schemas.
|
|
48
|
+
It is meant for predictive modeling on records that are not naturally flat:
|
|
49
|
+
customers with transactions, orders with line items, sessions with clickstream
|
|
50
|
+
events, devices recurring across histories, and mixed datatypes at every level.
|
|
51
|
+
|
|
52
|
+
Most ML pipelines flatten that shape first, then train on one fixed feature
|
|
53
|
+
row. `json2vec` takes the opposite path: describe the structured record, and
|
|
54
|
+
the schema becomes the model.
|
|
55
|
+
|
|
56
|
+
## Core Idea
|
|
57
|
+
|
|
58
|
+
A `json2vec` schema is both a data contract and an architecture blueprint.
|
|
59
|
+
|
|
60
|
+
- Leaf fields such as `Number`, `Category`, `Set`, `Entity`, `Text`, and
|
|
61
|
+
`Vector` become datatype-specific tensorfields.
|
|
62
|
+
- `Branch` nodes define shared contexts for child fields, with optional local
|
|
63
|
+
attention and pooling before the representation flows upward.
|
|
64
|
+
- Targets, masks, pruning, and embeddings are configured on the same schema
|
|
65
|
+
tree.
|
|
66
|
+
- Prediction output is keyed by schema address, so decoded values and
|
|
67
|
+
embeddings remain attached to the part of the record that produced them.
|
|
68
|
+
|
|
69
|
+
That gives one model surface for supervised prediction, masked reconstruction,
|
|
70
|
+
unsupervised embedding workflows, schema mutation, field importance, batch
|
|
71
|
+
inference, and serving.
|
|
72
|
+
|
|
73
|
+
## A Model From A Nested Record
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
import json2vec as jv
|
|
77
|
+
|
|
78
|
+
model = jv.Model(
|
|
79
|
+
name="order",
|
|
80
|
+
d_model=64,
|
|
81
|
+
n_layers=2,
|
|
82
|
+
n_heads=4,
|
|
83
|
+
embed=True,
|
|
84
|
+
customer_tier=jv.Category(size=16),
|
|
85
|
+
line_items=jv.Branch(
|
|
86
|
+
length=32,
|
|
87
|
+
embed=True,
|
|
88
|
+
sku=jv.Category(size=2048),
|
|
89
|
+
quantity=jv.Number,
|
|
90
|
+
price=jv.Number,
|
|
91
|
+
),
|
|
92
|
+
returned=jv.Category(target=True, size=2),
|
|
93
|
+
)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
This model reads records shaped like:
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
{
|
|
100
|
+
"customer_tier": "gold",
|
|
101
|
+
"line_items": [
|
|
102
|
+
{"sku": "A12", "quantity": 2, "price": 19.99},
|
|
103
|
+
{"sku": "B07", "quantity": 1, "price": 45.50},
|
|
104
|
+
],
|
|
105
|
+
"returned": "false",
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
The `line_items` branch has its own repeated context, `returned` is withheld
|
|
110
|
+
from input and decoded as a supervised target, and `embed=True` asks prediction
|
|
111
|
+
to emit embeddings at configured addresses.
|
|
112
|
+
|
|
113
|
+
## Train With Lightning
|
|
114
|
+
|
|
115
|
+
`jv.Model` is a LightningModule. `jv.PolarsDataModule` and
|
|
116
|
+
`jv.StreamingDataModule` are LightningDataModule implementations. The schema
|
|
117
|
+
defines the model tree, typed losses, prediction outputs, and embeddings;
|
|
118
|
+
Lightning runs `fit`, `validate`, `test`, and `predict`.
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
import lightning.pytorch as lit
|
|
122
|
+
import polars as pl
|
|
123
|
+
import torch
|
|
124
|
+
|
|
125
|
+
import json2vec as jv
|
|
126
|
+
|
|
127
|
+
records = pl.read_ndjson("docs/data/iris.jsonl").head(36).with_row_index()
|
|
128
|
+
train_records = records.filter((pl.col("index") % 3) != 2).drop("index")
|
|
129
|
+
validate_records = records.filter((pl.col("index") % 3) == 2).drop("index")
|
|
130
|
+
|
|
131
|
+
model = jv.Model(
|
|
132
|
+
d_model=16,
|
|
133
|
+
n_layers=1,
|
|
134
|
+
n_heads=4,
|
|
135
|
+
batch_size=8,
|
|
136
|
+
embed=True,
|
|
137
|
+
optimizer=lambda module: torch.optim.AdamW(module.parameters(), lr=1e-2),
|
|
138
|
+
sepal_length=jv.Number,
|
|
139
|
+
petal_length=jv.Number,
|
|
140
|
+
species=jv.Category(target=True, size=3, topk=[2]),
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
datamodule = jv.PolarsDataModule(
|
|
144
|
+
model=model,
|
|
145
|
+
train=train_records,
|
|
146
|
+
validate=validate_records,
|
|
147
|
+
num_workers=0,
|
|
148
|
+
persistent_workers=False,
|
|
149
|
+
pin_memory=False,
|
|
150
|
+
observation_buffer_size=32,
|
|
151
|
+
sample_rate=1.0,
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
trainer = lit.Trainer(
|
|
155
|
+
accelerator="cpu",
|
|
156
|
+
max_epochs=1,
|
|
157
|
+
logger=False,
|
|
158
|
+
enable_progress_bar=False,
|
|
159
|
+
enable_model_summary=False,
|
|
160
|
+
enable_checkpointing=False,
|
|
161
|
+
limit_train_batches=1,
|
|
162
|
+
limit_val_batches=1,
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
trainer.fit(model=model, datamodule=datamodule)
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
This tiny deterministic split is only a wiring example. Use a representative,
|
|
169
|
+
leakage-safe validation design before interpreting the metrics as model quality.
|
|
170
|
+
|
|
171
|
+
For larger jobs, the same model can run through normal Lightning callbacks,
|
|
172
|
+
checkpointing, precision settings, device placement, and distributed
|
|
173
|
+
strategies. See
|
|
174
|
+
[Training With Lightning](https://json2vec.github.io/json2vec/guides/lightning.html).
|
|
175
|
+
|
|
176
|
+
## Predict And Embed
|
|
177
|
+
|
|
178
|
+
For small interactive batches, call `model.predict(...)` with raw dictionaries.
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
requests = validate_records.drop("species").head(3).to_dicts()
|
|
182
|
+
predictions = model.predict(requests)
|
|
183
|
+
|
|
184
|
+
species = predictions[jv.Address("record", "species")]
|
|
185
|
+
record = predictions[jv.Address("record")]
|
|
186
|
+
|
|
187
|
+
print(species["content"]["value"])
|
|
188
|
+
print(species["content"]["probability"])
|
|
189
|
+
print(record["embedding"])
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
For larger offline jobs, configure a `predict` split on a data module and attach
|
|
193
|
+
`jv.Writer` to Lightning's prediction loop.
|
|
194
|
+
|
|
195
|
+
```python
|
|
196
|
+
writer = jv.Writer("predictions")
|
|
197
|
+
|
|
198
|
+
trainer = lit.Trainer(
|
|
199
|
+
accelerator="cpu",
|
|
200
|
+
callbacks=[writer],
|
|
201
|
+
logger=False,
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
predict_datamodule = jv.PolarsDataModule(
|
|
205
|
+
model=model,
|
|
206
|
+
predict=validate_records.drop("species"),
|
|
207
|
+
num_workers=0,
|
|
208
|
+
persistent_workers=False,
|
|
209
|
+
pin_memory=False,
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
trainer.predict(
|
|
213
|
+
model=model,
|
|
214
|
+
datamodule=predict_datamodule,
|
|
215
|
+
return_predictions=False,
|
|
216
|
+
)
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
`Writer` creates rank-partitioned Parquet files such as
|
|
220
|
+
`predictions/rank-0.parquet`. Use a postprocessor when downstream systems need
|
|
221
|
+
flat columns, renamed addresses, redacted payloads, or fewer fields. See
|
|
222
|
+
[Batch Inference](https://json2vec.github.io/json2vec/guides/batch-inference.html)
|
|
223
|
+
and [Postprocessors](https://json2vec.github.io/json2vec/guides/postprocessors.html).
|
|
224
|
+
|
|
225
|
+
## Learning Modes
|
|
226
|
+
|
|
227
|
+
`json2vec` does not maintain separate supervised and self-supervised code
|
|
228
|
+
paths. Supervised learning is the special case where a target field is hidden
|
|
229
|
+
from the input 100% of the time and decoded from the remaining context.
|
|
230
|
+
|
|
231
|
+
| Setting | What the model sees | What prediction can emit |
|
|
232
|
+
| --- | --- | --- |
|
|
233
|
+
| plain input | value is visible | no decoded output unless otherwise configured |
|
|
234
|
+
| `target=True` | value is hidden | decoded supervised output |
|
|
235
|
+
| `p_mask` | sampled configured leaf positions are hidden in train, validation, and test | decoded reconstruction |
|
|
236
|
+
| `p_prune` | whole leaf instances are hidden in train, validation, and test | decoded reconstruction |
|
|
237
|
+
| `embed=True` | does not hide the value | embedding at that address |
|
|
238
|
+
|
|
239
|
+
`target=True` is exact shorthand for `p_prune=1.0`. The current `p_mask`
|
|
240
|
+
implementation samples configured positions, including null and padded
|
|
241
|
+
positions, at rates lower than `1.0`; see
|
|
242
|
+
[Dynamic Masking](https://json2vec.github.io/json2vec/core-concepts/dynamic-masking.html)
|
|
243
|
+
for exact selection behavior. Use `embed=True` when you want a representation
|
|
244
|
+
returned from prediction.
|
|
245
|
+
|
|
246
|
+
## Data Modules
|
|
247
|
+
|
|
248
|
+
Data modules load raw records, apply optional preprocessing, batch
|
|
249
|
+
observations, tensorize values from the model schema, apply configured masking
|
|
250
|
+
and target pruning in non-predict loops, and hand encoded batches to Lightning.
|
|
251
|
+
|
|
252
|
+
Choose the data module by where the records live:
|
|
253
|
+
|
|
254
|
+
| Use case | Module |
|
|
255
|
+
| --- | --- |
|
|
256
|
+
| Tutorials, tests, notebooks, in-memory Polars frames | `PolarsDataModule` |
|
|
257
|
+
| Many local files | `StreamingDataModule` |
|
|
258
|
+
| S3-backed datasets | `StreamingDataModule` |
|
|
259
|
+
| Distributed training or prediction over large inputs | `StreamingDataModule` |
|
|
260
|
+
|
|
261
|
+
`StreamingDataModule` supports local `ndjson`, `parquet`, `feather`, `csv`,
|
|
262
|
+
`orc`, and `json` inputs. S3 roots use the PyArrow-backed formats—`parquet`,
|
|
263
|
+
`feather`, `csv`, `orc`, and `json`; `ndjson` is local-only. Avro is not
|
|
264
|
+
supported by the current reader. Split arguments are compiled regular
|
|
265
|
+
expressions matched against discovered file paths.
|
|
266
|
+
|
|
267
|
+
See [Data Modules](https://json2vec.github.io/json2vec/guides/data-modules.html)
|
|
268
|
+
for split configuration, sharding, sampling, buffers, and preprocessors.
|
|
269
|
+
|
|
270
|
+
## What Makes This Different
|
|
271
|
+
|
|
272
|
+
- **Hierarchical context encoding:** child records interact locally before
|
|
273
|
+
their representation flows upward.
|
|
274
|
+
- **Typed datatype architecture:** each built-in field owns validation,
|
|
275
|
+
tensorization, missing-state handling, masking, decoding, loss, metrics, and
|
|
276
|
+
output writing. The external registration surface is experimental and
|
|
277
|
+
same-process only in the current release.
|
|
278
|
+
- **Unified training roles:** `target=True`, `p_prune`, and `p_mask` all use the
|
|
279
|
+
same reconstruction path.
|
|
280
|
+
- **Embedding trees:** embeddings can come from the root, branches, or selected
|
|
281
|
+
leaves.
|
|
282
|
+
- **Schema evolution:** fields can be added, removed, updated, reset, or
|
|
283
|
+
temporarily overridden after construction.
|
|
284
|
+
- **Production missingness semantics:** `valued`, `null`, `padded`, `masked`,
|
|
285
|
+
and reserved `other` are distinct tensorfield states.
|
|
286
|
+
- **Training-serving parity:** queries, preprocessors, tensorization, model
|
|
287
|
+
execution, prediction writing, and postprocessors stay on the same configured
|
|
288
|
+
path.
|
|
289
|
+
|
|
290
|
+
## Where It Fits
|
|
291
|
+
|
|
292
|
+
Use `json2vec` when relationships inside the record matter: account histories,
|
|
293
|
+
fraud or risk snapshots, order and fulfillment events, flight itineraries,
|
|
294
|
+
operations telemetry, user sessions, repeated measurements, or mixed datatype
|
|
295
|
+
objects where flattening would discard useful structure.
|
|
296
|
+
|
|
297
|
+
Use a simpler tabular model when flattening loses no meaningful context. The
|
|
298
|
+
point is not to replace every table. The point is to model nested business data
|
|
299
|
+
without making a feature table the only representation the model can see.
|
|
300
|
+
|
|
301
|
+
## What It Does Not Do
|
|
302
|
+
|
|
303
|
+
`json2vec` stops at the representation and typed prediction layer. It is not a
|
|
304
|
+
feature store, governance system, rule engine, authorization layer,
|
|
305
|
+
decision-capture system, or audit platform. Those systems can consume
|
|
306
|
+
`json2vec` embeddings and predictions, but their policies and operational
|
|
307
|
+
controls remain separate concerns.
|
|
308
|
+
|
|
309
|
+
The open-source layer is the reusable encoder and runtime infrastructure. It
|
|
310
|
+
does not require users to publish data, schemas, checkpoints, or model
|
|
311
|
+
parameters.
|
|
312
|
+
|
|
313
|
+
## Install
|
|
314
|
+
|
|
315
|
+
JSON2Vec requires Python `>=3.12`. The currently documented user installation
|
|
316
|
+
is directly from the GitHub repository:
|
|
317
|
+
|
|
318
|
+
```bash
|
|
319
|
+
python -m pip install "json2vec @ git+https://github.com/json2vec/json2vec.git"
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
This follows the repository's default branch. Pin a tag or commit in the Git
|
|
323
|
+
URL for reproducible environments; the published documentation currently
|
|
324
|
+
tracks `main` and does not retain versioned snapshots.
|
|
325
|
+
|
|
326
|
+
Install optional functionality from the same source:
|
|
327
|
+
|
|
328
|
+
```bash
|
|
329
|
+
python -m pip install "json2vec[text] @ git+https://github.com/json2vec/json2vec.git"
|
|
330
|
+
python -m pip install "json2vec[serving] @ git+https://github.com/json2vec/json2vec.git"
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
Verify the environment:
|
|
334
|
+
|
|
335
|
+
```bash
|
|
336
|
+
python -c "import importlib.metadata; import json2vec; print(importlib.metadata.version('json2vec'))"
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
For a contributor checkout, use the locked development environment instead:
|
|
340
|
+
|
|
341
|
+
```bash
|
|
342
|
+
uv sync
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
Contributor extras:
|
|
346
|
+
|
|
347
|
+
```bash
|
|
348
|
+
uv sync --extra text
|
|
349
|
+
uv sync --extra serving
|
|
350
|
+
uv sync --extra docs
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
The `text` extra installs Hugging Face `transformers`. The `serving` extra
|
|
354
|
+
installs FastAPI-backed deployment dependencies. The `docs` extra installs the
|
|
355
|
+
Python packages used by the Quarto docs.
|
|
356
|
+
|
|
357
|
+
## Documentation Map
|
|
358
|
+
|
|
359
|
+
Start with:
|
|
360
|
+
|
|
361
|
+
- [Getting Started](https://json2vec.github.io/json2vec/getting-started.html)
|
|
362
|
+
- [AI / Expert Quickstart](https://json2vec.github.io/json2vec/ai-quickstart.html)
|
|
363
|
+
- [Model Tree](https://json2vec.github.io/json2vec/core-concepts/model-tree.html)
|
|
364
|
+
- [Data Flow](https://json2vec.github.io/json2vec/core-concepts/data-flow.html)
|
|
365
|
+
- [Binding Data](https://json2vec.github.io/json2vec/core-concepts/binding-data.html)
|
|
366
|
+
- [Query Paths](https://json2vec.github.io/json2vec/core-concepts/querypaths.html)
|
|
367
|
+
- [Built-In Data Types](https://json2vec.github.io/json2vec/core-concepts/data-types.html)
|
|
368
|
+
- [Learning Modes & Embeddings](https://json2vec.github.io/json2vec/core-concepts/embeddings.html)
|
|
369
|
+
- [Training With Lightning](https://json2vec.github.io/json2vec/guides/lightning.html)
|
|
370
|
+
- [Data Modules](https://json2vec.github.io/json2vec/guides/data-modules.html)
|
|
371
|
+
- [Evaluation And Metrics](https://json2vec.github.io/json2vec/guides/evaluation.html)
|
|
372
|
+
- [Model Lifecycle](https://json2vec.github.io/json2vec/guides/model-lifecycle.html)
|
|
373
|
+
- [Batch Inference](https://json2vec.github.io/json2vec/guides/batch-inference.html)
|
|
374
|
+
- [Serving](https://json2vec.github.io/json2vec/guides/serving.html)
|
|
375
|
+
|
|
376
|
+
Tutorials and guides:
|
|
377
|
+
|
|
378
|
+
- [Postprocessors](https://json2vec.github.io/json2vec/guides/postprocessors.html)
|
|
379
|
+
- [Field Importance](https://json2vec.github.io/json2vec/guides/field-importance.html)
|
|
380
|
+
- [Field Stacking](https://json2vec.github.io/json2vec/guides/field-stacking.html)
|
|
381
|
+
- [Model Configuration](https://json2vec.github.io/json2vec/guides/model-configuration.html)
|
|
382
|
+
- [Performance And Scaling](https://json2vec.github.io/json2vec/guides/performance.html)
|
|
383
|
+
- [Temporal Validation](https://json2vec.github.io/json2vec/guides/temporal-validation.html)
|
|
384
|
+
- [Schema Mutation](https://json2vec.github.io/json2vec/guides/schema-mutation.html)
|
|
385
|
+
- [Troubleshooting](https://json2vec.github.io/json2vec/guides/troubleshooting.html)
|
|
386
|
+
- [Experimental Custom Tensorfields](https://json2vec.github.io/json2vec/guides/custom-tensorfields.html)
|
|
387
|
+
- [Public API Map](https://json2vec.github.io/json2vec/reference/public-api.html)
|
|
388
|
+
- [Branch](https://json2vec.github.io/json2vec/data-types/branch.html)
|
|
389
|
+
- [Number](https://json2vec.github.io/json2vec/data-types/number.html)
|
|
390
|
+
- [Boolean](https://json2vec.github.io/json2vec/data-types/boolean.html)
|
|
391
|
+
- [Category](https://json2vec.github.io/json2vec/data-types/category.html)
|
|
392
|
+
- [Set](https://json2vec.github.io/json2vec/data-types/set.html)
|
|
393
|
+
- [Entity](https://json2vec.github.io/json2vec/data-types/entity.html)
|
|
394
|
+
- [DateParts](https://json2vec.github.io/json2vec/data-types/dateparts.html)
|
|
395
|
+
- [Vector](https://json2vec.github.io/json2vec/data-types/vector.html)
|
|
396
|
+
- [Text](https://json2vec.github.io/json2vec/data-types/text.html)
|
|
397
|
+
- [Reproducible Iris Case Study](https://json2vec.github.io/json2vec/case-studies/iris-reproducible.html)
|
|
398
|
+
- [Device Tenure Case Study](https://json2vec.github.io/json2vec/case-studies/device-tenure.html)
|
|
399
|
+
|
|
400
|
+
Build the docs locally with:
|
|
401
|
+
|
|
402
|
+
```bash
|
|
403
|
+
make render
|
|
404
|
+
uv run pytest tests/examples/test_e2e_examples.py
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
## Repository Layout
|
|
408
|
+
|
|
409
|
+
- `src/json2vec/architecture`: model assembly, attention, pooling, and routing
|
|
410
|
+
- `src/json2vec/data`: dataset fetch/read/process/batch/encode pipeline and preprocessor exports
|
|
411
|
+
- `src/json2vec/inference`: serving and prediction callbacks
|
|
412
|
+
- `src/json2vec/logging`: runtime logging callbacks
|
|
413
|
+
- `src/json2vec/structs`: pydantic config models, enums, and tree nodes
|
|
414
|
+
- `src/json2vec/tensorfields`: tensorfield plugin system and built-in fields
|
|
415
|
+
- `tests/`: package test suite
|
|
416
|
+
- `docs/`: Quarto project, pages, guides, stylesheets, and sample data
|
|
417
|
+
|
|
418
|
+
## Development
|
|
419
|
+
|
|
420
|
+
Run tests:
|
|
421
|
+
|
|
422
|
+
```bash
|
|
423
|
+
uv run pytest
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
Run type and lint checks:
|
|
427
|
+
|
|
428
|
+
```bash
|
|
429
|
+
uv run ty check src/json2vec --output-format concise
|
|
430
|
+
uv run ruff check
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
## Community
|
|
434
|
+
|
|
435
|
+
Join the [`json2vec` Discord](https://discord.gg/DVyZUkvTFA) for questions,
|
|
436
|
+
design discussion, and release notes.
|
|
437
|
+
|
|
438
|
+
## License
|
|
439
|
+
|
|
440
|
+
Licensed under the Apache License, Version 2.0. See `LICENSE` and `NOTICE`.
|
|
441
|
+
|
|
442
|
+
## References
|
|
443
|
+
|
|
444
|
+
- `BIBLIOGRAPHY.md`
|
|
445
|
+
- `CITATION.bib`
|