File size: 1,612 Bytes
164f469
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Text Embedding Visualizer

This project generates embeddings for short sentences and visualizes them in 2D using PCA and t-SNE.  
It works on **both CPU and GPU laptops** with the same dependencies.

## Install
```bash

## create a virtual environment 

python -m venv venv

## activate the venv

source ./venv/bin/activate  # Windows: ./venv/Scripts/activate



pip install -r requirements.txt



***How it Works***

## Loads a small dataset of sentences.

## Generates embeddings with all-MiniLM-L6-v2.

## Reduces dimensions using PCA and t-SNE.

## Visualizes them on a 2D plot.





## Example Output



When running the script, you will see:

followed by **two interactive plots**:



1. **PCA Visualization**

   - Each dot represents a sentence.

   - Sentences with similar meaning appear closer together.

   - Example:  

     - "The Eiffel Tower is in France"  

       and "The capital of France is Paris"  

       are positioned near each other.



2. **t-SNE Visualization**

   - Another dimensionality reduction method that shows natural clusters.

   - Example:

     - "Cats are amazing pets" and "Dogs are loyal companions"  

       appear together in one cluster, away from unrelated topics.



The plots help you **see how AI models understand meaning** in text.



---



## Sample Sentences Used

- Artificial intelligence is transforming the world.

- Cats are amazing pets.

- The capital of France is Paris.

- The Eiffel Tower is in France.

- Deep learning enables image recognition.

- Dogs are loyal companions.

- The sun rises in the east.

- The moon orbits the Earth.