{ "cells": [ { "cell_type": "markdown", "id": "e26a6a66", "metadata": {}, "source": [ "# HyperView Demo\n", "This notebook demonstrates how to use HyperView to visualize embeddings in both Euclidean and Hyperbolic spaces.\n" ] }, { "cell_type": "code", "execution_count": null, "id": "0aba0ed9", "metadata": { "execution": { "iopub.execute_input": "2025-12-21T23:01:47.867950Z", "iopub.status.busy": "2025-12-21T23:01:47.867881Z", "iopub.status.idle": "2025-12-21T23:01:48.736348Z", "shell.execute_reply": "2025-12-21T23:01:48.735942Z" } }, "outputs": [], "source": [ "import sys\n", "from pathlib import Path\n", "\n", "# Add src to path for development\n", "sys.path.insert(0, str(Path.cwd().parent / \"src\"))\n", "\n", "import hyperview as hv\n", "print(f\"HyperView version: {hv.__version__}\")\n" ] }, { "cell_type": "markdown", "id": "00becfad", "metadata": {}, "source": [ "## Initialize Dataset\n", "We'll create a new dataset named `cifar100_demo`.\n" ] }, { "cell_type": "code", "execution_count": 2, "id": "3e5e93d5", "metadata": { "execution": { "iopub.execute_input": "2025-12-21T23:01:48.738083Z", "iopub.status.busy": "2025-12-21T23:01:48.737879Z", "iopub.status.idle": "2025-12-21T23:01:49.297549Z", "shell.execute_reply": "2025-12-21T23:01:49.296797Z" } }, "outputs": [], "source": [ "dataset = hv.Dataset(\"cifar100_demo\")\n" ] }, { "cell_type": "markdown", "id": "2248602f", "metadata": {}, "source": [ "## Load CIFAR-100 Data\n", "We'll load 500 samples from the CIFAR-100 dataset using Hugging Face Datasets.\n" ] }, { "cell_type": "code", "execution_count": null, "id": "0666b39a", "metadata": { "execution": { "iopub.execute_input": "2025-12-21T23:01:49.299289Z", "iopub.status.busy": "2025-12-21T23:01:49.299171Z", "iopub.status.idle": "2025-12-21T23:01:51.732573Z", "shell.execute_reply": "2025-12-21T23:01:51.732008Z" } }, "outputs": [], "source": [ "dataset.add_from_huggingface(\n", " \"uoft-cs/cifar100\",\n", " split=\"train\",\n", " image_key=\"img\",\n", " label_key=\"fine_label\",\n", " max_samples=500,\n", ")\n" ] }, { "cell_type": "markdown", "id": "5e119424", "metadata": {}, "source": [ "## Compute Embeddings\n", "This will use a pre-trained model to compute high-dimensional embeddings for our images.\n" ] }, { "cell_type": "code", "execution_count": null, "id": "d4e2c71f", "metadata": { "execution": { "iopub.execute_input": "2025-12-21T23:01:51.734082Z", "iopub.status.busy": "2025-12-21T23:01:51.733890Z", "iopub.status.idle": "2025-12-21T23:01:55.876495Z", "shell.execute_reply": "2025-12-21T23:01:55.875932Z" } }, "outputs": [], "source": [ "dataset.compute_embeddings(show_progress=True)\n" ] }, { "cell_type": "markdown", "id": "6f552a59", "metadata": {}, "source": [ "## Compute Visualization Layout\n", "This step performs dimensionality reduction to project the high-dimensional embeddings into 2D Euclidean and Hyperbolic spaces.\n" ] }, { "cell_type": "code", "execution_count": null, "id": "b357847f", "metadata": { "execution": { "iopub.execute_input": "2025-12-21T23:01:55.880223Z", "iopub.status.busy": "2025-12-21T23:01:55.879935Z", "iopub.status.idle": "2025-12-21T23:01:56.272742Z", "shell.execute_reply": "2025-12-21T23:01:56.272238Z" } }, "outputs": [], "source": [ "dataset.compute_visualization()\n" ] }, { "cell_type": "markdown", "id": "54af1ea2", "metadata": {}, "source": [ "## Launch Interactive Visualizer\n", "Finally, we launch the visualizer. In a notebook environment, this will display an interactive iframe.\n" ] }, { "cell_type": "code", "execution_count": null, "id": "0acef7dc", "metadata": { "execution": { "iopub.execute_input": "2025-12-21T23:01:56.274506Z", "iopub.status.busy": "2025-12-21T23:01:56.274369Z", "iopub.status.idle": "2025-12-21T23:01:56.356551Z", "shell.execute_reply": "2025-12-21T23:01:56.355551Z" } }, "outputs": [], "source": [ "session = hv.launch(dataset)\n" ] } ], "metadata": { "kernelspec": { "display_name": ".venv (3.12.8)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.8" } }, "nbformat": 4, "nbformat_minor": 5 }