What Is Embedding?
Background # In the field of natural language processing (NLP), encoding words into numerical representations—so they can be fed into mathematical models—is an essential consideration:
- Index Encoding: Integer encoding; fails to capture relationships among features.
- Drawbacks of One-Hot Encoding:
- For categorical variables with a very large number of distinct values, the resulting vector dimensionality becomes excessively high and the vectors become extremely sparse.
- Mappings are entirely independent and cannot reflect relationships among different categories.
What Is Embedding? # Embedding is the process of converting positive integers (index values) into fixed-size, dense vectors<sup>2</sup>. This sentence comes from the Keras documentation’s description of the Embedding layer—it is highly concise and not immediately intuitive, yet it accurately summarizes the purpose.
For example, the sentence “I love China” corresponds to the index sequence [0, 1, 2, 3]. Instead of representing this using sparse one-hot encoding, embedding converts it into a fixed-size, dense vector representation—for instance: [[0.2, 0.5], [0.6, -0.1], [0.8, 0.4], [0.5, 0.5]].
Word embeddings typically range from 8 to 1024 dimensions, adjusted according to dataset size. Higher-dimensional embeddings better capture relationships among words but require more data for training.
How Is Embedding Implemented? # It is implemented via the Embedding layer. The Embedding layer can be viewed as a lookup table mapping indices to dense vectors. When used, its weights—like those of other neural network layers—are randomly initialized. During training, the Embedding layer’s weights are progressively adjusted via backpropagation, guided by the specific task objective.
The internal structure of the Embedding layer is a weight matrix of shape [vocabulary_size, embedding_dim], which functions as the lookup table. Its input consists of integer indices; the corresponding rows in the weight matrix constitute the word embeddings. The first half of the skip-gram model is precisely such word embedding.
For example, in TensorFlow, when building a sentence classification model, the Embedding layer takes integer indices as input. After passing through the Embedding layer, a pooling layer, and a fully connected layer—and undergoing training—the learned weights of the Embedding layer constitute the word embeddings.
embedding_dim = 16
model = Sequential([
vectorize_layer,
Embedding(vocab_size, embedding_dim, name="embedding"),
GlobalAveragePooling1D(),
Dense(16, activation='relu'),
Dense(1)
])
Applications # The most common application is word embedding. However, everything can be embedded. When input data lacks a suitable representation, Embedding transforms it—according to the downstream task—into learnable, high-dimensional vector representations. Examples include words, images, or spatial positions.
For instance, images from the MNIST dataset (10,000 × 784) can be represented via an Embedding layer, as shown in the figure below. Each point represents one image. The Embedding layer converts raw pixel values into dense vectors; subsequent dimensionality reduction (e.g., using t-SNE or PCA) reveals the spatial distribution of images. (generated by Copilot)
In feature engineering, capturing spatial (or temporal) dimensions is often challenging. By leveraging deep learning embedding layers—and feeding sequences of user behaviors (represented as indices) into the model—we can effectively encode such spatial dimensions.
My blog will soon be synchronized to Tencent Cloud Developer Community. You’re invited to join us: https://cloud.tencent.com/developer/support-plan?invite_code=2cy4t3peazy8s
Word embeddings | Text | TensorFlow ↩︎ Embedding Layer — Keras Chinese Documentation ↩︎
소스
Original article: https://youngforever.tech/posts/20230222-embedding/


Quick answers
What does this translated article cover?
## What Is Embedding? Background # In the field of natural language processing (NLP), encoding words into numerical representations—so they can be fed into mathematical models—is an essential consideration: 1. Inde
Who is this guide for?
This is an intermediate guide for readers who want a documented workflow, not a generic list of tools.
Where can I verify the steps?
Use the source and evidence links on this page, then check the official documentation before applying the workflow to production.
Sources and evidence
- sourceOriginal Chinese article: Embedding是什么?Open
This is a source-checked guide, not a claim of a full hands-on test unless a test is recorded above.