Word Embeddings (Word2Vec, GloVe)

ब हम Natural Language Processing (NLP) का एक बहुत ही महत्वपूर्ण विषय सीखते हैं —
🧠 Word Embeddings, जो deep learning-based NLP की नींव रखते हैं।


🔶 1. Word Embeddings क्या हैं?

Word Embeddings वो तकनीक है जिससे शब्दों को संख्याओं (vectors) में represent किया जाता है — इस तरह कि उनके semantic (meaningful) रिश्ते भी capture हों।

🎯 “Word Embeddings words को mathematical space में ऐसे map करते हैं कि उनके बीच के अर्थ संबंध भी साफ़ दिखें।”


🧠 क्यों ज़रूरी हैं?

Traditional NLP methods जैसे One-Hot Encoding सिर्फ पहचानते हैं कि कोई शब्द है या नहीं — लेकिन वो शब्दों के अर्थ या संबंध को नहीं समझते।

Techniqueसमस्या
One-HotHigh dimensional, sparse, no meaning
EmbeddingDense, low-dimensional, meaningful representation

📏 2. Embedding Vector कैसा होता है?

Word → Vector (जैसे 300 dimensions का dense vector):

WordVector (छोटा version)
king[0.25, 0.67, …, 0.12]
queen[0.23, 0.65, …, 0.14]
banana[0.10, 0.32, …, 0.91]
democracy[0.55, 0.40, …, 0.60]

👉 Words जो अर्थ में करीब होते हैं, उनके vectors भी पास होते हैं।


📊 3. Word2Vec

🧪 Developed By:

Google (2013) — Tomas Mikolov et al.

⚙️ Idea:

  • शब्दों के context के आधार पर embedding सीखना।
  • “You shall know a word by the company it keeps.”

🔁 Two Architectures:

Architectureकार्य
CBOW (Continuous Bag of Words)Nearby words से center word predict करता है
Skip-GramCenter word से आसपास के words predict करता है

🔍 Word2Vec Diagram:

[The] [king] [of] [Spain] → [rules]
↑ context → target

CBOW: Predict “rules”
Skip-Gram: Predict “The”, “king”, “Spain” ← “rules”


🧠 4. GloVe (Global Vectors)

🧪 Developed By:

Stanford (2014) — Jeffrey Pennington et al.

⚙️ Idea:

  • Word2Vec local context पर निर्भर करता है
  • GloVe पूरे corpus के co-occurrence matrix का उपयोग करता है

🧾 Objective:

Find word vectors so that: 

जहाँ Pij​ दो शब्दों के co-occurrence का ratio है।


🔍 Word2Vec vs GloVe

AspectWord2VecGloVe
ContextLocal windowGlobal corpus statistics
TypePredictiveCount-based
TrainingFasterSlower (matrix-based)
AccuracyHighSlightly better for analogies
Use CaseFast semantic learningFine-grained vector space

🧪 5. Real Example: Word Analogy

king−man+woman≈queen

Word Embeddings में ये relation mathematically मिल जाता है! 🔥


🧰 6. Python Example (Gensim – Word2Vec)

from gensim.models import Word2Vec

sentences = [["I", "love", "deep", "learning"],
["Word2Vec", "captures", "semantic", "meaning"]]

model = Word2Vec(sentences, vector_size=50, window=2, min_count=1, sg=1)
print(model.wv["deep"]) # Embedding vector
print(model.wv.most_similar("learning"))

📌 7. Pretrained Embedding Sources

EmbeddingSource
GloVehttps://nlp.stanford.edu/projects/glove/
Word2Vechttps://code.google.com/archive/p/word2vec/
FastTexthttps://fasttext.cc/
BERT EmbeddingsHuggingFace (transformers library)

📈 8. Applications

Use CaseHow Embeddings Help
🗣️ ChatbotsWords with similar meanings treated similarly
📝 Sentiment Analysis“bad” vs “awful” को पहचानना
🔁 TranslationSemantic similarity across languages
💬 Q&A SystemsUnderstanding user intent

📝 Practice Questions:

  1. Word Embeddings क्या होते हैं?
  2. Word2Vec के दो architecture कौन-कौन से हैं?
  3. GloVe और Word2Vec में मुख्य अंतर बताइए।
  4. एक embedding vector की structure को समझाइए।
  5. Word analogy कैसे काम करता है embedding space में?

🧠 Summary Table

TopicSummary
Word EmbeddingWords → meaningful vectors
Word2VecLearns from local context (CBOW, Skip-gram)
GloVeLearns from global co-occurrence
AdvantageSemantic similarity capture करना
ApplicationChatbots, translation, classification