Weighted embedding blending

From wenmin-wu/ds-skills · View interactive version

Weighted embedding blending is an AI agent skill from the GitHub repository wenmin-wu/ds-skills. Ensemble predictions from heterogeneous vision-language models by blending their output embeddings with fixed scalar weights in embedding space

How to use this skill

Skill file

Weighted Embedding Blending

Overview

When multiple models produce embeddings for the same input (e.g., CLIP k-NN, BLIP interrogator, fine-tuned ViT), blending their output embeddings with scalar weights is a simple yet effective ensemble. Unlike logit averaging, embedding blending works in the target space directly — each model's contribution is weighted and summed before submission.

Quick Start

import numpy as np

# Embeddings from three different models (shape: [n_samples, embed_dim])
emb_knn = predict_knn(images)       # CLIP k-NN regression
emb_blip = predict_blip(images)     # BLIP/CLIP interrogator + SentenceTransformer
emb_vit = predict_vit(images)       # Fine-tuned ViT regression head

w_knn, w_blip, w_vit = 0.60, 0.15, 0.25
blended = w_knn * emb_knn + w_blip * emb_blip + w_vit * emb_vit

Workflow

  1. Generate embeddings from each model independently
  2. Ensure all embeddings share the same dimensionality and target space
  3. L2-normalize each model's output before blending (prevents scale dominance)
  4. Apply fixed scalar weights that sum to 1.0
  5. Optionally tune weights on a validation set using grid search or Nelder-Mead

Key Decisions

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.