Averaged meta embedding

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

Averaged meta embedding is an AI agent skill from the GitHub repository wenmin-wu/ds-skills. Element-wise average of multiple pretrained embedding matrices as a parameter-free meta-embedding

How to use this skill

Skill file

Overview

Concatenating embedding matrices (GloVe + Paragram + FastText) doubles or triples the input dimension, inflating model size. An unweighted mean of the matrices — Dynamic Meta Embedding (DME) — preserves the original dimension while combining the semantic signal from each source. It's parameter-free, adds no inference cost, and often performs comparably to weighted blends.

Quick Start

import numpy as np

def load_glove(word_index, embed_size):
    # ... returns (vocab_size, embed_size)
    ...

def load_paragram(word_index, embed_size):
    # ... returns (vocab_size, embed_size)
    ...

embedding_matrix_1 = load_glove(word_index, 300)
embedding_matrix_2 = load_paragram(word_index, 300)

# Unweighted DME: element-wise mean, same shape as inputs
embedding_matrix = np.mean([embedding_matrix_1, embedding_matrix_2], axis=0)
# Shape: (vocab_size, 300) — NOT (vocab_size, 600)

Workflow

  1. Build embedding matrices from each pretrained source using the same word→index mapping
  2. Stack them and take np.mean(..., axis=0) — result has the same shape as each source
  3. Pass the averaged matrix to your Embedding layer
  4. Train the model normally — no special architecture changes required

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.