Module 6: Embedding Operations

Interpolation & Blending

Linear Interpolation

def interpolate(emb_a, emb_b, alpha=0.5):
    """Interpolate between 2 embeddings"""
    return alpha * emb_a + (1 - alpha) * emb_b

# Example
emb_cat = get_emb("cat")
emb_dog = get_emb("dog")

# Alpha = 0.5 → midpoint
emb_mid = interpolate(emb_cat, emb_dog, alpha=0.5)

# Find the closest concept
find_nearest(emb_mid)  # "pet", "animal"

Smooth Transitions

# Gradual transition
for alpha in [0.0, 0.25, 0.5, 0.75, 1.0]:
    emb = interpolate(emb_happy, emb_sad, alpha)
    nearest = find_nearest(emb)
    print(f"Alpha {alpha}: {nearest}")

# Output:
# Alpha 0.0: happy
# Alpha 0.25: cheerful
# Alpha 0.5: neutral
# Alpha 0.75: melancholy
# Alpha 1.0: sad

Applications

Content generation:

# Blending styles
emb_formal = get_emb("formal professional tone")
emb_casual = get_emb("casual friendly tone")

emb_balanced = interpolate(emb_formal, emb_casual, alpha=0.5)
# Use as a prompt embedding for generation

Summary

  • Interpolation: Semantic blending
  • Alpha: Blend control (0-1)
  • Use case: Smooth transitions, style blending

Module 6 - Capsule 03