Word embedding

Also known as: word vectors

On this page 7

A word embedding is a dense, real-valued vector that represents a word in a continuous space of typically 100 to 1,000 dimensions, learned so that words appearing in similar contexts receive similar vectors. In speech & language AI, word embeddings, also called word vectors, are the bridge between discrete symbols and the numeric inputs that neural networks require.

The idea rests on the distributional hypothesis: words that occur in the same contexts tend to have related meanings. Methods such as word2vec, GloVe and fastText turned this hypothesis into efficient training procedures around 2013 to 2016, and their success made pretrained embeddings a standard component of natural language processing before contextual models took over many tasks.

How word embeddings are learned

Word embeddings are learned by optimizing a prediction or reconstruction objective over a large text corpus, and the vectors are a by-product of that optimization. Each word starts with a random vector; training adjusts the vectors so that the model predicts context words, or reproduces co-occurrence statistics, as accurately as possible.

Two families dominate. Predictive models such as the skip-gram and continuous bag-of-words variants of word2vec slide a window over text and predict neighbors from a center word or the reverse, using negative sampling to avoid a costly softmax over the full vocabulary. Count-based models such as GloVe first build a global co-occurrence matrix and then factorize it, fitting vector dot products to the logarithm of co-occurrence counts.

The table below compares the best-known static embedding methods.

MethodTraining signalDistinctive property
word2vec skip-gramPredict context words from a center wordStrong on rare words, efficient with negative sampling
word2vec CBOWPredict a center word from its contextFaster training, slightly weaker on rare words
GloVeFit global co-occurrence log countsUses corpus-wide statistics directly
fastTextSkip-gram over character n-gramsBuilds vectors for unseen and misspelled words
Latent semantic analysisSingular value decomposition of a term matrixOlder, linear, interpretable dimensions
Major static word embedding methods

Geometry of the vector space

The usefulness of word embeddings comes from the geometry they encode: distance and direction in the space reflect linguistic relations. Similarity is usually measured with cosine similarity, which compares vector directions and ignores length, because vector length correlates with word frequency.

The famous analogy result, in which king minus man plus woman lies near queen, shows that some relations appear as approximately parallel offsets. Such analogies work best for frequent words and regular relations such as country to capital or verb tense; they fail often enough that they should be treated as an illustration rather than a reliable reasoning tool.

OperationWhat it measuresTypical use
Cosine similarityAngle between two vectorsFinding synonyms and related words
Nearest-neighbor searchClosest vectors to a queryQuery expansion and spelling suggestions
Vector offsetDifference between word pairsAnalogy tests and bias analysis
AveragingCentroid of several word vectorsCheap sentence or document representation
Common operations on word vectors

Dimensionality is a trade-off between capacity and data. Around 300 dimensions became a common default for general English corpora of billions of tokens; smaller corpora often work better with 50 to 100 dimensions, because larger vectors overfit sparse statistics.

Static and contextual embeddings

Classic word embeddings are static: each word type has exactly one vector regardless of the sentence. This means the word bank receives the same representation in a river context and in a financial context, which merges distinct senses into one point.

Contextual models such as ELMo and transformer encoders produce a different vector for every occurrence, computed from the surrounding sentence. The comparison below explains when each kind fits.

AspectStatic word embeddingContextual embedding
Vectors per wordOne per vocabulary entryOne per occurrence in context
Polysemy handlingSenses are blendedSenses are separated by context
Compute costSimple table lookupFull neural network pass
Memory footprintTens to hundreds of megabytesHundreds of megabytes to gigabytes
Best fitLightweight search, features, analysisAccuracy-critical language understanding
Static versus contextual word representations

Static vectors remain relevant because they are fast, small and transparent. They are widely used for low-resource languages, for on-device applications, for linguistic research and as the input layer that many larger models still learn as their first step.

Using word embeddings in applications

In practice, teams either load pretrained vectors or train embeddings on their own domain corpus. Pretrained vectors cover general vocabulary well, while domain training captures specialist terms such as drug names, legal phrases or product codes.

  • Feature input: initializing the embedding layer of a text classifier or named entity recognition model.
  • Semantic search: matching queries to documents that use different but related words.
  • Speech systems: rescoring speech-to-text hypotheses with semantic plausibility.
  • Lexical resources: discovering synonyms and new terminology in large collections.
  • Bias auditing: measuring social stereotypes encoded in corpus statistics.

Evaluation combines intrinsic tests, such as word similarity benchmarks and analogy sets, with extrinsic tests on the downstream task. Intrinsic scores correlate only loosely with application performance, so the downstream metric should decide which vectors to deploy.

Limitations and risks

Word embeddings inherit the statistics and prejudices of their training text. Studies have repeatedly shown gender and ethnic stereotypes in standard vectors, for example occupations aligned with gendered directions, which can propagate into hiring or recommendation systems if left unchecked.

Other limitations are technical. Word-level models cannot represent out-of-vocabulary words unless they use subword units, they struggle with negation and compositional meaning, and antonyms often appear close together because they share contexts. A common mistake is reading high cosine similarity as synonymy, when it frequently signals only topical relatedness.

Understanding it simply

A word embedding gives each word a position on a huge invisible map. Words that are used in similar ways end up near each other. Cat lands close to dog. Coffee lands close to tea.

The computer learns this map by reading enormous amounts of text. It notices which words keep the same company. Once the map exists, the computer can measure how related two words are simply by checking the distance between them.

Applied in practice

A support team at a regional telecom operator receives about 8,000 customer messages per day and wants to route them automatically to billing, technical support or contract departments. Customers describe the same problem in many ways, such as no signal, dead line or cannot connect.

The data science group trains fastText embeddings of 300 dimensions on two years of anonymized support tickets, so that local slang, abbreviations and frequent misspellings receive meaningful vectors. A lightweight classifier then uses averaged message vectors as input.

Compared with the previous keyword rules, the embedding-based router raises correct routing from about 71 percent to about 88 percent on a held-out month of messages. It runs on a standard CPU server in a few milliseconds per message, and agents spend noticeably less time forwarding tickets between departments.