subsumer 0.7.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. subsumer-0.7.0/Cargo.toml +68 -0
  2. subsumer-0.7.0/LICENSE-APACHE +203 -0
  3. subsumer-0.7.0/LICENSE-MIT +22 -0
  4. subsumer-0.7.0/PKG-INFO +9 -0
  5. subsumer-0.7.0/README.md +261 -0
  6. subsumer-0.7.0/docs/katex-header.html +82 -0
  7. subsumer-0.7.0/examples/box_training.rs +391 -0
  8. subsumer-0.7.0/examples/cone_training.rs +267 -0
  9. subsumer-0.7.0/examples/containment_hierarchy.rs +142 -0
  10. subsumer-0.7.0/examples/dataset_training.rs +220 -0
  11. subsumer-0.7.0/examples/el_training.rs +127 -0
  12. subsumer-0.7.0/examples/fuzzy_query.rs +169 -0
  13. subsumer-0.7.0/examples/gumbel_box_exploration.rs +194 -0
  14. subsumer-0.7.0/examples/hyperbolic_demo.rs +228 -0
  15. subsumer-0.7.0/examples/imagenet_hierarchy.rs +753 -0
  16. subsumer-0.7.0/examples/octagon_demo.rs +195 -0
  17. subsumer-0.7.0/examples/query2box.rs +271 -0
  18. subsumer-0.7.0/examples/save_checkpoint.rs +178 -0
  19. subsumer-0.7.0/examples/taxobell_demo.rs +209 -0
  20. subsumer-0.7.0/examples/taxobell_training.rs +167 -0
  21. subsumer-0.7.0/examples/wn18rr_training.rs +139 -0
  22. subsumer-0.7.0/pretrained/wordnet_subset.json +6938 -0
  23. subsumer-0.7.0/pyproject.toml +19 -0
  24. subsumer-0.7.0/src/box_trait.rs +425 -0
  25. subsumer-0.7.0/src/candle_backend/candle_box.rs +438 -0
  26. subsumer-0.7.0/src/candle_backend/candle_gumbel.rs +480 -0
  27. subsumer-0.7.0/src/candle_backend/distance.rs +249 -0
  28. subsumer-0.7.0/src/candle_backend/mod.rs +7 -0
  29. subsumer-0.7.0/src/cone.rs +24 -0
  30. subsumer-0.7.0/src/dataset.rs +480 -0
  31. subsumer-0.7.0/src/distance.rs +195 -0
  32. subsumer-0.7.0/src/el.rs +617 -0
  33. subsumer-0.7.0/src/el_training.rs +966 -0
  34. subsumer-0.7.0/src/fuzzy.rs +310 -0
  35. subsumer-0.7.0/src/gaussian.rs +904 -0
  36. subsumer-0.7.0/src/hyperbolic.rs +627 -0
  37. subsumer-0.7.0/src/lib.rs +286 -0
  38. subsumer-0.7.0/src/metrics.rs +342 -0
  39. subsumer-0.7.0/src/ndarray_backend/distance.rs +268 -0
  40. subsumer-0.7.0/src/ndarray_backend/mod.rs +11 -0
  41. subsumer-0.7.0/src/ndarray_backend/ndarray_box.rs +1729 -0
  42. subsumer-0.7.0/src/ndarray_backend/ndarray_cone.rs +825 -0
  43. subsumer-0.7.0/src/ndarray_backend/ndarray_gumbel.rs +1138 -0
  44. subsumer-0.7.0/src/ndarray_backend/ndarray_octagon.rs +1895 -0
  45. subsumer-0.7.0/src/octagon.rs +47 -0
  46. subsumer-0.7.0/src/optimizer.rs +273 -0
  47. subsumer-0.7.0/src/petgraph_adapter.rs +81 -0
  48. subsumer-0.7.0/src/sheaf.rs +1103 -0
  49. subsumer-0.7.0/src/taxobell.rs +1023 -0
  50. subsumer-0.7.0/src/taxobell_encoder.rs +979 -0
  51. subsumer-0.7.0/src/taxonomy.rs +533 -0
  52. subsumer-0.7.0/src/trainable.rs +703 -0
  53. subsumer-0.7.0/src/trainer/box_trainer.rs +1394 -0
  54. subsumer-0.7.0/src/trainer/cone_trainer.rs +373 -0
  55. subsumer-0.7.0/src/trainer/evaluation.rs +1462 -0
  56. subsumer-0.7.0/src/trainer/mod.rs +438 -0
  57. subsumer-0.7.0/src/trainer/negative_sampling.rs +654 -0
  58. subsumer-0.7.0/src/utils.rs +675 -0
  59. subsumer-0.7.0/subsume-python/Cargo.lock +456 -0
  60. subsumer-0.7.0/subsume-python/Cargo.toml +21 -0
  61. subsumer-0.7.0/subsume-python/README.md +22 -0
  62. subsumer-0.7.0/subsume-python/src/lib.rs +178 -0
@@ -0,0 +1,68 @@
1
+ [package]
2
+ name = "subsume"
3
+ version = "0.7.0"
4
+ edition = "2021"
5
+ rust-version = "1.75"
6
+ license = "MIT OR Apache-2.0"
7
+ authors = ["Arc <attobop@gmail.com>"]
8
+ description = "Geometric region embeddings (boxes, cones, octagons, Gaussians, hyperbolic intervals, sheaf networks) for subsumption, entailment, and logical query answering"
9
+ keywords = ["embeddings", "box-embeddings", "geometric", "subsumption", "ontology"]
10
+ categories = ["science", "algorithms"]
11
+ repository = "https://github.com/arclabs561/subsume"
12
+ documentation = "https://docs.rs/subsume"
13
+ readme = "README.md"
14
+ publish = true
15
+ include = [
16
+ "/src/**/*.rs",
17
+ "/examples/**/*.rs",
18
+ "/docs/katex-header.html",
19
+ "/Cargo.toml",
20
+ "/LICENSE-*",
21
+ "/README.md",
22
+ "/pretrained/*.json",
23
+ ]
24
+
25
+ [dependencies]
26
+ serde = { version = "1", features = ["derive"] }
27
+ thiserror = "2"
28
+ rand = { version = "0.9", optional = true }
29
+ hyperball = { version = "0.1.3", optional = true }
30
+ skel = { version = "0.1.1", optional = true }
31
+ ndarray = { version = "0.16", features = ["serde-1"], optional = true }
32
+ serde_json = { version = "1.0", optional = true }
33
+ candle-core = { version = "0.9", optional = true }
34
+ petgraph = { version = "0.7", optional = true }
35
+
36
+ [features]
37
+ default = ["ndarray-backend"]
38
+ ndarray-backend = ["dep:ndarray", "dep:serde_json", "rand"]
39
+ candle-backend = ["dep:candle-core"]
40
+ rand = ["dep:rand"]
41
+ petgraph = ["dep:petgraph"]
42
+ hyperbolic = ["dep:hyperball", "dep:skel", "dep:ndarray"]
43
+
44
+ [dev-dependencies]
45
+ criterion = { version = "0.5", features = ["html_reports"] }
46
+ proptest = "1.5"
47
+ tempfile = "3"
48
+
49
+ [[example]]
50
+ name = "hyperbolic_demo"
51
+ required-features = ["hyperbolic"]
52
+
53
+
54
+ [[example]]
55
+ name = "taxobell_training"
56
+ required-features = ["candle-backend"]
57
+
58
+ [lints.rust]
59
+ missing_docs = "warn"
60
+ unsafe_code = "warn"
61
+
62
+ [package.metadata.docs.rs]
63
+ all-features = true
64
+ rustdoc-args = ["--cfg", "docsrs", "--html-in-header", "docs/katex-header.html"]
65
+
66
+ [lints.clippy]
67
+ correctness = { level = "deny", priority = -1 }
68
+ perf = { level = "warn", priority = -1 }
@@ -0,0 +1,203 @@
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
+ 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
+ (which shall not include Communications that are clearly marked or
39
+ otherwise designated in writing by the copyright holder as "Not a Work").
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based upon (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 holder 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 format 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 2025 arclabs561
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
201
+ implied. See the License for the specific language governing
202
+ permissions and limitations under the License.
203
+
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 arclabs561
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,9 @@
1
+ Metadata-Version: 2.4
2
+ Name: subsumer
3
+ Version: 0.7.0
4
+ Classifier: Programming Language :: Rust
5
+ Classifier: Programming Language :: Python :: Implementation :: CPython
6
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
7
+ Requires-Dist: numpy>=1.20
8
+ Summary: Geometric region embeddings for knowledge graph subsumption (Python bindings for the subsume Rust crate)
9
+ Requires-Python: >=3.9
@@ -0,0 +1,261 @@
1
+ # subsume
2
+
3
+ [![crates.io](https://img.shields.io/crates/v/subsume.svg)](https://crates.io/crates/subsume)
4
+ [![Documentation](https://docs.rs/subsume/badge.svg)](https://docs.rs/subsume)
5
+ [![CI](https://github.com/arclabs561/subsume/actions/workflows/ci.yml/badge.svg)](https://github.com/arclabs561/subsume/actions/workflows/ci.yml)
6
+
7
+ Geometric region embeddings for subsumption, entailment, and logical query answering. Boxes, cones, octagons, Gaussians, hyperbolic intervals, and sheaf networks. Ndarray and Candle backends.
8
+
9
+ ![Box embedding concepts](docs/box_concepts.png)
10
+
11
+ *(a) Containment: nested boxes encode taxonomic is-a relationships. (b) Gumbel soft boundary: temperature controls membership sharpness. (c) Octagon: diagonal constraints cut corners for tighter volume bounds.*
12
+
13
+ ## What it provides
14
+
15
+ ### Geometric primitives
16
+
17
+ | Component | What it does |
18
+ |---|---|
19
+ | `Box` trait | Axis-aligned hyperrectangle: volume, containment, overlap, distance |
20
+ | `NdarrayGumbelBox` / `CandleGumbelBox` | Probabilistic boxes via Gumbel random variables (dense gradients, no flat regions; Dasgupta et al., 2020) |
21
+ | `NdarrayCone` | Angular cones in d-dimensional space: containment via aperture, closed under negation (Zhang & Wang, NeurIPS 2021) |
22
+ | `NdarrayOctagon` | Axis-aligned polytopes with diagonal constraints; tighter volume bounds than boxes (Charpenay & Schockaert, IJCAI 2024) |
23
+ | `gaussian` | Diagonal Gaussian boxes: KL divergence (asymmetric containment) and Bhattacharyya coefficient (symmetric overlap) |
24
+ | `hyperbolic` | Poincare ball embeddings and hyperbolic box intervals (via `hyperball`; requires `hyperbolic` feature) |
25
+ | `sheaf` | Sheaf diffusion primitives: stalks, restriction maps, Laplacian (Hansen & Ghrist 2019; Bodnar et al., ICLR 2022) |
26
+
27
+ ### Scoring and query answering
28
+
29
+ | Component | What it does |
30
+ |---|---|
31
+ | `distance` | Query2Box alpha-weighted point-to-box distance (Ren et al., 2020); depth-based (RegD) and boundary distances in backend modules |
32
+ | `fuzzy` | Fuzzy t-norms/t-conorms for logical query answering (FuzzQE, Chen et al., AAAI 2022) |
33
+ | `el` | EL++ ontology embedding: inclusion loss, role composition, existential boxes (Box2EL/TransBox) |
34
+
35
+ ### Taxonomy and training
36
+
37
+ | Component | What it does |
38
+ |---|---|
39
+ | `taxonomy` | TaxoBell-format dataset loader: `.terms`/`.taxo` parsing, train/val/test splitting |
40
+ | `taxobell` | TaxoBell combined loss: Bhattacharyya triplet + KL containment + volume regularization + sigma clipping |
41
+ | Training utilities | Negative sampling, AMSGrad optimizer |
42
+ | Evaluation | MRR, Hits@k, Mean Rank, nDCG |
43
+
44
+ ### Backends
45
+
46
+ | Component | What it does |
47
+ |---|---|
48
+ | `NdarrayBox` / `NdarrayGumbelBox` / `NdarrayCone` / `NdarrayOctagon` | CPU backend using `ndarray::Array1<f32>` |
49
+ | `CandleBox` / `CandleGumbelBox` | GPU/Metal backend using `candle_core::Tensor` |
50
+
51
+ The ndarray backend has full geometry support. The candle backend provides
52
+ GPU-accelerated box operations for training workflows.
53
+
54
+ ## Usage
55
+
56
+ ```toml
57
+ [dependencies]
58
+ subsume = { version = "0.7", features = ["ndarray-backend"] }
59
+ ndarray = "0.16"
60
+ ```
61
+
62
+ ```rust
63
+ use subsume::ndarray_backend::NdarrayBox;
64
+ // Renamed import avoids shadowing std::boxed::Box
65
+ use subsume::Box as BoxRegion;
66
+ use ndarray::array;
67
+
68
+ // Box A: [0,0,0] to [1,1,1] (general concept)
69
+ let premise = NdarrayBox::new(array![0., 0., 0.], array![1., 1., 1.], 1.0)?;
70
+
71
+ // Box B: [0.2,0.2,0.2] to [0.8,0.8,0.8] (specific, inside A)
72
+ let hypothesis = NdarrayBox::new(array![0.2, 0.2, 0.2], array![0.8, 0.8, 0.8], 1.0)?;
73
+
74
+ // Containment probability: P(B inside A)
75
+ let p = premise.containment_prob(&hypothesis)?;
76
+ assert!(p > 0.9);
77
+ ```
78
+
79
+ ## Examples
80
+
81
+ ```bash
82
+ cargo run -p subsume --example containment_hierarchy # taxonomic is-a relationships with nested boxes
83
+ cargo run -p subsume --example gumbel_box_exploration # Gumbel boxes, soft containment, temperature effects
84
+ cargo run -p subsume --example cone_training # training cone embeddings on a taxonomy
85
+ cargo run -p subsume --example box_training # training box embeddings on a 25-entity taxonomy
86
+ cargo run -p subsume --example taxobell_demo # TaxoBell Gaussian box losses on a mini taxonomy
87
+ cargo run -p subsume --example query2box # Query2Box: multi-hop queries, box intersection, distance scoring
88
+ cargo run -p subsume --example octagon_demo # octagon embeddings: diagonal constraints, containment, volume
89
+ cargo run -p subsume --example fuzzy_query # fuzzy query answering: t-norms, De Morgan duality, rankings
90
+ cargo run -p subsume --example dataset_training --release # full pipeline: WN18RR-format data, train, evaluate
91
+ cargo run -p subsume --example imagenet_hierarchy --release # 252 Tiny ImageNet synsets, volume-depth correlation
92
+ cargo run -p subsume --example save_checkpoint --release # generate pretrained/wordnet_subset.json checkpoint
93
+ cargo run -p subsume --features hyperbolic --example hyperbolic_demo # Poincare ball: hierarchy preservation, exponential capacity
94
+ cargo run -p subsume --example wn18rr_training --release # WN18RR benchmark: 40K entities, 20 epochs
95
+ cargo run -p subsume --example el_training # EL++ box embeddings on a biomedical-style ontology
96
+ cargo run -p subsume --features candle-backend --example taxobell_training # TaxoBell MLP encoder training (Candle)
97
+ ```
98
+
99
+ See [`examples/README.md`](examples/README.md) for a guide to choosing the right example.
100
+
101
+ ## Tests
102
+
103
+ ```bash
104
+ cargo test -p subsume
105
+ ```
106
+
107
+ Unit, property, and doc tests covering:
108
+
109
+ - Box geometry: intersection, union, containment, overlap, distance, volume, truncation
110
+ - Gumbel boxes: membership probability, temperature edge cases, Bessel volume
111
+ - Cones: angular containment, negation closure, aperture bounds
112
+ - Octagon: intersection closure, containment, Sutherland-Hodgman volume
113
+ - Fuzzy: t-norm/t-conorm commutativity, associativity, De Morgan duality
114
+ - Gaussian boxes, EL++ ontology losses, sheaf networks, hyperbolic geometry
115
+ - Training: MRR, Hits@k, Mean Rank, nDCG, negative sampling, AMSGrad
116
+
117
+ ## Choosing a geometry
118
+
119
+ | Geometry | When to use it | ¬? | Key tradeoff |
120
+ |---|---|---|---|
121
+ | NdarrayBox / NdarrayGumbelBox | Containment hierarchies, each dimension independent | No | Simple, fast; Gumbel adds dense gradients where hard boxes have zero gradient |
122
+ | Cone | Multi-hop queries requiring negation (FOL with ¬) | Yes | Closed under complement; angular parameterization harder to initialize |
123
+ | Octagon | Rule-aware KG completion; tighter containment than boxes | No | Diagonal constraints cut box corners; more parameters per entity |
124
+ | Gaussian | Taxonomy expansion with uncertainty (TaxoBell) | No | KL = asymmetric containment; Bhattacharyya = symmetric overlap |
125
+ | Hyperbolic | Tree-like hierarchies with exponential branching | No | Low-dim capacity; numerical care near Poincare ball boundary |
126
+
127
+ ## Why regions instead of points?
128
+
129
+ Point embeddings (TransE, RotatE, ComplEx) represent entities as vectors. They work
130
+ well for link prediction -- RotatE hits 0.476 MRR on WN18RR, BoxE hits 0.451.
131
+ For standard triple scoring, points are simpler and equally accurate.
132
+
133
+ Regions become necessary when the task requires structure that points cannot encode.
134
+ The core operation is **containment probability**:
135
+
136
+ $$P(B \subseteq A) = \frac{\text{Vol}(A \cap B)}{\text{Vol}(B)}$$
137
+
138
+ If B fits inside A, $P = 1$. If disjoint, $P = 0$. This is the scoring
139
+ function used for evaluation (`containment_prob`).
140
+
141
+ | What you need | Points | Regions |
142
+ |---|---|---|
143
+ | Containment (A ⊆ B) | No -- points have no interior | Box nesting = subsumption |
144
+ | Volume = generality | No -- points have no size | Large box = broad concept |
145
+ | Intersection (A ∧ B) | No set operations | Box ∩ Box = another box |
146
+ | Negation (¬A) | No complement | Cone complement = another cone |
147
+ | Uncertainty per dimension | No | Gaussian sigma |
148
+
149
+ Three tasks where point embeddings structurally fail:
150
+
151
+ 1. **Ontology completion (EL++)**: "Dog is-a Animal" requires representing one concept's
152
+ extension as a subset of another's. Points have no containment. Box2EL, TransBox, and
153
+ DELE use boxes for this and outperform point baselines on Gene Ontology, GALEN, and
154
+ Anatomy.
155
+
156
+ 2. **Logical query answering (∧, ∨, ¬)**: multi-hop KG queries with conjunction,
157
+ disjunction, and negation need set operations. ConE handles all three (MRR 52.9 on
158
+ FB15k EPFO+negation queries vs Query2Box's 41.0 and BetaE's 44.6). Points cannot
159
+ attempt negation queries at all.
160
+
161
+ 3. **Taxonomy expansion**: inserting a new concept at the right depth requires knowing
162
+ both what it is (similarity) and how general it is (volume). TaxoBell uses Gaussian
163
+ boxes where KL divergence gives asymmetric parent-child containment for free.
164
+
165
+ If your task is link prediction or entity similarity, use RotatE. If you need
166
+ containment, set operations, or volume, you need regions.
167
+
168
+ See [`docs/SUBSUMPTION_HISTORY.md`](docs/SUBSUMPTION_HISTORY.md) for the research
169
+ history of geometric subsumption embeddings, from hard boxes through Gumbel, cones, and beyond.
170
+
171
+ ## Why Gumbel boxes?
172
+
173
+ ![Gumbel gradient landscape](docs/gumbel_robustness.png)
174
+
175
+ *(a) Membership probability at a box boundary: hard boxes have a discontinuous step, Gumbel boxes have smooth sigmoids controlled by temperature. (b) Gradient magnitude: hard boxes produce zero gradient everywhere except the exact boundary (gray regions), while Gumbel boxes provide gradients throughout the space.*
176
+
177
+ Gumbel boxes model coordinates as Gumbel random variables, creating soft boundaries
178
+ that provide dense gradients throughout training. Hard boxes create flat regions where
179
+ gradients vanish; Gumbel boxes solve this *local identifiability problem*
180
+ (Dasgupta et al., 2020). Lower temperature (small beta) gives crisper boundaries with
181
+ sharper gradients; higher temperature gives broader gradients that reach further from
182
+ the boundary but sacrifice containment precision.
183
+
184
+ ## Training convergence
185
+
186
+ ![Training convergence](docs/training_convergence.png)
187
+
188
+ *25-entity taxonomy learned over 200 epochs. Left: total violation drops 3 orders of magnitude. Right: containment probabilities converge to 1.0 at different rates depending on hierarchy depth. Reproduce: `cargo run --example box_training` or `uv run scripts/plot_training.py`.*
189
+
190
+ ## Embedding export
191
+
192
+ `BoxEmbeddingTrainer::export_embeddings()` returns flat f32 vectors suitable for
193
+ safetensors, numpy (via reshape), and vector databases:
194
+
195
+ ```rust,ignore
196
+ let (ids, mins, maxs) = trainer.export_embeddings();
197
+ // mins/maxs are flat Vec<f32> of length n_entities * dim
198
+ // Reshape to (n_entities, dim) for numpy/safetensors
199
+ ```
200
+
201
+ Checkpoint save/load via serde:
202
+
203
+ ```rust,ignore
204
+ let json = serde_json::to_string(&trainer)?;
205
+ let restored: BoxEmbeddingTrainer = serde_json::from_str(&json)?;
206
+ ```
207
+
208
+ ## Integration patterns
209
+
210
+ Convert from petgraph (when `petgraph` feature is enabled):
211
+
212
+ ```rust,ignore
213
+ use subsume::petgraph_adapter::from_graph;
214
+ let dataset = from_graph(&my_digraph);
215
+ ```
216
+
217
+ Convert from polars (no dependency needed, user-side code):
218
+
219
+ ```rust,ignore
220
+ use subsume::dataset::Triple;
221
+ let triples: Vec<Triple> = df.column("head")?.str()?
222
+ .into_iter()
223
+ .zip(df.column("relation")?.str()?)
224
+ .zip(df.column("tail")?.str()?)
225
+ .filter_map(|((h, r), t)| Some(Triple::new(h?, r?, t?)))
226
+ .collect();
227
+ let dataset = Dataset::new(triples, vec![], vec![]);
228
+ ```
229
+
230
+ ## References
231
+
232
+ - Nickel & Kiela (2017). "Poincare Embeddings for Learning Hierarchical Representations"
233
+ - Vilnis et al. (2018). "Probabilistic Embedding of Knowledge Graphs with Box Lattice Measures"
234
+ - Li et al. (2019). "Smoothing the Geometry of Probabilistic Box Embeddings" (ICLR 2019)
235
+ - Abboud et al. (2020). "BoxE: A Box Embedding Model for Knowledge Base Completion"
236
+ - Dasgupta et al. (2020). "Improving Local Identifiability in Probabilistic Box Embeddings"
237
+ - Ren et al. (2020). "Query2Box: Reasoning over Knowledge Graphs using Box Embeddings"
238
+ - Hansen & Ghrist (2019). "Toward a Spectral Theory of Cellular Sheaves"
239
+ - Bodnar et al. (2022). "Neural Sheaf Diffusion: A Topological Perspective on Heterophily and Oversmoothing in GNNs"
240
+ - Boratko et al. (2021). "Box Embeddings: An open-source library for representation learning using geometric structures" (EMNLP Demo)
241
+ - Chen et al. (2021). "Probabilistic Box Embeddings for Uncertain Knowledge Graph Reasoning" (BEUrRE, ACL 2021)
242
+ - Gebhart, Hansen & Schrater (2021). "Knowledge Sheaves: A Sheaf-Theoretic Framework for Knowledge Graph Embedding"
243
+ - Zhang & Wang (2021). "ConE: Cone Embeddings for Multi-Hop Reasoning over Knowledge Graphs"
244
+ - Chen et al. (2022). "Fuzzy Logic Based Logical Query Answering on Knowledge Graphs"
245
+ - Jackermeier et al. (2023). "Dual Box Embeddings for the Description Logic EL++"
246
+ - Yang, Chen & Sattler (2024). "TransBox: EL++-closed Ontology Embedding"
247
+ - Bourgaux et al. (2024). "Knowledge Base Embeddings: Semantics and Theoretical Properties" (KR 2024)
248
+ - Charpenay & Schockaert (2024). "Capturing Knowledge Graphs and Rules with Octagon Embeddings"
249
+ - Lacerda et al. (2024). "Strong Faithfulness for ELH Ontology Embeddings" (TGDK 2024)
250
+ - Huang et al. (2023). "Concept2Box: Joint Geometric Embeddings for Learning Two-View Knowledge Graphs"
251
+ - Mashkova et al. (2024). "DELE: Deductive EL++ Embeddings for Knowledge Base Completion"
252
+ - Yang & Chen (2025). "Achieving Hyperbolic-Like Expressiveness with Arbitrary Euclidean Regions"
253
+ - Mishra et al. (2026). "TaxoBell: Gaussian Box Embeddings for Self-Supervised Taxonomy Expansion" (WWW '26)
254
+
255
+ ## See also
256
+
257
+ - [`hyperball`](https://crates.io/crates/hyperball) -- hyperbolic geometry primitives (optional; requires `hyperbolic` feature for Poincare ball embeddings)
258
+
259
+ ## License
260
+
261
+ MIT OR Apache-2.0
@@ -0,0 +1,82 @@
1
+ <!-- KaTeX CSS -->
2
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css" crossorigin="anonymous">
3
+
4
+ <!-- KaTeX JavaScript -->
5
+ <!--
6
+ Note: we intentionally do not use SRI hashes here.
7
+ In practice these files are used in multiple contexts (rustdoc, local previews, etc.) and
8
+ stale/incorrect integrity values fail closed and silently break rendering.
9
+ -->
10
+ <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js" crossorigin="anonymous"></script>
11
+ <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/contrib/auto-render.min.js" crossorigin="anonymous"></script>
12
+
13
+ <script>
14
+ // Configure KaTeX to render math in rustdoc
15
+ document.addEventListener("DOMContentLoaded", function() {
16
+ // Render math in all documentation content
17
+ renderMathInElement(document.body, {
18
+ delimiters: [
19
+ {left: "\\[", right: "\\]", display: true},
20
+ {left: "\\(", right: "\\)", display: false},
21
+ {left: "$$", right: "$$", display: true},
22
+ {left: "$", right: "$", display: false}
23
+ ],
24
+ throwOnError: false,
25
+ strict: false,
26
+ trust: true
27
+ });
28
+
29
+ // Also watch for dynamically loaded content (rustdoc uses JS to load content)
30
+ const observer = new MutationObserver(function(mutations) {
31
+ mutations.forEach(function(mutation) {
32
+ mutation.addedNodes.forEach(function(node) {
33
+ if (node.nodeType === 1) { // Element node
34
+ renderMathInElement(node, {
35
+ delimiters: [
36
+ {left: "\\[", right: "\\]", display: true},
37
+ {left: "\\(", right: "\\)", display: false},
38
+ {left: "$$", right: "$$", display: true},
39
+ {left: "$", right: "$", display: false}
40
+ ],
41
+ throwOnError: false,
42
+ strict: false,
43
+ trust: true
44
+ });
45
+ }
46
+ });
47
+ });
48
+ });
49
+
50
+ // Observe the main content area
51
+ const content = document.querySelector('.content') || document.querySelector('main') || document.body;
52
+ if (content) {
53
+ observer.observe(content, {
54
+ childList: true,
55
+ subtree: true
56
+ });
57
+ }
58
+ });
59
+ </script>
60
+
61
+ <style>
62
+ /* Enhance KaTeX rendering in rustdoc */
63
+ .rustdoc .katex {
64
+ font-size: 1.1em;
65
+ }
66
+
67
+ .rustdoc .katex-display {
68
+ margin: 1.5em 0;
69
+ overflow-x: auto;
70
+ overflow-y: hidden;
71
+ }
72
+
73
+ /* Better spacing for math in doc comments */
74
+ .rustdoc .docblock .katex-display {
75
+ margin: 1em 0;
76
+ }
77
+
78
+ .rustdoc .docblock .katex {
79
+ font-size: 1.05em;
80
+ }
81
+ </style>
82
+