Data & Feature Engineering

Using Embeddings as Features

Extracting pre trained continuous dense vector representations to represent complex text, images, and graph entities in downstream models.

🟡 intermediate5 min readfeaturesembeddings
Using Embeddings as Features utilizes pre trained dense vector representations as inputs for downstream machine learning models. Instead of engineering manual features from complex data like text, images, or graph nodes, pre trained deep learning models compress complex entities into continuous dense vectors. These embedding features capture high level semantic relationships and transfer learning knowledge for tabular classifiers and ranking models.

What Are Embedding Features?

High-dimensional unstructured data (text documents, images, audio clips, user interaction graphs) cannot easily be fed into traditional tabular models like XGBoost.

Instead of writing manual rules or calculating basic statistics, we pass unstructured data through a Pre-Trained Deep Learning Backbone to extract a continuous Dense Vector Embedding ($d = 128 \text{ to } 768$ dimensions).

Unstructured Input (Text / Image / Graph Entity)
                       │
                       ▼
  [ PRE-TRAINED BACKBONE MODEL (BERT / ResNet / Node2Vec) ]
                       │
                       ▼
  Dense Feature Vector e = [0.14, -0.82, 0.45, ..., 0.08]
                       │
                       ▼
  Passed as Input Features to Downstream Model (XGBoost / Logistic Reg)

3 Core Sources of Embedding Features

┌──────────────────────────┬──────────────────────────┬──────────────────────────┐
│ 1. TEXT EMBEDDINGS       │ 2. VISION EMBEDDINGS     │ 3. GRAPH EMBEDDINGS      │
├──────────────────────────┼──────────────────────────┼──────────────────────────┤
│ Sentence Transformers /  │ ResNet / Vision          │ Node2Vec / GraphSAGE     │
│ OpenAI Embeddings.       │ Transformer activations. │ graph node embeddings.   │
│ Captures document topic  │ Captures visual style    │ Captures social graph    │
│ and semantic intent!     │ and object features!     │ network connections!     │
└──────────────────────────┴──────────────────────────┴──────────────────────────┘

Pooling Sequences into Fixed Features

When an entity consists of multiple embeddings (for example a user who clicked 5 product items), how do we represent the sequence as a single feature vector?

Common Pooling Strategies:

  1. Mean Pooling: Take the element-wise average across item vectors:

$$\mathbf{e}{\text{user}} = \frac{1}{K} \sum{i=1}^K \mathbf{e}_{\text{item}_i}$$

  1. Max Pooling: Take the element-wise maximum across dimensions to capture peak interest signals.
  2. Attention Weighted Pooling: Weight recent item vectors higher than older item vectors using self-attention.

Frozen vs Fine-Tuned Embeddings

Say this out loud

Using embeddings as features extracts continuous dense vectors from pre trained deep learning backbones to represent text, images, or graph entities in downstream models. Sequence inputs are combined using mean or attention pooling. Frozen embeddings offer fast, cheap feature generation, while fine tuning updates embedding representations for maximum downstream accuracy.

Followups to expect

  1. How do you handle dimensionality reduction on 768-dim embeddings for GBDT models? Use Principal Component Analysis (PCA) or UMAP to compress 768-dimensional embeddings down to 32 or 64 dimensions before feeding them into Gradient Boosted Trees.
  2. What is Item2Vec? Applying Word2Vec skip-gram algorithms to user interaction sessions, treating item click sequences like sentences to learn item embedding representations.

Check yourself

Question 1 of 3

What primary benefit does using pre-trained embeddings as input features provide for downstream tabular machine learning models?

More in Data & Feature Engineering

See all →
Feature Engineering Fundamentals4 minSQL Questions in ML Interviews5 minEncoding Categorical Variables4 min