https://github.com/bdr-pro/embeddings-similarity
Sentence Embedding Similarity Visualizer (Manim)
https://github.com/bdr-pro/embeddings-similarity
Last synced: 9 days ago
JSON representation
Sentence Embedding Similarity Visualizer (Manim)
- Host: GitHub
- URL: https://github.com/bdr-pro/embeddings-similarity
- Owner: BDR-Pro
- License: mit
- Created: 2025-05-27T08:41:17.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-28T10:49:25.000Z (about 1 year ago)
- Last Synced: 2025-07-02T12:49:49.594Z (about 1 year ago)
- Language: Jupyter Notebook
- Size: 400 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ๐ง Sentence Embedding Similarity (Local)
This simple Python script uses `sentence-transformers` to compute and visualize sentence embeddings and their cosine similarity.
[Colab Ipynb](https://colab.research.google.com/drive/1Mz-QT4492QJEqH3-cxpR7KbowucRGi8H?usp=sharing)
## ๐ Features
- Loads a small, efficient embedding model: `all-MiniLM-L6-v2`
- Encodes a set of example sentences into dense vector embeddings
- Computes **pairwise cosine similarity matrix**
- Performs a **semantic search** for the most similar sentences to a query
- Outputs a ranked list of closest matches
## ๐ Run Instructions
### 1. Install Dependencies
```bash
pip install sentence-transformers scikit-learn pandas
````
### 2. Run the Script
```bash
python sentence_similarity.py
```
Or use a Jupyter Notebook if you're working interactively.
## ๐งพ Output Example
Example query:
```
"Hot pizza from the oven"
```
Top similar sentences:
```
A pizza is baking in the oven (score: 0.57)
The oven is very hot (score: 0.47)
I like pizza (score: 0.37)
```
## ๐ Pairwise Similarity Matrix (visual in notebook)
| | I like pizza | The dog... | A pizza... | He enjoys... | The oven... | She loves... |
| ------------ | ------------ | ---------- | ---------- | ------------ | ----------- | ------------ |
| I like pizza | 1.000 | 0.057 | 0.409 | ... | 0.244 | 0.284 |
| ... | ... | ... | ... | ... | ... | ... |
Styled with a blue gradient using Pandas.
## ๐ก Notes
* This is a fully **local** setup โ no API or external service calls
* Uses cosine similarity to reflect **semantic closeness** of sentences
* Useful for quick NLP prototyping or exploring sentence relationships
## ๐ Sentence Embedding Similarity Visualizer (Manim)
This project visualizes **cosine similarity** between sentence embeddings using the [Manim](https://docs.manim.community/) animation engine.
## ๐ฏ Features
- Shows sentence vectors as arrows in 2D space
- Animates sentence labels
- Annotates cosine similarity between selected vectors
- Uses **precomputed cosine similarity** (no model required)
## ๐ ๏ธ Requirements
```bash
pip install manim
````
(Use a virtualenv if needed)
## ๐ Run
```bash
python -m manim -pql embeddings.py VisualizeCosineSimilarity
```
* `-pql`: Preview in low quality (for faster rendering)
* You can also use `-pqh` for high quality or `-qm` for medium
## ๐ง How It Works
* Positions of arrows are **manually defined** to reflect semantic similarity visually
* Cosine similarity is precomputed and displayed during the animation
* No need to load or compute SentenceTransformer models at runtime
## ๐งพ Example Output
Youโll see 6 arrows, each representing a sentence like:
```
I like pizza
The oven is very hot
She loves climbing rocks
...
```
And similarity score annotations like:
```
cosine = 0.41
```
## ๐ Files
* `embeddings.py`: Manim animation script
* `README.md`: You are here
## ๐งฉ To Extend
* Animate angles using `Angle()` in Manim
* Import sentence embeddings and do PCA live
* Add fade-in comparisons or a slider over time
---
MIT License โ Use and modify freely!