ENSy: Design, Implementation, and Application of an Interactive Embedding Navigation System for Large Language Models
Author: Alexandre da Silva Santos
Institution: Federal University of Maranhão
Program: B.Sc. in Science and Technology – Computer Engineering
Date: August 2026
Version: 2.0.0
The internal representations of large language models, commonly referred to as word embeddings, encode rich semantic and syntactic relationships in high-dimensional vector spaces that resist straightforward human inspection. This work presents ENSy (Embedding Navigation System), an interactive, browser-based computational environment designed to enable the navigation, exploration, and geometric analysis of high-dimensional embedding spaces extracted from three large language model architectures: Qwen 2.5 0.5B-Instruct (decoder-only,
Keywords: word embeddings, embedding navigation, dimensionality reduction, co-ranking, trustworthiness, continuity,
---columns{count=2}---
Modern large language models (LLMs) rely on embedding matrices to map discrete tokens—linguistic units such as words, subwords, or characters—into continuous, dense vectors in a high-dimensional real-valued space
Despite the theoretical richness of these spaces, their high dimensionality—ranging from
Dimensionality reduction techniques such as Principal Component Analysis (PCA), t-distributed Stochastic Neighbor Embedding (t-SNE), Uniform Manifold Approximation and Projection (UMAP), and Isomap offer a bridge between the native high-dimensional space and lower-dimensional projections that preserve topological or statistical structure to varying degrees. However, these transformations introduce distortions whose nature and magnitude vary across algorithms and datasets. Existing tools for applying these techniques to language model embeddings are often limited to static 2D scatter plots, require specialized data science environments, or lack quantitative assessment of projection fidelity.
This work addresses these limitations by presenting ENSy (Embedding Navigation System): a full-stack, interactive platform that renders large language model embedding spaces as navigable 3D manifolds in the browser and quantifies geometric distortions through the rank-based co-ranking framework of Lee & Verleysen (2009). ENSy empowers researchers to explore high-dimensional geometries via 6-DOF flight controls, inspect local neighborhoods using screen-space reticle raycasting, contrast four projection algorithms (UMAP, t-SNE, PCA, Isomap), assess projection quality through co-ranking metrics, and visualize local distortion contributions via a thermal camera overlay.
The contribution of this work is both theoretical and practical. It provides a concrete implementation of an XAI instrument for language model geometry, demonstrates the architectural patterns required to couple a machine learning inference pipeline with a real-time 3D rendering engine, and offers an accessible platform for pedagogical exploration of embedding spaces at the undergraduate and graduate levels.
The research program guiding this work is articulated through five specific objectives:
O1 — Full-Stack Manifold Rendering. To design and implement an interactive web architecture capable of extracting language model embeddings from multiple large language model architectures and rendering them as navigable 3D Riemannian manifold approximations.
O2 — Multi-Algorithmic and Multi-Model Comparative Analysis. To integrate linear (PCA) and non-linear (t-SNE, UMAP, Isomap) dimensionality reduction engines behind a unified asynchronous API, enabling comparative inspection across four algorithms and three model architectures (Qwen 2.5 0.5B-Instruct, Gemma 2B, BERT base uncased), yielding 12 experimental configurations.
O3 — Quantitative Projection Quality Assessment. To implement the rank-based co-ranking framework (Lee & Verleysen, 2009) computing Trustworthiness
O4 — Topological Neighborhood Inspection. To implement a screen-space proximity selection mechanism that dynamically exposes local topological structures through a three-layer color system (reference partition, thermal camera
O5 — Interpretability and Methodological Rigor. To demonstrate the system's practical efficacy as an explainable AI tool while maintaining a reproducible experimental protocol with a fixed dataset derived from the Penn Treebank, congelated hyperparameter tables, and seed-fixed stochastic algorithms.
This document is organized as follows. Section 2 provides the theoretical background on word embeddings, dimensionality reduction algorithms, and the co-ranking quality assessment framework. Section 3 describes the system architecture in full, encompassing the technology stack, component model, and data flow. Section 4 details the backend implementation, including the embedding pipeline, projection endpoints, and metrics computation. Section 5 describes the frontend implementation, with emphasis on the Three.js rendering engine, camera control model, raycasting selection mechanism, and visualization layers. Section 6 discusses user interaction design and interface layout. Section 7 presents the data model. Section 8 discusses limitations and directions for future work. Section 9 concludes.
The mathematical foundation of word embeddings rests on the distributional hypothesis, which asserts that words appearing in similar linguistic contexts tend to share semantic properties. Formally, given a vocabulary
mapping each token
ENSy extracts exclusively the input embedding matrix of each model — get_input_embeddings().weight for Qwen 2.5 and Gemma 2B (decoder-only), and word_embeddings.weight for BERT (encoder-only). This representation is directly comparable across the three architectures because it corresponds to the token-to-vector mapping applied before any contextual attention layer, making it architecture-agnostic at the point of extraction. Extracting hidden states from intermediate transformer layers would require decisions about layer depth, context, and pooling strategy that would compromise cross-architecture comparability.
The three models differ not only in architecture (decoder-only vs. encoder-only) but also in embedding dimensionality, vocabulary size, tokenizer, pre-training objective, corpus, and training recipe. ENSy's experimental design therefore permits observing whether distortion patterns of dimensionality reduction algorithms are consistent or variable across different models and architectures, without attributing causality exclusively to any single factor.
:::booktabs
| Model | Architecture | Embedding dimension |
Vocab. size |
|---|---|---|---|
| Qwen 2.5 0.5B-Instruct | Decoder-only (Transformer) | 896 | 151,936 |
| Gemma 2B | Decoder-only (Transformer) | 2,048 | 256,000 |
| BERT base uncased | Encoder-only (Transformer) | 768 | 30,522 |
| ::: |
The cosine similarity between two embedding vectors
The cosine similarity ranges in the interval
All embedding vectors are subjected to mandatory
In ENSy, the high-dimensional neighborhood structure used by all co-ranking metrics is computed using the cosine distance matrix metric="cosine" to ensure consistency between the neighborhood graph construction and the metric used for quality assessment.
Since native embedding dimensions (
PCA is a classical linear method that projects data onto a lower-dimensional subspace defined by the directions of maximum variance in the original data. Given the centered data matrix
selecting the
A PCA-NC (non-centered) variant, which omits the centering step
t-SNE is a nonlinear probabilistic method that preserves local neighborhood structure in the projection. t-SNE constructs a probability distribution
The perplexity is fixed at
UMAP is a manifold learning technique grounded in Riemannian geometry and algebraic topology. UMAP constructs a weighted graph representation of the high-dimensional data, approximating the manifold on which the data lies, then optimizes a low-dimensional layout by minimizing the cross-entropy between the high- and low-dimensional fuzzy topological representations. UMAP preserves both local and global structure better than t-SNE and is significantly faster for large datasets.
ENSy applies UMAP with the following congelated parameterization (library defaults):
The library default values for n_neighbors and min_dist are adopted deliberately: using documented defaults rather than values selected to produce visually appealing projections protects against the criticism that hyperparameters were adjusted post-hoc to favor a particular result.
Isomap is a nonlinear method that extends classical multidimensional scaling (MDS) to preserve geodesic distances on the data manifold. Isomap first constructs a neighborhood graph with
In ENSy, Isomap uses metric="cosine" for graph construction. The neighborhood scale of 15 is adopted to ensure approximate comparability with UMAP's neighborhood graph, not as a canonical value for the algorithm.
ENSy adopts the rank-based co-ranking framework of Lee & Verleysen (2009) as the primary quantitative instrument for assessing the geometric fidelity of each dimensionality reduction, following the implementation order:
Given
The computational cost is
Intrusions and Extrusions. An intrusion occurs when $\hat{r}{ij} \le K < r{ij}$: point
Trustworthiness
Trustworthiness is penalized by severe
The mild intrusion and extrusion fractions are defined as (Lee & Verleysen, 2009, Eq. 22–23):
(fraction of mild
(fraction of mild
A positive value indicates intrusive behavior (crowding, as characteristically produced by t-SNE in sparse regions); a negative value indicates extrusive behavior (tearing, as produced by Isomap under component collapse); a value near zero indicates approximately balanced behavior. The apparently counterintuitive sign convention—where intrusive behavior yields
The overall preservation of
where
The thermal camera visualization requires a per-token local score. Each entry
This definition satisfies the consistency property (verified as an automated test before thermal camera deployment):
The local score ranges approximately in
For each projected token
where content_noun/content_verb/function_word as the reference linguistic partition. The Silhouette provides a complementary measure of inter-category separation in the projected space; it measures separation, not the cause (crowding, tearing, etc.). Class-Conditional Centering is never applied before this computation, as using class labels to center prior to an unsupervised projection algorithm would artificially inflate inter-category separation and invalidate the metric.
The concept of "manifold" in ENSy's nomenclature refers to the mathematical concept of a topological manifold: a space that locally resembles Euclidean space but may possess complex global geometry. The embedding vectors of a language model are hypothesized to lie near a low-dimensional manifold embedded in the high-dimensional vector space
ENSy follows a two-tier client-server architecture, separating the computationally intensive embedding extraction, dimensionality reduction, and co-ranking metric computation from the interactive rendering and user interface.
ENSy leverages modern web and scientific computing frameworks structured across four primary layers:
Frontend and Graphics Engine. React (v19.0.1) and TypeScript (~v5.8.2) orchestrate component state and static type verification, while Three.js (v0.184.0) manages the WebGL 3D scene graph, shader routines, and canvas rendering. Vite (v6.2.3) serves as the high-throughput development bundler, Tailwind CSS (v4.1.14) and Motion (v12.23.24) govern responsive layout and micro-animations, MathJax (v3) provides client-side LaTeX equation rendering, and Lucide React (v0.546.0) delivers vector iconography.
Backend and Asynchronous Serving. High-throughput REST API serving is provided by FastAPI (v0.115.8) running on the asynchronous Uvicorn (v0.34.0) ASGI server.
Machine Learning and Reduction Pipeline. Token embedding extraction is performed on Qwen 2.5 0.5B-Instruct, Gemma 2B, and BERT base uncased using PyTorch (v2.6.0) and HuggingFace Transformers (v4.49.0). Dimensionality reduction algorithms (PCA, t-SNE, Isomap, UMAP) are executed via scikit-learn (v1.6.1) and UMAP (v0.5.7), supported by vectorized NumPy (v2.1.3) linear algebra.
Verification and Quality Assurance. Automated endpoint validation and visual regression testing are conducted using Pytest (v8.3.5) and headless Playwright (v1.48.0). Synthetic co-ranking test cases (Section 4.6) provide pre-deployment validation of all metric implementations.
The system's data flow proceeds through the following stages:
Stage 1 — Dataset Construction. Prior to any embedding extraction or metric computation, the lexical dataset is built from the Penn Treebank (Section 4.2). The resulting dataset.json is versioned and its SHA-256 hash is recorded. This file is congelated and serves as a fixed experimental input.
Stage 2 — Application Initialization. Upon server startup (app.py), the dependency installer verifies and installs missing Python packages. The cached embedding matrices for all three models are loaded from memory if available; otherwise, a daemon thread is launched to load each model sequentially.
Stage 3 — Model Loading (Background). The background thread loads each model's tokenizer and weights via the HuggingFace Transformers library. The input embedding matrix get_input_embeddings().weight (Qwen/Gemma) or bert.embeddings.word_embeddings.weight (BERT), cast from float16 to float32, and active_vectors pointer for that model is atomically updated.
Stage 4 — API Request. The React frontend issues an HTTP GET request to /api/projection/{model_id}/{engine_type} whenever the user changes the model or projection algorithm.
Stage 5 — Projection and Metric Computation. The backend applies the requested dimensionality reduction algorithm to active_vectors for the selected model, producing 3D coordinates for each token. It then computes the full co-ranking matrix
Stage 6 — JSON Response. The backend returns a JSON object conforming to the SemanticSpace interface. The frontend's App.tsx stores this in the semanticSpace state variable.
Stage 7 — 3D Scene Update. SpaceVisualizer detects the updated data and calls syncProjectionDataPrivate(), which linearly interpolates each token's 3D point towards its new projected position over subsequent animation frames. Token colors are updated by rewriting the BufferGeometry vertex color attribute.
Stage 8 — Offline Fallback. If the API request fails, App.tsx catches the exception and loads the static semanticSpaceData from src/data/semanticSpace.ts, ensuring the application remains functional.
The backend server (app.py) begins with a self-bootstrapping dependency management routine (install_deps()). Before importing any scientific computing library, the function iterates over a required package list (fastapi, uvicorn, transformers, torch, scikit-learn, umap-learn) and attempts an import for each. Any package that fails the import test is installed via subprocess.check_call([sys.executable, "-m", "pip", "install", ...]). This strategy eliminates the need for a pre-configured environment.
ENSy's experimental vocabulary is a lexical dataset derived from the Penn Treebank, not a fixed hardcoded word list. The dataset is built by a 10-step curation pipeline that produces a frozen, reproducible lexical input prior to any embedding extraction or metric computation:
-
Corpus Extraction: Extract token surface forms from the Penn Treebank corpus (PTB tokens
$\to$ lexical types). - Text Normalization: Apply case normalization (lowercasing) and punctuation/symbol stripping.
-
Linguistic Categorization: Assign each candidate form a reference linguistic category:
content_noun,content_verb, orfunction_word. - Homograph Disambiguation: Resolve homographs appearing under multiple categories using a fixed corpus-frequency rule: the category of highest frequency in the corpus is assigned. Forms whose category cannot be determined unambiguously by this rule are excluded from the dataset.
- Qwen Tokenization: Perform independent tokenization using the Qwen 2.5 tokenizer.
- Gemma Tokenization: Perform independent tokenization using the Gemma 2B tokenizer.
- BERT Tokenization: Perform independent tokenization using the BERT base uncased tokenizer.
- Single-Token Intersection Filtering: Retain only candidate forms that map to exactly one token ID across all three tokenizers and correspond to valid rows of each model's input embedding matrix.
- Strict Deduplication: Ensure each normalized surface form appears at most once in the dataset.
-
Category Balancing and Hash Freezing: Balance the representation across the three reference categories and record the resulting
$N$ items asdataset.jsonaccompanied by its SHA-256 integrity hash.
This 10-step curation constitutes Phase 1 of the system's 21-step operational sequence: Steps 1–10 produce and freeze dataset.json; Steps 11–13 extract input embeddings across the three models, verify native dimensions (
The final token count dataset.json file and its SHA-256 hash are versioned in the repository as immutable experimental inputs.
Taxonomy note. The partition content_noun/content_verb/function_word is designated the reference linguistic partition — not "grammatical classes" or "stopwords." The label assigned to each form in the dataset represents the chosen category in the curated set, not an inference from model representations.
Upon model loading, embedding vectors for the float32, and
cache_key = (
model_id,
dataset_hash,
extraction_config,
preprocessing_config,
)This cache guarantees zero recomputation when the user switches projection algorithms for the same model, while ensuring that any change to the dataset or extraction configuration triggers a full recomputation. No disk-based cache is used; reproducibility is guaranteed by the dataset_hash and fixed random_state=42 for stochastic algorithms.
The model loading procedure is executed asynchronously via a Python daemon thread spawned upon server startup (see Appendix D, Listing D.2).
The background initialization sequence executes three sequential stages per model:
Tokenizer and Architecture Instantiation. The pipeline instantiates the HuggingFace AutoTokenizer and AutoModelForCausalLM (Qwen, Gemma) or AutoModel (BERT) using half-precision (float16) to minimize memory footprint.
Embedding Matrix Extraction. The input embedding weights get_input_embeddings().weight (Qwen/Gemma) or bert.embeddings.word_embeddings.weight (BERT), cast to float32 NumPy arrays, and
Single-Token Validation. Each candidate dataset term is evaluated with the model's tokenizer. Forms that decompose into multiple subwords are excluded, consistent with the dataset construction criterion of Section 4.2.
Atomic Pointer Replacement. Following validation, the global references active_words, active_vectors, and model metadata are updated simultaneously. Python's Global Interpreter Lock (GIL) ensures atomic reference reassignment.
Note on Gemma 2B. Gemma 2B is a gated model on HuggingFace Hub, requiring license acceptance and token-based authentication before programmatic download. Credentials must be configured before server startup.
The core API endpoint is GET /api/projection/{model_id}/{engine_type}, accepting qwen, gemma, or bert as model_id and umap, pca, tsne, or isomap as engine_type.
All algorithm parameters are fixed prior to data collection and are not modified during experimentation:
:::booktabs
| Algorithm | Parameter | Value |
|---|---|---|
| PCA | n_components | 3 |
| PCA | centering | yes (ablation: PCA-NC, non-centered) |
| t-SNE | perplexity | 5 (fixed; adopted for small sample size) |
| t-SNE | random_state | 42 |
| t-SNE | metric (high-dim) | cosine |
| UMAP | n_neighbors | 15 (library default) |
| UMAP | min_dist | 0.1 (library default) |
| UMAP | metric | cosine |
| UMAP | random_state | 42 |
| Isomap | n_neighbors | 15 (comparable scale to UMAP) |
| Isomap | metric | cosine |
| ::: |
For stochastic algorithms (t-SNE, UMAP): a fixed seed guarantees reproducibility of the reported result but does not characterize stability. Sensitivity analysis with multiple seeds is a separate analysis, never mixed with the 12 principal experimental results.
The endpoint returns 3D projected coordinates and all co-ranking metrics for the requested (model, algorithm) configuration.
Following projection, the backend computes the full co-ranking metric suite for
Co-ranking matrix computation ($O(N^2 \log N)$): rank matrices
Trustworthiness and Continuity (
Behavioral indicator
Per-token decomposition
Silhouette score: computed over the projected
Results for all 12 configurations (3 models × 4 algorithms) are versioned alongside the dataset_hash and the library version manifest.
In production mode, FastAPI mounts the dist/ directory and serves the React SPA. The fallback route GET /{rest_of_path:path} returns index.html for any non-API path, enabling client-side React navigation.
The frontend architecture is partitioned across four specialized React components coordinated by the root App.tsx. The root orchestrator maintains global application state (selectedModel, selectedEngine, selectedNode, semanticSpace, activeColorLayer), handles HTTP communication with the backend API, and manages fallback routing. SidebarLeft.tsx hosts model and algorithm selectors, co-ranking metric panels, and server connectivity monitors. SpaceVisualizer.tsx encapsulates the Three.js WebGL canvas, 6-DOF camera mechanics, HUD overlays, and the three-layer color system. SidebarRight.tsx inspects node coordinates, presents co-ranking metrics for the selected token, and provides CSV exports. BottomHUD.tsx renders non-intrusive navigation indicators.
All inter-component communication occurs through unidirectional props and callbacks, preserving deterministic state propagation via useState and useCallback hooks.
Application settings are debounced and serialized to localStorage at one-second intervals to prevent frame drops during the 60 FPS animation loop. Persisted attributes include the active model (modelId), reduction engine (projectionType), active color layer (colorLayer), octant spatial filter (currentFilter), camera projection geometry (cameraMode), field of view (fov), coordinate axis visibility flags (showXAxis, showYAxis, showZAxis), reference grid planes, mouse sensitivity coefficients, and 6-DOF camera coordinates.
The SpaceVisualizer component initializes the Three.js rendering pipeline within an empty-dependency useEffect hook, isolating the WebGL scene graph from React reconciliation cycles.
The Three.js scene graph consists of a primary THREE.Scene configured with exponential atmospheric fog ($\text{FogExp2}(0xfcfcfc, 0.003)$), an ambient illumination source (THREE.AmbientLight(0xffffff, 1)), a composite gridGroup containing reference planes, axis arrows, and tick markers, and a single THREE.Points object backed by a BufferGeometry containing all token positions and vertex colors.
Three distinct camera modes require both a perspective and an orthographic camera:
Perspective mode (THREE.PerspectiveCamera): standard projection model; FOV is user-configurable from
Parallel (Orthographic) mode (THREE.OrthographicCamera): orthographic projection for engineering views. Bounds are dynamically synchronized to the perspective camera's current frustum:
Two-point perspective mode: approximation of architectural two-point perspective, implemented by injecting a vertical shear into the projection matrix: persp.projectionMatrix.elements[9] = Math.tan(persp.rotation.x).
ENSy implements a six-degrees-of-freedom (6-DOF) first-person flight control scheme using the browser's Pointer Lock API. When the user clicks the viewport, requestPointerLock() captures the mouse cursor.
Mouse movement updates camera orientation in YXZ Euler rotation order:
where
Keyboard translation is computed each frame with time-delta scaling:
where
Camera preset transitions use a damped interpolation scheme per-frame:
Position LERP (Linear Interpolation):
Quaternion-based SLERP is used for rotation to prevent gimbal lock. Interpolation terminates when position distance
Preset camera transitions align the viewport to canonical orthogonal and perspective projections: Front view targets position
All THREE.BufferGeometry, with colors stored as a vertex attribute array (geometry.setAttribute('color', new THREE.BufferAttribute(colorArray, 3))), and the material configured with vertexColors: true. This consolidation produces a single draw call for the entire point cloud regardless of
Token labels are rendered as canvas sprites (THREE.Sprite + CanvasTexture), where each label is drawn as text into an offscreen <canvas> and uploaded as a GPU texture billboarded toward the camera. This approach eliminates the per-frame DOM update cost of the CSS2DRenderer pattern (<div> elements repositioned via JavaScript every frame), at the cost of texture memory and draw calls that scale significantly better than DOM manipulation for the expected
Visual clarity is maintained through dynamic depth sorting, where
Token colors are managed through three distinct visual layers with a strict precedence rule: Probing (Layer 3) > Thermal Camera (Layer 2) > Reference Partition (Layer 1). Switching layers is implemented by rewriting the vertex color array and marking colorAttribute.needsUpdate = true — an
Layer 1 — Reference Linguistic Partition (default). Each token is colored by its dataset category:
:::booktabs
| Category | Color |
|---|---|
content_noun |
Blue |
content_verb |
Orange |
function_word |
Teal |
| ::: |
Layer 2 — Thermal Camera /
:::booktabs
| Range of |
Color | Interpretation |
|---|---|---|
| Blue/Cyan | Extrusive behavior (tearing) | |
| Light grey (never green) | High fidelity / neutral | |
| Red/Orange | Intrusive behavior (crowding) | |
| ::: |
Grey is reserved for the neutral point; green is reserved exclusively for Layer 3. The scale is global and fixed — it does not normalize dynamically per frame or per projection. Two algorithms with the same local value always receive the same color, enabling direct comparison.
Layer 3 — Neighborhood Probing (active only on the reticle-selected token, F3).
:::booktabs
| Color | Category | Definition |
|---|---|---|
| Green | True Neighbors ( |
Genuine high-dim neighbors preserved in projection |
| Red | False Neighbors ( |
False neighbors introduced by projection |
| Translucent blue | Missing Neighbors ( |
Genuine neighbors displaced outside neighborhood |
| ::: |
The thermal camera label in the UI reads: "Thermal Camera — local contribution to
ENSy implements a screen-space reticle selection mechanism evaluated on every animation frame. The viewport center is established as onNodeHovered state transition, highlighting the corresponding label with the .highlighted-acad CSS class, activating Layer 3 probing visualization for that token, and populating the Right Sidebar with the token's co-ranking metrics.
When switching projection algorithms or models, new coordinates arrive from the API asynchronously. The syncProjectionDataPrivate() function updates each token's targetPosition, and the animation loop smoothly interpolates token coordinates via $\vec{p}_{t+1} = \vec{p}t + 0.04 \cdot (\vec{p}{\text{target}} - \vec{p}_t)$. This LERP factor produces a transition of approximately
Grid tick density dynamically adapts to camera distance
A 2D circular minimap is rendered each frame on a <canvas> element overlaid on the viewport. It depicts all token positions projected onto the XZ plane, colored by the active color layer (Layer 1 by default), with a camera orientation indicator.
The interface adopts a three-panel editorial layout designed for scholarly rigor: a 280-pixel Left Sidebar hosting engine controls, model selection, and projection quality metrics; a central WebGL viewport for full-fidelity 3D exploration; and a 280-pixel Right Sidebar functioning as a topological inspector for the selected token. Typography is strictly structured using EB Garamond for editorial prose, Fira Code for monospaced metrics, and MathJax 3 for mathematical expressions.
The control dashboard organizes administrative controls across five functional groups:
Model Selection. Interactive switching between Qwen 2.5 0.5B-Instruct, Gemma 2B, and BERT base uncased, with display of model architecture type (decoder-only / encoder-only), embedding dimensionality, and active vocabulary count
Manifold Properties. Displays active reduction algorithm, real-time animation FPS, and dataset hash.
Projection Engine. Provides interactive switching between UMAP, t-SNE, PCA (centered), PCA-NC (ablation), and Isomap algorithms, accompanied by spatial octant filters (Positive, Negative, or Full volume).
Visualization Layers. Toggle controls for the three color layers (Reference Partition / Thermal Camera / Neighborhood Probing) and the
Camera Optics. Hosts projection mode selectors (Perspective, Parallel orthographic, Two-point perspective), field-of-view sliders (
Cartesian Apparatus. Allows fine-grained toggling of coordinate axes (X, Y, Z), reference plane grids, mouse navigation sensitivity, and HUD indicators.
Upon selecting a token via the central reticle, the inspector renders:
- The token's projected coordinate vector
$\vec{v} = [x_{3d},; y_{3d},; z_{3d}]^\top$ - Global vocabulary matrix index and reference linguistic category badge
- Per-token behavioral indicator
$B_{NX,i}(K)$ for the active$K$ - Ranked table of true neighbors (
$T_K$ ), false neighbors ($F_K$ ), and missing neighbors ($M_K$ ) with cosine similarity scores - Co-ranking curves (
$M_T(K)$ ,$M_C(K)$ ,$B_{NX}(K)$ , $Q_{NX}(K)$) for the current (model, algorithm) configuration - Export trigger for downloading neighborhood data as CSV (
token_{label}_neighbors.csv)
A dedicated panel displays the 12-configuration matrix (
A minimal floating overlay monitors real-time keypress states (W, A, S, D, R, F, ESC) with instantaneous typographic highlights, providing immediate visual feedback during flight navigation.
The frontend data model is structured around a set of TypeScript interfaces defined in src/types.ts that enforce compile-time verification across coordinate payloads, metric scores, and model metadata (see Appendix D, Listing D.4).
The SemanticNode interface includes both id (sequential index within the active dataset) and token_id (vocabulary index in the model's full vocabulary), addressing the discrepancy between sequential node ordering and actual model vocabulary identifiers.
src/data/semanticSpace.ts contains pre-computed semantic nodes with UMAP-projected coordinates derived from actual Qwen 2.5 0.5B-Instruct execution on the Penn Treebank dataset, using the congelated parameters of Section 4.5. This ensures a meaningful experience even without the Python backend.
L1 — Context-free embeddings. ENSy extracts exclusively the static input embedding matrices of each model — lookup tables applied before any contextual attention layer. This is a deliberate methodological decision ensuring direct comparability across the three architectures (Section 2.1), not an accidental limitation. Contextualized representations (hidden states from intermediate transformer layers) would require decisions about layer depth, context, and pooling strategy that would compromise cross-architecture comparability.
L2 — Causal attribution. The three models differ in architecture, embedding dimension, vocabulary, tokenizer, pre-training objective, corpus, and training recipe simultaneously. Observed differences in distortion patterns cannot be attributed exclusively to any single factor. The experiment design permits observing cross-model variation; it does not isolate architectural causality.
L3 — Sample size and statistical variability. The dataset
L4 — Single-machine deployment. Production deployment would require containerization (Docker) and production ASGI server configuration.
L5 — Rendering at
F1 — Contextual embeddings. Sentence-level hidden state extraction from intermediate transformer layers would enable visualization of how token representations shift across semantic contexts, extending beyond the static input embedding geometry characterized in this work.
F2 — Anisotropy analysis. Real-time characterization of anisotropy in the embedding space (Ethayarajh, 2019; Cai et al., 2021) would provide additional geometric context complementing the co-ranking framework.
F3 — Trajectory visualization. Rendering interpolation paths between projection algorithms as visible trajectories would reveal embedding stability across algorithmic transformations.
F4 — Multi-session persistence. Server-side result caching with database-backed storage would enable longitudinal analysis and cross-session comparison without recomputing projections.
This work presented ENSy (Embedding Navigation System), an interactive computational environment for the 3D navigation and quantitative geometric analysis of neural language model embedding spaces. By coupling a FastAPI/PyTorch backend with a WebGL/Three.js rendering engine, the system fulfills its core design and architectural objectives: extracting architecture-agnostic input embeddings across distinct neural architectures (Qwen 2.5 0.5B, Gemma 2B, BERT base uncased), projecting them into navigable 3D Riemannian manifolds across linear (PCA) and non-linear (t-SNE, UMAP, Isomap) dimensionality reduction engines at 60 FPS, and grounding geometric quality assessment in the rank-based co-ranking framework of Lee & Verleysen (2009).
The methodological framework establishes a strictly reproducible experimental protocol across 12 configurations (3 model architectures
ENSy bridges the gap between abstract mathematical quality criteria and interactive spatial exploration, delivering a foundational, browser-native instrument for explainable artificial intelligence (XAI). Following the full empirical execution of the 12 experimental configurations, future research directions will expand beyond static input embedding matrices toward layer-wise contextual representations, cross-session comparative persistence, and automated anisotropy diagnostics in deep language models.
---/columns---
:::pagebreak
manifold/
├── app.py FastAPI backend server
├── dataset_builder.py Penn Treebank dataset pipeline (21-step)
├── metrics.py Co-ranking metric suite (Q, M_T, M_C, B_NX, Q_NX, Silhouette)
├── requirements.txt Unified Python dependencies (backend + testing)
├── index.html HTML template; MathJax configuration
├── package.json Node.js package manifest
├── vite.config.ts Vite build configuration; API proxy
├── tsconfig.json TypeScript compiler options
└── src/
├── main.tsx React application entrypoint
├── App.tsx Root component; state orchestration
├── types.ts TypeScript data model interfaces
├── index.css Global CSS styles
├── components/
│ ├── SpaceVisualizer.tsx Three.js renderer; flight controls; color layers
│ ├── SidebarLeft.tsx Control dashboard; model/algorithm selectors
│ ├── SidebarRight.tsx Token inspector; co-ranking metrics; CSV export
│ ├── MetricsPanel.tsx 12-configuration comparative metrics panel (F5)
│ └── BottomHUD.tsx Navigation indicator
└── data/
├── dataset.json Congelated lexical dataset (PTB-derived, versioned)
└── semanticSpace.ts Static fallback dataset
:::pagebreak
Path parameters:
model_idin {qwen,gemma,bert}engine_typein {umap,pca,pca_nc,tsne,isomap}
Response schema:
{
status: "STABLE" | "LOADING",
meta: {
model: string,
architecture: "decoder-only" | "encoder-only",
embedding_dim: number,
total_tokens: number,
dataset_hash: string,
algorithm_params: object,
library_versions: object
},
nodes: Array<{
id: number,
label: string,
token_id: number,
category: "content_noun" | "content_verb" | "function_word",
coords: {
x3d: number, y3d: number, z3d: number
},
bnx_local: { [K: number]: number }, // B_{NX,i}(K) for K in {5,10,15,20}
true_neighbors: Array<{ label: string, cosine_similarity: number }>,
false_neighbors: Array<{ label: string, cosine_similarity: number }>,
missing_neighbors: Array<{ label: string, cosine_similarity: number }>
}>,
metrics: {
trustworthiness: { [K: number]: number },
continuity: { [K: number]: number },
b_nx: { [K: number]: number },
q_nx: { [K: number]: number },
silhouette: number
}
}Triggers execution of the Penn Treebank dataset pipeline (Section 4.2). Returns the resulting dataset.json content and SHA-256 hash.
:::pagebreak
:::booktabs
| Input Binding | Subsystem / Operation | Functional Description |
|---|---|---|
| Click Viewport | Input Management | Engages browser pointer lock mode (requestPointerLock()) to capture mouse orientation. |
W / S |
6-DOF Flight Camera | Translates the camera position forward or backward along the horizontal XZ world plane. |
A / D |
6-DOF Flight Camera | Strafes the camera position left or right perpendicular to the current gaze direction vector. |
R / F |
6-DOF Flight Camera | Translates the camera position vertically along the global Cartesian Y-axis (ascend / descend). |
| Mouse Motion | 6-DOF Flight Camera | Adjusts camera orientation (pitch and yaw) with clamped pitch angle to eliminate gimbal lock. |
| Scroll Wheel | Optical Controls | Adjusts focal distance zoom (translates along the local Z-axis in perspective mode; scales orthographic frustum). |
T |
Visualization | Toggles the Thermal Camera layer (Layer 2, |
H |
User Interface | Toggles visibility of the bottom flight navigation HUD overlay. |
P |
Developer Diagnostics | Outputs point cloud memory metrics, raycasting statistics, and vector state to the browser console. |
Escape |
Input Management | Releases browser pointer lock and restores standard cursor interaction mode. |
| ::: |
:::pagebreak
# Decoder-only models (Qwen, Gemma)
embedding_matrix = model.get_input_embeddings().weight.detach().float().numpy()
# Encoder-only models (BERT)
embedding_matrix = model.bert.embeddings.word_embeddings.weight.detach().float().numpy()
# L2 normalization (mandatory, applied to all models)
norms = np.linalg.norm(embedding_matrix, axis=1, keepdims=True)
embedding_matrix = embedding_matrix / norms@app.on_event("startup")
def startup_event():
for model_id in ["qwen", "gemma", "bert"]:
threading.Thread(
target=load_model_background,
args=(model_id,),
daemon=True
).start(){
"id": 0,
"label": "document",
"token_id": 6062,
"category": "content_noun",
"coords": {
"x3d": 5.423237,
"y3d": 2.238469,
"z3d": 6.157989
},
"bnx_local": { "5": 0.12, "10": 0.08, "15": 0.05, "20": 0.03 },
"true_neighbors": [{ "label": "file", "cosine_similarity": 0.8821 }],
"false_neighbors": [{ "label": "compile", "cosine_similarity": 0.4103 }],
"missing_neighbors": [{ "label": "record", "cosine_similarity": 0.7654 }]
}type LinguisticCategory = "content_noun" | "content_verb" | "function_word";
type KValue = 5 | 10 | 15 | 20;
interface Coords3D {
x3d: number;
y3d: number;
z3d: number;
}
interface Neighbor {
label: string;
cosine_similarity: number;
}
interface SemanticNode {
id?: number;
token_id: number;
label: string;
category: LinguisticCategory;
coords: Coords3D;
bnx_local: Record<KValue, number>;
true_neighbors: Neighbor[];
false_neighbors: Neighbor[];
missing_neighbors: Neighbor[];
}
interface CoRankingMetrics {
trustworthiness: Record<KValue, number>;
continuity: Record<KValue, number>;
b_nx: Record<KValue, number>;
q_nx: Record<KValue, number>;
silhouette: number;
}
interface SemanticSpace {
meta: SemanticMeta;
nodes: SemanticNode[];
metrics: CoRankingMetrics;
}CAI, Xingyu et al. Isotropy in the Contextual Embedding Space: Clusters and Manifolds. ICLR, 2021.
ETHAYARAJH, Kawin. How Contextual are Contextualized Word Representations? EMNLP-IJCNLP, 2019.
LEE, John A.; VERLEYSEN, Michel. Quality assessment of dimensionality reduction: Rank-based criteria. Neurocomputing, v. 72, p. 1431–1443, 2009.
LUEKS, W. et al. How to Evaluate Dimensionality Reduction? Improving the Co-ranking Matrix. arXiv:1110.3917, 2011.
MCINNES, Leland et al. UMAP: Uniform Manifold Approximation and Projection for Dimension Reduction. arXiv, 2018.
PEARSON, Karl. On lines and planes of closest fit. Philosophical Magazine, 1901.
ROUSSEEUW, Peter J. Silhouettes: a graphical aid to the interpretation and validation of cluster analysis. J. Comput. Appl. Math., 1987.
TENENBAUM, Joshua B. et al. A global geometric framework for nonlinear dimensionality reduction. Science, 2000.
VAN DER MAATEN, Laurens; HINTON, Geoffrey. Visualizing data using t-SNE. JMLR, 2008.
VENNA, Jarkko; KASKI, Samuel. Local multidimensional scaling. Neural Networks, 2006.