The workflow
export_artifact writes the manifest and ONNX file described in
Bringing your own weights, so khaos serve ./my-artifact
works straight away. Each domain also exposes its own build and model classes under
khaos.<domain>.models.
All architectures export to ONNX with a dynamic batch dimension, and a dynamic
length where the domain needs one (nodes, atoms, timesteps, tokens). The tests
check that ONNX Runtime reproduces PyTorch’s output.
Finance
Named-entity recognition on the raw text of SEC filings.FilingNER is a Hugging
Face encoder with a BIO token-classification head. It returns per-token logits
for entity extraction and a mean-pooled vector, the filing or chunk embedding.
model_name. Filings are far longer
than an encoder’s context, so two helpers cover the text side:
Physics
The four physics artifacts use Fourier Neural Operators (FNOs) on a fixed 64 x 64 grid. Artifact names end in_2d for the grid dimensionality; 3D variants (_3d)
are planned but not built yet.
Every model solves a scenario: the input holds the fields and the boundary
conditions, so the same network answers for different boundaries. A boundary
condition is two channels, a mask (where it applies) and its values. Scalar PDE
parameters such as viscosity go in a separate params input.
FNO2d handles steady problems, where the output depends only on the scenario.
TimeConditionedFNO2d also takes a time t, so you can query the state at any time
directly instead of stepping a solver. The datasets describe each channel in detail.
The trained artifacts are wrapped in
khaos.physics.models.Normalized, which
standardizes inputs and rescales outputs inside the exported model. Serving takes raw
physical values, so you do not normalize anything yourself.
The grid resolution is fixed when you build the model, and the exported ONNX
model only accepts that grid size. Train and serve at the same resolution, or
export a separate artifact per resolution.
Robotics
Transformer encoders over(T, state_dim) trajectories. Inputs are traj
(batch, T, state_dim) and mask (batch, T) with 1 for real timesteps and 0
for padding, so variable-length trajectories batch together.
FailureDetector uses causal attention, so the logit at each timestep depends only
on past states. That makes it safe for a real-time loop: read the logit at the last
timestep.
Telemetry
Models for fixed-length sensor windows(batch, channels, length), split into
patches. Each window is normalized inside the model, so raw sensor units work.
The two autoencoders give a zero-shot anomaly score: the reconstruction error on the
normalized window. Pre-train on healthy data with
model.reconstruct(x), which
returns the reconstruction and the normalized input for your loss, optionally masking
patches first.
length must be a multiple of patch_len, and the exported model accepts that
window length. Slice streams into windows before calling it. The defaults are 3,200
samples for vibration, 2,048 for ECG, and 8 channels by 512 samples for regime
shifts (streams with fewer channels are zero-padded). The vibration autoencoder
squeezes each patch through a 16-number bottleneck so it cannot just copy its input.
Graph
Models for one graph per call: node featuresx (N, F) and a dense adjacency
adj (N, N). N is dynamic. Dense adjacency keeps the models free of sparse
operations so they export to ONNX; for very large graphs, run them on sampled
subgraphs.
GCNAutoencoder has a reconstruct(x, adj) method for masked-feature pre-training.
Fraud rings are the connected groups of high-scoring nodes, which a pipeline extracts
after the model runs.
Chemistry
A SMILES transformer (1D) and a GIN-style molecular graph network (2D), fused into a single molecule vector. Featurization (RDKit atom features and adjacency) belongs to your data pipeline; the models take tensors.
A pure-Python tokenizer for the SMILES ids lives in
khaos.chem.tokenizer, with no
RDKit or PyTorch needed:
Geometry
Point-set networks. Every model takes a fixed-size point setpoints
(batch, channels, 512): sample a mesh or scan to 512 points, center it and scale it
to the unit sphere first. The k-nearest-neighbor graph is rebuilt inside the model,
and everything exports to ONNX with a dynamic batch.
The embeddings are unit vectors, so cosine similarity is a dot product. The mesh encoder
sees normals, which separate shapes that share an outline; the scan encoder adds
attention pooling to cope with noise, occlusion and background points.
The number of points is fixed when you build the model, and the exported ONNX model
only accepts that many. The first release is trained on 512 points.
Tabular
Four different models for four different table problems.khaos.tabular.text has the pure-Python helpers that build these inputs:
encode_column turns a sample of cells into byte ids, pair_features computes the
overlap features, serialize_record writes a record as column: value | ..., and
robust_scale scales a numeric column.
The anomaly model is a masked-cell transformer. Each column of a row is a token, and
the model learns to predict hidden cells from the visible ones. To score a table, hide a
random 25% of the cells, run the model a few times with different masks, and use the
average error on hidden cells as the row’s anomaly score. Column ids are arbitrary slots
that training shuffles, so the model reasons from the other values rather than from fixed
column meanings, which is what lets it score tables it has never seen.