Skip to main content

Origami

A machine learning model for JSON data.

PyPI Python License

Origami trains models that learn the relationships between fields in JSON objects. Given a dataset of JSON records, an Origami model can:

  • Predict missing field values based on the other fields
  • Generate new synthetic JSON objects that follow the patterns in your data
  • Embed JSON objects as dense vectors for similarity search or downstream tasks

Unlike tabular ML models that require flat feature vectors, Origami works directly with JSON structure — including nested objects and arrays.

Installation

pip install origami-ml

Or with uv:

uv add origami-ml

Origami v2 is a breaking rewrite of the original origami-ml package. See Migrating from v1 to v2 if you are upgrading from v1.

Requires Python 3.11+. PyTorch is installed automatically. GPU acceleration (CUDA, Apple Silicon MPS) is auto-detected — no configuration needed.

Quick Start

from origami import OrigamiPipeline

# Your data: a list of JSON objects (Python dicts)
data = [
    {"product": "Wireless Headphones", "categories": ["audio", "wireless"], "price": 79.99,  "rating": 4.2},
    {"product": "USB-C Hub",           "categories": ["accessories"],       "price": 34.99,  "rating": 4.5},
    {"product": "Mechanical Keyboard", "categories": ["peripherals"],       "price": 129.99, "rating": 4.7},
    # ... more records
]

# Train with default settings
pipeline = OrigamiPipeline()
pipeline.fit(data, epochs=20)

# Predict a missing value (including arrays)
prediction = pipeline.predict(
    {"product": "Bluetooth Speaker", "categories": None},
    target_key="categories",
    allow_complex_values=True,
)
print(prediction)  # ["audio", "wireless"]

# Generate new synthetic records
samples = pipeline.generate(num_samples=5, temperature=0.8)

# Get a vector embedding
embedding = pipeline.embed({"product": "Wireless Headphones", "categories": ["audio", "wireless"]})
# numpy array of shape (128,)

# Save and load
pipeline.save("model.pt")
loaded = OrigamiPipeline.load("model.pt")

Configuration

For more control, pass an OrigamiConfig with nested configuration objects:

from origami import OrigamiPipeline, OrigamiConfig, ModelConfig, TrainingConfig, DataConfig

config = OrigamiConfig(
    model=ModelConfig(
        d_model=256,       # Larger hidden dimension (default: 128)
        n_layers=6,        # More transformer layers (default: 4)
    ),
    training=TrainingConfig(
        batch_size=64,
        num_epochs=50,
        target_key="price",                  # Track prediction metrics during training
        eval_metrics={"acc": "accuracy"},     # Compute accuracy each epoch
    ),
    data=DataConfig(
        numeric_mode="scale",  # Handle numeric fields as continuous values
    ),
)

pipeline = OrigamiPipeline(config)
pipeline.fit(train_data, eval_data=val_data)
  • ModelConfig controls the model architecture (size, depth, position encoding strategy)
  • TrainingConfig controls training hyperparameters (learning rate, batch size, evaluation)
  • DataConfig controls data preprocessing (how numeric fields are handled, vocabulary size)
  • InferenceConfig controls inference-time constraints (grammar and schema enforcement)

See Configuration Reference for all options.

Command-Line Interface

Origami includes a CLI for training, prediction, generation, evaluation, and embedding:

# Train a model
origami train -d data.jsonl -t label -e 20 -o model.pt

# Predict missing values
origami predict -m model.pt -d test.jsonl -t label

# Generate synthetic data
origami generate -m model.pt -n 100 --temp 0.8

# Evaluate model performance
origami evaluate -m model.pt -d test.jsonl -t label --metrics accuracy

See CLI Reference for all commands and options.

Documentation

  • Concepts — How Origami works: tokenization, position encoding, grammar constraints
  • Python SDK — Complete API reference for OrigamiPipeline
  • CLI Reference — All commands, options, and supported data formats
  • Configuration — Every configuration parameter explained
  • Migrating from v1 to v2 — Breaking changes and migration guidance

How It Works

Origami converts each JSON object into a sequence of tokens that preserve the hierarchical structure — keys, values, nesting, and arrays are all explicitly represented. Instead of encoding token position as a simple index (1st, 2nd, 3rd...), Origami uses Key-Value Position Encoding (KVPE), which encodes the path through the JSON tree. This lets the model understand which key each value belongs to, regardless of key order.

A grammar constraint system (a pushdown automaton) ensures that every model output is valid JSON — no syntax errors, ever. This is applied automatically with no configuration needed.

For numeric fields with many distinct values (like prices or measurements), Origami can model them as continuous distributions rather than discrete tokens, using a mixture density output head.

For a deeper explanation of these concepts, see the Concepts page.

License

Apache-2.0

Metadata

Release files for origami-ml 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for origami-ml 2.0.1
File Size Uploaded Provenance
origami_ml-2.0.1.tar.gz 1.4 MB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for origami-ml 2.0.1
File Interpreter ABI Platform
origami_ml-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 1.5 MB

Release files / origami_ml-2.0.1.tar.gz

Download URL origami_ml-2.0.1.tar.gz
Size 1.4 MB
Tags Source
SHA-256 checksum
How to use checksums
b16d07a5a19c323cff7e135600bdeee4b11548a35c270e14d52677d57afa6538
BLAKE2b-256 checksum
How to use checksums
5e93f524fd5f33138499d70c81e53c473dc3396e8d3062c75c5245dd1ec481a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.11

Release files / origami_ml-2.0.1-py3-none-any.whl

Download URL origami_ml-2.0.1-py3-none-any.whl
Size 169.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fe8af7c2bb16af375923da8603affa9b91d338f61c8119868685a0bb8b18a1e7
BLAKE2b-256 checksum
How to use checksums
39b0abd880a4f89f384d7f80d82dad30e27d4725fb7c99d608bf6e415530ea54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.11

Security for origami-ml 2.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page