26. Inductive API¶
This page documents the inductive API. For a full run, see the inductive tutorial.
26.1 What it is for¶
The inductive brick defines method registries and datasets for SSL methods that do not require a graph. [1][2]
26.2 Examples¶
Instantiate a method by ID:
import numpy as np
from modssc.inductive import DeviceSpec, InductiveDataset, get_method_class
from modssc.inductive.methods.pseudo_label import PseudoLabelSpec
X_l = np.random.randn(5, 4)
y_l = np.array([0, 1, 0, 1, 0])
X_u = np.random.randn(20, 4)
spec = PseudoLabelSpec(classifier_id="knn", classifier_backend="numpy")
method = get_method_class("pseudo_label")(spec=spec)
method.fit(InductiveDataset(X_l=X_l, y_l=y_l, X_u=X_u), device=DeviceSpec(device="cpu"), seed=0)
List available method IDs:
from modssc.inductive import available_methods
print(available_methods())
The registry and dataset types are in src/modssc/inductive/registry.py and src/modssc/inductive/types.py. [1][2]
26.3 API reference¶
Inductive semi-supervised learning (planned).
This package defines the interfaces and registry for inductive methods. The inductive brick is read-only with respect to input artifacts; any data modifications must be handled by upstream bricks.
26.4
DeviceSpec
dataclass
¶
Device and dtype settings.
device
- cpu: always CPU
- cuda: use CUDA (error if unavailable)
- mps: use Apple MPS (error if unavailable)
- auto: pick cuda if available, else mps, else cpu
dtype: numeric precision to use for math operators
Source code in src/modssc/inductive/types.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
26.5
InductiveDataset
dataclass
¶
Read-only input bundle for inductive SSL methods.
The inductive brick must not mutate these arrays; any data changes should be handled by upstream bricks (sampling, preprocess, augmentation, views).
Source code in src/modssc/inductive/types.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
26.6
InductiveMethod
¶
Bases: Protocol
Common interface for inductive methods.
Source code in src/modssc/inductive/base.py
41 42 43 44 45 46 47 48 49 50 | |
26.7
InductiveNotImplementedError
¶
Bases: NotImplementedError
Raised when a method is registered but not implemented yet.
Source code in src/modssc/inductive/errors.py
21 22 23 24 25 26 27 28 29 30 | |
26.8
InductiveValidationError
¶
Bases: ValueError
Raised when inputs are invalid for inductive methods.
Source code in src/modssc/inductive/errors.py
17 18 | |
26.9
MethodInfo
dataclass
¶
Metadata for an inductive method.
Source code in src/modssc/inductive/base.py
26 27 28 29 30 31 32 33 34 35 36 37 38 | |
26.10
NumpyDataset
dataclass
¶
Strict numpy view of an inductive dataset (no implicit conversion).
Source code in src/modssc/inductive/adapters/numpy.py
42 43 44 45 46 47 48 49 50 51 52 | |
26.11
OptionalDependencyError
dataclass
¶
Bases: PackageOptionalDependencyMessageMixin, ImportError
Raised when an optional dependency (extra) is required but missing.
Source code in src/modssc/inductive/errors.py
8 9 10 11 12 13 14 | |
26.12
TorchDataset
dataclass
¶
Strict torch view of an inductive dataset (no implicit conversion).
Source code in src/modssc/inductive/adapters/torch.py
103 104 105 106 107 108 109 110 111 112 113 | |
26.13
TorchModelBundle
dataclass
¶
Torch model bundle provided by the deep-model brick.
Source code in src/modssc/inductive/deep/types.py
8 9 10 11 12 13 14 15 16 17 | |
26.14
make_numpy_rng(seed)
¶
Create a numpy Generator seeded with the given seed.
Source code in src/modssc/inductive/seed.py
13 14 15 | |
26.15
seed_everything(seed, *, deterministic=True)
¶
Best-effort deterministic seeding across random, numpy, and torch (if available).
Source code in src/modssc/inductive/seed.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
26.16
to_numpy_dataset(data)
¶
Validate and wrap an inductive dataset backed by numpy arrays.
Source code in src/modssc/inductive/adapters/numpy.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
26.17
to_torch_dataset(data, *, device=None, require_same_device=True)
¶
Validate and wrap an inductive dataset backed by torch tensors.
If device.device == "auto", only device consistency is enforced.
Source code in src/modssc/inductive/adapters/torch.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |
26.18
validate_inductive_dataset(data)
¶
Validate the minimal invariants needed by inductive algorithms.
Source code in src/modssc/inductive/validation.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
26.19
validate_torch_model_bundle(bundle)
¶
Validate a torch model bundle (model + optimizer).
Source code in src/modssc/inductive/deep/validation.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |