Skip to content
AI360XpertBeta
Playgrounds

Generative AI

Embeddings & Vector Space

Original vectors and a chosen metric determine retrieval; a coordinate map and camera determine the picture.

Guided steps 1 / 4

Stage 1 of 4: Space and Similarity

Twenty manually curated 3D vectors, three assigned groups. No learned/pretrained vectors, model training or random draws. Retrieval uses original coordinates; the camera only changes the picture.

Active PCA View; original neighbour metric cosine; pin none. Settings remain active on stage return.

PCA projection at yaw 45 degrees, tilt 10 degrees. The two axes on screen carry 60.69893678585573 percent of the variance. The most compressed pair candidate is prince and puppy. No word is pinned. Selected man.

0 word labels omitted to avoid crowding. Points may overlap; use native selection. Coordinates are orthographically projected, then equally scaled into pixels; rounded metrics do not feed computation.

Selected man

Original (1, 0, 0); centred (1.055, -0.045, -0.06000000000000003); active PCA View (0.005930625537955078, 1.048565226400123, -0.13829603633216242).

Yaw 45° = 0.7853981633974483 rad; pitch 10° = 0.17453292519943295 rad. Rotated (x,y,depth) = (-0.09359647956712704, 1.0503444395826498, 0.08164715090221698); pixels Pending measured canvas.

Active-coordinate variance: x 1.7734547188701675 + y 0.9248254675398695 = 2.698280186410037; hidden 1.7470698135899627; denominator 4.4453499999999995; ratio 0.6069893678585573. Population divisor 20; this is not semantic accuracy or ranking preservation.

Maximum-ratio pair prince ↔ puppy: original distance 2.891366458960192; raw projected distance 0.44976196465656665; denominator max(projected, 0.000001); ratio 6.428659349102604; pixel distance pending. First vocabulary pair wins exact ratio ties; a maximum ratio need not exceed one.

  • Word vector
Adjust parameters

Rotate about Y first. Drag adds 0.6 degrees per horizontal pointer pixel.

Rotate about X second. Positive tilt subtracts rotated depth from screen y.

Variance on screen60.7%Variance on screen: 60.7 %
prince ↔ puppy ratio6.4prince ↔ puppy ratio: 6.4

Does looking close prove two vectors are similar?

Twenty manually curated 3D vectors in three assigned groups. Select a word and inspect its original coordinates. Orbit using Yaw, Tilt or gridline drag; the picture is a different space.

Embedding

A numerical representation. These coordinates are hand-built, not learned or pretrained.

Check this stage

Check your understanding

Original vectors and a chosen metric determine retrieval. Orbit twenty manually curated vectors to see how a coordinate map and camera change the picture.

What are these vectors?

An embedding is a numerical representation. This lab uses twenty manually curated 3D vectors, with x/y/z coordinates, in three assigned groups. It neither loads pretrained vectors nor learns them. Select any word to inspect every original number.

People contains man, woman, king, queen, prince, princess, boy and girl; animals contains dog, cat, puppy, kitten, wolf and tiger; places contains france, paris, italy, rome, japan and tokyo. The full coordinate table is under Under the hood. There is no vocabulary editor or subword fallback. Unknown pure-API neighbour words return an empty list; an unknown analogy operand returns null.

The royalty and simplified gender offsets are illustrative construction choices, not empirical semantic evidence, universal semantic axes or a complete account of identity. Trained representations depend on data and objectives. The contextual objectives in the Word2Vec paper are external context, not operations performed here.

Which metric chooses a neighbour?

Pin a word using a mark or Pinned word. Three neighbour links and a full ranking use the original vectors. Selected word and ranking buttons inspect a candidate without changing the pin. Compare cosine and Euclidean with vocabulary, vectors, pinned query and candidate exclusion held fixed.

a⋅b=∑i=13aibi,∥a∥=∑i=13ai2,s(a,b)=a⋅b∥a∥∥b∥,d(a,b)=∑i=13(ai−bi)2.a\cdot b=\sum_{i=1}^{3}a_i b_i,\quad \|a\|=\sqrt{\sum_{i=1}^{3}a_i^2},\quad s(a,b)=\frac{a\cdot b}{\|a\|\|b\|},\quad d(a,b)=\sqrt{\sum_{i=1}^{3}(a_i-b_i)^2}.

Cosine ranks largest first; Euclidean ranks smallest first. The pin is excluded by identity. Exact score ties retain original vocabulary order. UI k is three; the general API floors finite k, clamps it from zero through available count and returns none for nonfinite k. The general vector query can include itself when no exclusion is supplied; identity exclusions remove every matching identity.

For nonzero vectors, cosine one means same direction, zero orthogonal and minus one opposite. Equal direction need not mean equal vectors or equivalent words. Zero-vector cosine is mathematically undefined; this API returns numeric sentinel zero, not observed orthogonality. The original UI vectors are all nonzero.

Dog·cat = −0.04+0.20+4.20 = 4.36; squared norms are 4.29 and 4.61. Squared distance is 0.16+0.01+0.01 = 0.18. Inspect the raw products, dot, norms, cosine, differences, squared terms and Euclidean distance. No rounding supplies ranking. For a=(1,0,0), b=(10,0,0), c=(1,1,0), cosine prefers b (one versus 1/√2), while Euclidean prefers c (one versus nine). Neither metric universally measures meaning.

Is the arithmetic query a word?

The UI operands are fixed: king − man + woman. Step Calculation reveals subtraction, then addition. These steps are not training or optimiser updates.

vking−vman=(0.1,1.5,0.1),q=(vking−vman)+vwoman=(−0.9,1.5,0.1).v_{king}-v_{man}=(0.1,1.5,0.1),\qquad q=(v_{king}-v_{man})+v_{woman}=(-0.9,1.5,0.1).

Queen is (−1.1,1.5,0.1), not that query. Their dot is 3.25; squared norms are 3.07 and 3.47; distance is 0.2. Cosine about 0.996 is a similarity, not confidence or accuracy. Original unnormalised operands produce q, then cosine ranks original candidates excluding all three operand identities. Inspection retains every score and zero-based rank. Absent/excluded answers have rank −1. An empty eligible set returns nearest null and score sentinel zero. Inspect vector selects an intermediate or query; cross marks distinguish computed points from words.

The pure API accepts other triples; the UI does not edit operands. The curated paris−france+italy matches rome up to floating rounding. One answer is no proof of reasoning, understanding, universal relations or model quality. The relation-specific analogy study motivates an explicit evaluation protocol; its experimental outcomes do not apply to this toy.

PCA View centres each arithmetic point once and expresses it in the full basis. Alternate View has no unique group for a new query: it borrows its nearest cosine match's group, people, for both intermediate and query. This is an arbitrary display convention. The retained arrows connect man→king and woman→query; group-dependent remaps need not preserve one common translation between these endpoints.

Which coordinate space is this?

Inspection separates original, centred, full PCA-basis, alternate-remapped, rotated, projected and pixel coordinates. PCA View retains all three coordinates:

μ=1N∑ivi,C=1N∑i(vi−μ)(vi−μ)T,zj=(v−μ)⋅uj.\mu=\frac1N\sum_i v_i,\qquad C=\frac1N\sum_i(v_i-\mu)(v_i-\mu)^{\mathsf T},\qquad z_j=(v-\mu)\cdot u_j.

Covariance uses population divisor N, not N−1. There is no standardisation, feature scaling or whitening. The symmetric 3×3 Jacobi solver starts at the identity basis; each rotation chooses the largest absolute off-diagonal entry, with exact pivot ties (0,1), (0,2), (1,2). Stop when that entry is at most 10⁻¹⁴ times the largest absolute current matrix entry, or after 64 rotations. A zero matrix stops immediately. Matrix and basis rotate together: no power-iteration seed, deflation or randomisation.

Eigenvalue estimates sort descending; exact ties retain original column order. PC1's first coordinate with absolute value above 10⁻¹² is made positive. PC2 aligns positively with the least-aligned standard axis to PC1, x/y/z on ties. A normalised cross product completes PC3; norm below 10⁻⁹ falls back to z. Signs are conventions. Empty input has mean/covariance zero. Singleton, constant, repeated, coincident, collinear, rank-deficient and tied-eigenvalue finite inputs have deterministic orthonormal outputs. Repeated eigenvalues do not identify unique individual axes.

A full centred orthonormal basis preserves pairwise Euclidean distances. Centring can change origin-relative cosine; the subsequent orthogonal map preserves centred dots and norms. The pure top-two API actually discards coordinate three and sets z=0; the UI does not use it. Official PCA documentation provides context, not numerical parity with this solver or covariance divisor.

Alternate View is (1.5y+tₓ, 1.5z+tᵧ, 1.5x+t_z). Translation tₓ is 2 for animals and −2 otherwise; tᵧ is 2 for places and −2 otherwise; t_z is 2 for people and −2 otherwise. Same-group differences are permuted and scaled by 1.5. Different-group translations can further change distances and angles. This is not t-SNE, UMAP, learned structure or a distance-preserving projection.

What does the camera discard?

The UI uses degrees, converted to radians. Yaw rotates Y first, pitch X second:

x1=xcos⁡ψ+zsin⁡ψ,z1=−xsin⁡ψ+zcos⁡ψ,y2=ycos⁡ϕ−z1sin⁡ϕ,z2=ysin⁡ϕ+z1cos⁡ϕ.x_1=x\cos\psi+z\sin\psi,\quad z_1=-x\sin\psi+z\cos\psi,\quad y_2=y\cos\phi-z_1\sin\phi,\quad z_2=y\sin\phi+z_1\cos\phi.

Orthographic projection keeps (x₁,y₂), discarding depth z₂, without perspective division. Gridline drag adds 0.6 degrees per horizontal/vertical pointer pixel, clamped yaw ±180° and pitch ±90°; sliders use five-degree grids. Exact off-grid angles survive links. Increasing depth paints word marks later; computed inspection marks sit above the vocabulary. Unpinned depth below −1 dims; pin/neighbour and selected identity otherwise control emphasis. Opacity never changes retrieval. Pixel y reverses the upward projected coordinate.

The measured rectangular domain expands to equal pixel units on both axes. A fixed per-mode radius includes arithmetic vectors with 12% padding. Raw projected and pixel distances are different units. Crowded labels are omitted at native font size; points are never jittered. Native selectors and raw inspection retain all omitted values. Zero-length arrows have no shaft/head. Visual overlap does not imply equal original vectors.

What is “Variance on screen”?

Rotate the active mapped vocabulary, then compute population variances:

R=Var⁡(x1)+Var⁡(y2)Var⁡(x1)+Var⁡(y2)+Var⁡(z2).R=\frac{\operatorname{Var}(x_1)+\operatorname{Var}(y_2)}{\operatorname{Var}(x_1)+\operatorname{Var}(y_2)+\operatorname{Var}(z_2)}.

Each variance uses divisor N. Pixel scales, labels and opacity are excluded. Empty/constant data make the ratio undefined; compatibility sentinel one is separate from the raw denominator and defined flag. Below 45% is a teaching threshold, not numerical divergence. Captured variance does not certify pairwise distances, rankings, semantic accuracy or neighbourhood preservation. Across modes the denominator describes different mapped coordinates, not a controlled quality score.

Look down PC1 loads PCA yaw 90° and tilt zero. The widest direction disappears, while original retrieval stays fixed. Maximum-ratio pair searches unordered drawn pairs in vocabulary order: original Euclidean distance / max(raw projected distance, 10⁻⁶). The guard avoids division by zero; exact ratio ties retain the first pair. Below two words there is no pair. General-API missing truth identities fall back to drawn vectors. A maximum ratio need not exceed one. Pixel distance is separately labelled and never supplies the denominator.

What stays fixed in a comparison?

Camera changes hold original vocabulary/vectors, pin/operands, candidate set, exclusions and metric fixed. Changing the neighbour metric changes the mathematical query. Changing PCA/alternate mode changes display coordinates and scale, while original retrieval stays fixed. No centring or normalisation silently enters retrieval. No confidence, model prediction, accuracy, training improvement or generalisation is evaluated.

Elementary operations use JavaScript doubles. Hypot norms and scaled cosine reduce avoidable overflow. Compound covariance/PCA reject nonfinite operands and unsupported overflow. Ranking rejects nonfinite operands or nonfinite ranking scores; raw dot products and squared inspection terms can overflow even when scaled cosine remains finite. Tiny products can underflow; finite iterations and relative tolerance limit eigen resolution. Bounded UI data cannot exercise arbitrary extremes. Pure-API edge-case support is separate from editable UI capabilities.

How do sharing, reset and recovery work?

Stage return retains camera, mode, selected/pinned identities, metric, inspected vector and arithmetic prefix. Every experiment, selection, stage, sandbox or reveal edit clears prediction. Help/inspection/presentation/motion preserve it. Mark explored records local exploration, not assessment. No random seed action or playback exists.

Links store display stage, selected/pinned indices, metric, map, inspected vector, arithmetic prefix and exact embYaw/embPitch angles. Shared seed is fixed inert infrastructure. Links open guided and recompute outputs; guesses, recovery, sandbox identity and local progress stay local. Invalid numeric controls fall back or clamp to supported ranges; imported identities resolve to bounded vocabulary indices.

Reset controls defaults the experiment at the current guided stage, enters guided and clears recovery/prediction. Clear steps rewinds only arithmetic disclosure. Failure recovery saves complete preceding experiment, stage, sandbox and prediction; Restore experiment recovers them after further edits. URL navigation clears local recovery and prediction. The two reveal steps are not a training history, and there is no asynchronous numerical process to play or cancel.

Stage recap

  1. Space and Similarity

    Twenty manually curated 3D vectors in three assigned groups. Select a word and inspect its original coordinates. Orbit using Yaw, Tilt or gridline drag; the picture is a different space.

  2. Nearest Neighbours

    Pin any word. Three neighbours and the full ranking use original vectors: highest cosine or smallest Euclidean distance, excluding the pinned identity. Exact ties retain vocabulary order.

  3. Semantic Arithmetic

    Fixed king − man + woman yields a new query vector. Reveal subtraction, then addition. Retrieve by cosine after excluding all operands. This toy construction is no proof of reasoning or universal identity axes.

  4. What the Lens Costs

    PCA View retains all three centred basis coordinates until the camera drops depth. Alternate View permutes/scales coordinates and shifts by group. Neither display chooses the retrieval result.

Reference

Vector
Three manually curated numbers per word; assigned groups and axes are design choices.
Cosine similarity
dot(A,B)/(norm(A) norm(B)); descending rank. Undefined at zero; this API returns numeric zero there.
Euclidean distance
sqrt(sum((A−B)²)); ascending rank. Magnitude and direction both matter.
Dot product
sum(A_i B_i). Equals cosine only for unit vectors; a scalar projection also divides by the receiving norm.
Rotation versus translation
Orthogonal linear maps preserve dot products and norms; translations preserve pair distances but can change origin-relative cosine.
Arithmetic
king−man=(0.1,1.5,0.1), then +woman=(−0.9,1.5,0.1). Queen is a retrieved item, not that exact vector.
PCA
Population covariance, deterministic symmetric Jacobi eigenpairs, full three-axis basis. Camera projection subsequently drops depth; no whitening.
Variance on screen
(Var(x_rot)+Var(y_rot))/(Var(x_rot)+Var(y_rot)+Var(depth)) in active mapped coordinates. Empty/constant uses sentinel one.
Maximum-ratio pair
Original Euclidean distance / max(raw projected distance, 1e−6), first pair on exact ties. Pixel distances are separate.

Break it on purpose

In PCA View, yaw 90 degrees and tilt zero hide the widest direction. Low visible variance and projected overlaps do not change original-space neighbours.