Skip to main content

2D/3D embedding visualization for JSON documents

Project description

Diorama

Interactive 2D/3D embedding visualization for JSON documents.

Diorama takes high-dimensional embeddings and a list of JSON documents, runs dimensionality reduction, and produces interactive Plotly scatter plots. Color points by any field in your documents, filter with MongoDB query syntax, and switch between perspectives via dropdown.

Install

pip install diorama[umap]        # core + UMAP (recommended)
pip install diorama[all]         # core + UMAP + T-SNE + Dash app

Quick start

import numpy as np
import diorama

# Load your data
documents = [{"city": "Sydney", "score": 4.2, "category": "A"}, ...]
embeddings = np.load("embeddings.npy")  # (N, D) array

# Reduce and visualize in one call
fig = diorama.show(embeddings, documents, color_by="category")

Reduce once, explore fast

UMAP is the expensive step. Run it once and reuse the result:

reduced = diorama.reduce(embeddings, n_components=2, show_progress=True)

# Fast iterations — only filtering + plotting
diorama.show(reduced, documents, color_by="city")
diorama.show(reduced, documents, color_by="score")
diorama.show(reduced, documents, filter={"score": {"$gt": 3.0}})

Positions are stable across calls — the same document always appears at the same coordinates.

Large datasets

For 100K+ points, fit UMAP on a subset and transform the rest:

reduced = diorama.reduce(
    embeddings, n_components=2,
    subsample=10_000, show_progress=True,
)

Coloring

Pass a single field, a list of fields (creates a dropdown), or None to auto-discover:

# single field
diorama.show(reduced, documents, color_by="category")

# dropdown
diorama.show(reduced, documents, color_by=["category", "city", "score"])

# auto-discover top 15
diorama.show(reduced, documents)

Numeric fields with many unique values are colored continuously. Low-cardinality numerics, strings, and booleans are categorical. Override with:

diorama.show(
    reduced, documents,
    color_by="score",
    color_type_overrides={"score": "categorical"},
)

Filtering

Filter documents using MongoDB query syntax:

diorama.show(reduced, documents,
             filter={"score": {"$gte": 4.0}, "city": "Sydney"})

diorama.show(reduced, documents,
             filter={"$or": [{"city": "Sydney"}, {"city": "Melbourne"}]})

diorama.show(reduced, documents,
             filter={"name": {"$regex": "^A"}})

Supported operators: $eq, $ne, $gt, $gte, $lt, $lte, $in, $nin, $exists, $regex, $and, $or, $not, $nor.

3D

reduced_3d = diorama.reduce(embeddings, n_components=3)
diorama.show(reduced_3d, documents, color_by="category")

Dash app

Launch an interactive web UI with a field dropdown, filter text input, and 2D/3D toggle:

diorama.app(embeddings, documents, subsample=10_000)
# Opens at http://127.0.0.1:8050

Requires the dash extra: pip install diorama[dash].

Options

diorama.show(
    embeddings,
    documents,
    color_by="field.path",          # dot notation for nested fields
    filter={"age": {"$gt": 20}},    # MongoDB-style filter
    n_components=2,                  # 2 or 3
    method="umap",                   # "umap" or "tsne"
    subsample=10_000,                # fit on subset, transform all
    color_scheme="dark",             # "light" or "dark"
    height=800,                      # figure height in pixels
    show_progress=True,              # tqdm progress bar
    output_path="plot.html",         # save to file
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

diorama-0.2.0.tar.gz (59.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

diorama-0.2.0-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file diorama-0.2.0.tar.gz.

File metadata

  • Download URL: diorama-0.2.0.tar.gz
  • Upload date:
  • Size: 59.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.11

File hashes

Hashes for diorama-0.2.0.tar.gz
Algorithm Hash digest
SHA256 62d16b956a5627c36d5aeed5e8908091e56c2809f43d3f91a7864f0a014d3e3e
MD5 ad3f78cedb9ab8b92c377992153a6627
BLAKE2b-256 951a2d1e70c50232b619915e3918b6e74f14e080d9b12160ecc0b31c2639b1a2

See more details on using hashes here.

File details

Details for the file diorama-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: diorama-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.11

File hashes

Hashes for diorama-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 60800a625651270c0a04014a4b2d0e4db9f6db66153bb172a480bc27019cc3a3
MD5 6e87b15195d287c4a6f914dc7f369b4e
BLAKE2b-256 cfc396bd5a32b438d17943bfbf7966a7c21f3a59c760bb0377944a2dd8b144e5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page