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:

diorama.show(reduced, documents, color_by="category")                  # single field
diorama.show(reduced, documents, color_by=["category", "city", "score"])  # dropdown
diorama.show(reduced, documents)                                        # auto-discover top 15

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.1.0.tar.gz (56.6 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.1.0-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for diorama-0.1.0.tar.gz
Algorithm Hash digest
SHA256 308c85c6a08db68525c61d9c75b3b76880068e902ae4f8ca715fb85a31c762c7
MD5 2b65f016726e3eed9f29547f9c1ab2bf
BLAKE2b-256 a287b4be461bbb88a239aa3409807c86f0248367e6744bebc3cedb62aff81c9f

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for diorama-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 00f1e6b0beff65b1be8d3109956d3d975a594c9784451c0f5b8fb0a1426a39cd
MD5 88b3a21a465054eca40ff2db3b88fb90
BLAKE2b-256 586ed25b8222ca23b96105a85f6bf02102b041906795a43643a5db1738132603

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