An interactive web application for computing and visualizing word embeddings using transformer models.
- Compute embeddings for words and sentences using
sentence-transformers/all-MiniLM-L6-v2 - Display raw embedding vectors (384 dimensions)
- Visualize embeddings in 2D using UMAP dimensionality reduction
- Interactive scatter plot showing semantic relationships
- Real-time updates as you add more inputs
- Clean, minimal UI with responsive design
┌─────────────────┐ ┌──────────────────┐
│ Frontend │ │ Backend │
│ (nginx) │────────▶│ (FastAPI) │
│ - HTML/JS │ HTTP │ - Transformers │
│ - Chart.js │ │ - UMAP │
└─────────────────┘ └──────────────────┘
:80 :8000
- Framework: FastAPI
- Package Manager: UV (modern Python package manager)
- Model: sentence-transformers/all-MiniLM-L6-v2 (384-dim embeddings)
- Dimensionality Reduction: UMAP
- Storage: In-memory (no database required)
- Tech: Vanilla JavaScript, Chart.js
- Server: nginx
- Features: Interactive form, real-time plot updates, embedding display
- Docker
- Docker Compose
- Clone this repository
- Navigate to the project directory
- Start the application:
docker-compose up --build- Open your browser and go to
http://localhost - Enter words or sentences to see their embeddings visualized!
The first startup will take a few minutes as it downloads the transformer model (~90MB).
docker-compose down- Enter Text: Type a word or sentence in the input box
- Compute: Click "Compute Embedding" or press Enter
- View Results:
- See the embedding vector (first 10 dimensions shown)
- Watch the 2D plot update with the new point
- Add More: Keep adding words/sentences to see relationships
Try these to see semantic clustering:
- "cat", "dog", "puppy", "kitten"
- "king", "queen", "prince", "princess"
- "happy", "sad", "joyful", "depressed"
- "Paris", "France", "London", "England"
Health check endpoint
curl http://localhost:8000/healthCompute embedding for input text
curl -X POST http://localhost:8000/embed \
-H "Content-Type: application/json" \
-d '{"text": "hello world"}'Response:
{
"id": "uuid",
"text": "hello world",
"embedding": [0.123, -0.456, ...]
}Get all stored embeddings with 2D coordinates
curl http://localhost:8000/embeddingsResponse:
{
"count": 3,
"embeddings": [
{
"id": "uuid",
"text": "hello world",
"x": 1.23,
"y": -0.45,
"embedding": [...]
}
]
}The backend is now a UV-managed Python package:
cd backend
uv sync # Install dependencies
MODEL_NAME="sentence-transformers/all-MiniLM-L6-v2" uv run uvicorn embeddings_backend.main:app --reloadBackend will be available at http://localhost:8000
Simply open frontend/index.html in a browser, or use a local server:
cd frontend
python -m http.server 8080Frontend will be available at http://localhost:8080
Note: Update API_BASE_URL in app.js if running locally without Docker.
visualize-embeddings/
├── backend/ # UV-managed Python package
│ ├── src/
│ │ └── embeddings_backend/
│ │ ├── __init__.py
│ │ ├── main.py # FastAPI app and endpoints
│ │ ├── embedding_service.py # Transformer model wrapper
│ │ └── embedding_store.py # In-memory storage
│ ├── pyproject.toml # UV package configuration
│ ├── uv.lock # Locked dependencies
│ └── Dockerfile
├── frontend/
│ ├── index.html # UI layout and styling
│ ├── app.js # Frontend logic and API calls
│ └── Dockerfile
├── docker-compose.yml # Container orchestration
└── README.md
- Uses UMAP for projecting 384-dim embeddings to 2D
- Preserves local and global structure
- Random state fixed for reproducibility
- Handles edge cases (1 or 2 points)
- Embeddings stored as numpy arrays
- Singleton pattern for service instances
- No persistence (data lost on restart)
- Suitable for demo/exploration purposes
- Configured to allow all origins
- Suitable for development
- Consider restricting in production
- Data is not persisted (in-memory only)
- No authentication or user management
- Single-user experience
- Model cannot be changed without code modification
- Add database for persistence
- Support multiple models
- Download embeddings as CSV
- Similarity search functionality
- Clustering visualization
- Multi-user support with sessions
MIT
- Built with FastAPI
- Embeddings from sentence-transformers
- Visualization with Chart.js
- Dimensionality reduction using UMAP