Skip to main content

Visualize text embeddings with interactive plots

Project description

embedding-visualizer

Interactive 2D visualization of text embeddings using OpenAI's embedding API and Plotly.

Install

cd embedding_visualizer
uv sync

Requires an OPENAI_API_KEY environment variable.

Usage

from embedding_visualizer import visualize_embeddings, PrincipalComponent, TextEmbedding

docs = [
    {
        "text": "This text will be embedded",
        "label": "optional, groups points in the legend",
        "color": "optional, color for the point/label group",
        "line-id": "optional, connects points with the same id",
        "hover": "optional hover text",
    },
    # ...
]

# t-SNE or PCA projection
plot = visualize_embeddings(docs=docs, projection="t-sne")  # or "pca"

# Custom per-axis projection
plot = visualize_embeddings(
    docs=docs,
    x_projection=PrincipalComponent(1),
    y_projection=TextEmbedding("some text to project onto"),
    title="My Embedding Plot",
)

plot.display()              # show in Jupyter or browser
plot.to_html("plot.html")   # self-contained HTML file

Doc fields

Field Required Description
text yes Text to embed
label no Legend group name; points with the same label share a color
color no Point color. If label is set, applies to the whole group
line-id no Connects points with the same id in document order
hover no Custom hover text (defaults to first 100 chars of text)

Projections

  • projection="t-sne" — t-SNE with cosine metric (default)
  • projection="pca" — PCA
  • PrincipalComponent(n) — project onto the nth principal component (1-indexed)
  • TextEmbedding("text") — cosine similarity with a reference text's embedding

Example

examples/repo_files.py embeds every Python file in this repository at multiple truncation points and connects versions of the same file with lines:

uv run python examples/repo_files.py

Caching

Embeddings are cached to ~/.cache/embedding_visualizer/ so repeated runs don't re-call the API.

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

embedding_visualizer-0.1.1.tar.gz (106.1 kB view details)

Uploaded Source

Built Distribution

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

embedding_visualizer-0.1.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file embedding_visualizer-0.1.1.tar.gz.

File metadata

  • Download URL: embedding_visualizer-0.1.1.tar.gz
  • Upload date:
  • Size: 106.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for embedding_visualizer-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a976956c0812d878fb835787cb8594a9879fd10d5641f58cf47c4d8245387119
MD5 9361a7db6311dd7459d6eed56d878c00
BLAKE2b-256 978665dddfcdf5395d16e2299f4ed7ecf2ca06913c0bb6d005900871ad84934b

See more details on using hashes here.

Provenance

The following attestation bundles were made for embedding_visualizer-0.1.1.tar.gz:

Publisher: workflow.yaml on nielsrolf/embedding_visualizer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file embedding_visualizer-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for embedding_visualizer-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d8d3a8976181b1d22e41220083c4c216e7750a279f9da039cda34fbd9cde2a57
MD5 6c5570605ac4f8caecac31e0d40a8af9
BLAKE2b-256 9ca1caa516b7379abd6b5a8ee577b69dc0cdc5ddbe0b8781bc4c109e7f0a97bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for embedding_visualizer-0.1.1-py3-none-any.whl:

Publisher: workflow.yaml on nielsrolf/embedding_visualizer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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