jnalv/embedding-fingerprints
๐ Embedding Fingerprint Explorer
Turn word embeddings into visual "fingerprints," and explore semantic relationships. Each embedding dimension becomes a pixel โ similar words create similar patterns!
What is this?
This is a fun utility meant to educate people about embeddings!
Word embeddings capture semantic meaning as high-dimensional vectors (typically 384-1024 dimensions). This tool converts those abstract vectors into visual representations, turning each dimension into a pixel in a square, or a line on a heatmap.
This demonstrates a few interesting concepts:
- Words with high similarity scores share similar visual patterns.
- And dissimilar words look obviously different.
- Embeddings with more dimensions capture more semantic nuance, like the resolution of an image! The metaphor becomes literal!! ๐
Features
๐ Linear Heatmap
Compare embedding dimensions across multiple words. Each column is a word, each row is a dimension. Colors show activation levels (red=high, blue=low).
๐ผ๏ธ Square "Fingerprint"
Each word's embedding is reshaped into a square grid where each pixel represents one dimension. Similar words produce visually similar patterns - like fingerprints for meaning!
๐ฌ Comparison Matrix
Calculate and visualize cosine similarity scores between all word pairs. Values range from 0.0 (unrelated) to 1.0 (identical).
How to Use
- Select an embedding model from the dropdown (default:
all-MiniLM-L6-v2) - Enter words separated by commas or newlines:
happy, joyful, sad, angry- Or one word per line
- Click a visualization button to generate:
- Linear: Works with 1+ words
- Square: Works with 1+ words
- Compare: Requires 2+ words
- Try the quick examples for instant exploration!
Example Word Sets
- ๐ฏ Synonyms:
huge, enormous, big - โฏ๏ธ Closeness of antonyms:
cold, warm - โก Dissimilarity:
dog, metacarpus - โ๏ธ Polysemous averaging:
dog, bark, tree
Available Models
Models are downloaded from HuggingFace Hub on first use and cached automatically.
Tips
- Best results: Use 2-10 words for comparison
- Semantic relationships: Try related words (cat, kitten), contrasting concepts (hot, cold), or try for complete non sequiturs (unicycle, Wyomingite)
- Model selection: Smaller models are faster; larger models capture more nuance
- First load: The first time you select a model, it may take 5-30 seconds to download
โ ๏ธ Please Keep In Mind:
- Dimension interpretation: Individual pixels have no semantic meaning
- Spatial arrangement: Pixel position in grid is arbitrary
- Similarity is relative: "Similar" depends on model's training data
- Cultural bias: Models reflect biases in training data, eg. "doctor" being more similar to "male" than "female"
Key Design Decisions
Why These Models?
- all-MiniLM-L6-v2: Fast, lightweight, good general performance (default)
- all-mpnet-base-v2: Balanced accuracy/speed, strong sentence understanding
- bge-large-en-v1.5: State-of-the-art accuracy, larger dimensions (1024)
- bge-small-en-v1.5: Fast alternative to BGE-large
- paraphrase-multilingual: Supports 50+ languages
Why No 2D Projection?
Originally included t-SNE/PCA visualizations, but removed because:
- Requires 30+ words to show meaningful clusters
- Primary use case is 2-10 word comparisons
- Better suited as separate "Semantic Space Explorer" project (coming soon, maybe? ๐)
- Fingerprints and similarity matrices work better for small sets
Why Percentile Normalization?
After testing, percentile clipping (2nd-98th) provides best balance:
- Reduces impact of extreme outlier dimensions
- Preserves relative differences in mid-range
- Creates crisper visual patterns than linear normalization
- Less aggressive than histogram equalization
Why Matplotlib โ PIL โ Gradio?
Gradio's native matplotlib support is limited. Converting to PIL Images:
- Ensures consistent rendering across browsers
- Enables right-click save functionality
- Provides better resolution control (150 DPI)
- Avoids interactive plot complications
Technical Details
- Built with Gradio
- Uses sentence-transformers for embeddings
- Visualizations created with matplotlib and seaborn
- Similarity calculations via scikit-learn
License
MIT License - feel free to use, modify, and share!
Acknowledgments
- Sentence-Transformers library by UKP Lab
- HuggingFace for model hosting
- Gradio for the UI framework
- All embedding model creators
