Nestor G Pestelos Jr · Reference · Print this page
Embeddings
Published September 3, 2026 · Machine Learning & Representation Theory
Vector embeddings are dense numerical representations of discrete entities (such as tokens, sentences, code, or images) in a continuous high-dimensional vector space. By projecting discrete concepts into continuous geometries, embeddings enable machine learning models to quantify semantic similarity, capture associative analogies, and conduct sub-linear nearest neighbor retrieval across massive corpora.
1. Theoretical Motivation
In classical computational linguistics, words were treated as atomic symbols represented by orthogonal one-hot vectors [1]. In a vocabulary of size \(|V|\), each word \(w_i\) is represented by a vector \(\mathbf{x}_i \in \{0, 1\}^{|V|}\) where exactly one entry is 1 and all others are 0. This formulation exhibits two fundamental flaws:
- Dimensional curse: The dimensionality grows linearly with vocabulary scale, requiring tens or hundreds of thousands of sparse dimensions.
- Orthogonal isolation: Every one-hot vector is completely orthogonal to every other: \(\mathbf{x}_i \cdot \mathbf{x}_j = 0\) for all \(i \neq j\). Consequently, the representation cannot capture that "physician" and "doctor" share semantic meaning, while "physician" and "submarine" do not.
Modern representation learning addresses this limitation through the distributional hypothesis, formulated by linguist J.R. Firth in 1957: "You shall know a word by the company it keeps" [2]. Dense vector embeddings map discrete vocabulary items into a low-dimensional continuous manifold \(\mathbb{R}^d\) (where typically \(d \in [256, 4096]\)), such that words appearing in similar contextual distributions are positioned close to one another in latent geometric space.
2. Mathematical Formulation & Geometry
Given an input token index \(i \in \{1, \dots, |V|\}\), the embedding operation corresponds to a matrix lookup in an embedding weight matrix \(\mathbf{W}_E \in \mathbb{R}^{|V| \times d}\):
$$\mathbf{e}_i = \mathbf{W}_E^T \mathbf{x}_i$$where \(\mathbf{x}_i\) is the one-hot indicator vector for token \(i\), and \(\mathbf{e}_i \in \mathbb{R}^d\) is the resulting dense embedding.
Distance & Similarity Metrics
The semantic relationship between two embedded vectors \(\mathbf{u}, \mathbf{v} \in \mathbb{R}^d\) is quantified using geometric metrics in the embedding space:
- Dot Product: $$\langle \mathbf{u}, \mathbf{v} \rangle = \sum_{k=1}^d u_k v_k$$ Measures unnormalized directional alignment and vector magnitude.
- Cosine Similarity: $$\cos(\theta) = \frac{\mathbf{u} \cdot \mathbf{v}}{\|\mathbf{u}\|_2 \|\mathbf{v}\|_2}$$ Measures the cosine of the angle between vectors, normalizing for vector length. Widely preferred in text retrieval because document length variations do not distort thematic alignment.
- Euclidean Distance (\(L_2\)): $$\|\mathbf{u} - \mathbf{v}\|_2 = \sqrt{\sum_{k=1}^d (u_k - v_k)^2}$$ For \(L_2\)-normalized vectors (\(\|\mathbf{u}\|_2 = \|\mathbf{v}\|_2 = 1\)), Euclidean distance relates directly to cosine similarity: \(\|\mathbf{u} - \mathbf{v}\|_2^2 = 2 - 2\cos(\theta)\).
Linear Substructure & Arithmetic
A seminal discovery in distributed representations is that continuous vector spaces encode analogical relationships as consistent directional offsets [3]. Relationships such as gender, grammatical tense, and capital-country associations emerge as stable translation vectors:
$$\mathbf{e}_{\text{king}} - \mathbf{e}_{\text{man}} + \mathbf{e}_{\text{woman}} \approx \mathbf{e}_{\text{queen}}$$This linear property demonstrates that training objectives based on word co-occurrence implicitly perform matrix factorization on point-wise mutual information (PMI) matrices [4].
3. Architectural Evolution
Static Word Embeddings
Early distributed representation frameworks produced static lookup tables where each vocabulary token mapped to a single fixed vector regardless of context:
- Word2Vec (2013): Mikolov et al. introduced Continuous Bag-of-Words (CBOW) to predict target words from context windows, and Continuous Skip-gram to predict surrounding context from target words using negative sampling [3].
- GloVe (2014): Pennington et al. trained vectors directly on global log-bilinear word co-occurrence statistics across whole corpora, combining the advantages of global matrix factorization with local window methods [5].
- FastText (2017): Bojanowski et al. extended embeddings to character \(n\)-grams, allowing models to generate out-of-vocabulary representations for unseen morphological variants [6].
Contextual Sequence Embeddings
Static embeddings fail on polysemy: the token "bank" received the exact same vector in "river bank" and "investment bank." Modern deep architectures produce dynamically contextualized embeddings where each token's vector is a function of the entire sequence:
- ELMo (2018): Bi-directional LSTMs generating layered representations based on sequence context [7].
- Transformer Encoders (BERT, 2019): Bidirectional multi-head self-attention generating deep, dynamically weighted token representations [8].
- Sentence Transformers (SBERT, 2019): Siamese neural networks trained with InfoNCE and multiple-negatives ranking loss to yield semantically meaningful whole-sentence pooling vectors [9].
Positional Encodings
Because the self-attention mechanism is inherently permutation-invariant, positional information must be added directly into token representations [10]:
- Absolute Sinusoidal Embeddings: Fixed frequencies using trigonometric functions across dimensions (original Transformer) [10].
- Rotary Position Embeddings (RoPE): Rotates query and key vectors in complex 2D subspaces based on token index, preserving relative distance decay without parameter inflation [11].
4. Geometric Pathologies: Anisotropy & Degeneration
A persistent challenge in deep language model representation is the anisotropy problem [12]. Rather than utilizing the full capacity of the \(d\)-dimensional hypersphere uniformly, learned token representations tend to collapse into a narrow, cone-shaped subspace. Consequently, arbitrary pairs of unrelated tokens often exhibit high positive cosine similarities (e.g. \(\cos > 0.7\)).
Remediations in modern embedding pipelines include:
- Mean-centering and whitening: Subtracting the empirical mean vector \(\boldsymbol{\mu}\) and transforming vectors by the inverse covariance matrix to restore isotropic distribution.
- Contrastive regularization: Incorporating InfoNCE losses that explicitly push negative pairs apart across the full geometric sphere during fine-tuning.
- Matryoshka Representation Learning (MRL): Structuring embeddings so that truncating a 1536-dimension vector down to 256 or 512 dimensions preserves the highest-variance semantic information with minimal recall loss.
5. Production Retrieval & Vector Indexing
In production applications such as Retrieval-Augmented Generation (RAG) and semantic search, systems query datasets containing millions or billions of embedding vectors. Exact \(k\)-nearest neighbor search via brute-force linear scanning requires \(O(N \cdot d)\) operations per query, which is computationally prohibitive at scale.
Production infrastructures deploy Approximate Nearest Neighbor (ANN) indexing structures:
- Hierarchical Navigable Small World (HNSW): Multi-layer geometric graphs providing logarithmic search complexity \(O(\log N)\) while preserving high recall [13].
- Inverted File with Product Quantization (IVF-PQ): Clusters vector space into Voronoi cells and quantizes sub-vectors into compressed codebooks, reducing RAM requirements by 80% to 95%.
See also
- ELI5: Embeddings · Visual picture-book explainer of word coordinates and distance metrics.
- Tokens and Tokenization · Discrete subword representation and vocabulary algorithms.
- Retrieval-Augmented Generation (RAG) · Grounding model generation on retrieved external context.
- Semantic Caching · Caching query results via embedding distance thresholds.
- Large Language Models · Foundational Transformer architectures and self-attention.
References
- [1] D. Jurafsky and J. H. Martin, Speech and Language Processing, 3rd ed. draft, Prentice Hall, 2024.
- [2] J. R. Firth, "A synopsis of linguistic theory 1930–1955," in Studies in Linguistic Analysis, Philological Society, Oxford, 1957, pp. 1–32.
- [3] T. Mikolov, K. Chen, G. Corrado, and J. Dean, "Efficient Estimation of Word Representations in Vector Space," in Proceedings of the International Conference on Learning Representations (ICLR), 2013. https://arxiv.org/abs/1301.3781
- [4] O. Levy and Y. Goldberg, "Neural Word Embedding as Implicit Matrix Factorization," in Advances in Neural Information Processing Systems (NeurIPS), vol. 27, 2014, pp. 2177–2185.
- [5] J. Pennington, R. Socher, and C. D. Manning, "GloVe: Global Vectors for Word Representation," in Proceedings of the 2014 Conference on Empirical Methods in Natural Language Processing (EMNLP), 2014, pp. 1532–1543. https://nlp.stanford.edu/pubs/glove.pdf
- [6] P. Bojanowski, E. Grave, A. Joulin, and T. Mikolov, "Enriching Word Vectors with Subword Information," Transactions of the Association for Computational Linguistics, vol. 5, pp. 135–146, 2017. https://arxiv.org/abs/1607.04606
- [7] M. E. Peters, M. Neumann, M. Iyyer, M. Gardner, C. Clark, K. Lee, and L. Zettlemoyer, "Deep Contextualized Word Representations," in NAACL-HLT, 2018, pp. 2227–2237. https://arxiv.org/abs/1802.05365
- [8] J. Devlin, M. Chang, K. Lee, and K. Toutanova, "BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding," in NAACL-HLT, 2019, pp. 4171–4186. https://arxiv.org/abs/1810.04805
- [9] N. Reimers and I. Gurevych, "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks," in EMNLP-IJCNLP, 2019, pp. 3982–3992. https://arxiv.org/abs/1908.10084
- [10] A. Vaswani, N. Shazeer, N. Parmar, J. Uszkoreit, L. Jones, A. N. Gomez, Ł. Kaiser, and I. Polosukhin, "Attention Is All You Need," in NeurIPS, 2017, pp. 5998–6008. https://arxiv.org/abs/1706.03762
- [11] J. Su, M. Ahmed, Y. Lu, S. Pan, W. Bo, and Y. Liu, "RoFormer: Enhanced Transformer with Rotary Position Embedding," Neurocomputing, vol. 568, p. 127063, 2024. https://arxiv.org/abs/2104.09864
- [12] B. Gao, Y. Song, S. Shen, et al., "Representation Degeneration Problem in Language Modeling," in ICLR, 2019. https://arxiv.org/abs/1907.12009
- [13] Y. A. Malkov and D. A. Yashunin, "Efficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs," IEEE Transactions on Pattern Analysis and Machine Intelligence, vol. 42, no. 4, pp. 824–836, 2018. https://arxiv.org/abs/1603.09320