Spaces:
Running
Running
File size: 4,896 Bytes
23680f2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
{
"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
}
|