DL
beginner
Text Representation (OHE, BOW, N-gram, TF-IDF, Word2Vec)
AI Engineer path · lesson 51 of 124Master ALL fundamental NLP techniques: One-Hot Encoding, Bag of Words, N-grams, TF-IDF, and Word2Vec (CBOW & Skip-gram). See how text becomes numbers!
Text Representation Techniques
Explore how words are converted to numbers for machine learning
Input Documents (one per line)
8 documents • 26 unique words
One-Hot Encoding (OHE)
Each word is represented as a binary vector with 1 at its vocabulary position, 0 elsewhere. Vector dimension = vocabulary size (26).
"a"
→1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
"and"
→0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
"are"
→0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
"crown"
→0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
"delicious"
→0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
"eating"
→0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
"fruits"
→0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
"guava"
→0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...showing first 8 words of 26 total
Key Properties:
- Sparse: Only 1 non-zero value per vector (99%+ zeros for large vocab)
- No semantic meaning: "king" and "queen" are equally distant
- High dimensional: Vocabulary size = vector dimension
- Used in: Categorical features, simple classification
Technique Comparison
| Technique | Dimension | Sparsity | Semantics | Best For |
|---|---|---|---|---|
| OHE | |Vocab| | Extremely Sparse | None | Categorical features |
| BOW | |Vocab| | Very Sparse | None | Document classification |
| N-grams | up to |Vocab|^N (in practice, # of observed N-grams) | Extremely Sparse | Local context | Text generation, LMs |
| TF-IDF | |Vocab| | Sparse | Importance | Search, similarity |
| Word2Vec | 100-300 | Dense | Rich semantics | Modern NLP, transfer learning |
NLP
Text Representation
Feature Engineering
Embeddings
Fundamental
Order by how much meaning is kept
Sequence
Order these representations from least semantic to most.
Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.
- 1Drop a step here
- 2Drop a step here
- 3Drop a step here
- 4Drop a step here
4 pieces left to place
Test your knowledge
20 questions
Question 1 of 20
Score: 0
What is One-Hot Encoding?
Interview Questions
Amazon
Elastic
Pinterest
Yahoo
Grammarly
Hugging Face
Spotify
Apple
SoundCloud
Hugging Face
Cohere
Elastic
Grammarly
Duolingo
Meta
References & Further Reading
Love this visualization?
Sign up to track your progress, earn achievements, use the AI assistant, and access your personal learning dashboard.
100% free • No credit card required