टेक्स्ट डेटा का एन्कोडिंग

PyTorch के साथ टेक्स्ट के लिए डीप लर्निंग

Shubham Jain

Data Scientist

टेक्स्ट एन्कोडिंग

Pytorch प्रोसेसिंग पाइपलाइन

  • टेक्स्ट को मशीन-पढ़ने योग्य नंबरों में बदलें
  • विश्लेषण और मॉडलिंग सक्षम करें

इनसाइट्स के लिए सीक्वेंशियल डेटा इमेज

PyTorch के साथ टेक्स्ट के लिए डीप लर्निंग

एन्कोडिंग तकनीकें

  • One-hot encoding: शब्दों को यूनिक न्यूमेरिकल रिप्रेजेंटेशन में बदलता है
  • Bag-of-Words (BoW): क्रम को नज़रअंदाज़ कर शब्द आवृत्ति पकड़ता है
  • TF-IDF: विशिष्टता और महत्त्व का संतुलन करता है
  • Embedding: शब्दों को वेक्टर में बदलता है, सिमेंटिक अर्थ कैप्चर करता है (Chapter 2)
PyTorch के साथ टेक्स्ट के लिए डीप लर्निंग

One-hot encoding

  • हर शब्द को अलग वेक्टर से मैप करना
  • बाइनरी वेक्टर:
    • शब्द की उपस्थिति पर 1
    • शब्द की अनुपस्थिति पर 0
  • ['cat', 'dog', 'rabbit']
    • 'cat' [1, 0, 0]
    • 'dog' [0, 1, 0]
    • 'rabbit' [0, 0, 1]
PyTorch के साथ टेक्स्ट के लिए डीप लर्निंग

PyTorch के साथ One-hot encoding

import torch
vocab = ['cat', 'dog', 'rabbit']

vocab_size = len(vocab)
one_hot_vectors = torch.eye(vocab_size)
one_hot_dict = {word: one_hot_vectors[i] for i, word in enumerate(vocab)}
print(one_hot_dict)
{'cat': tensor([1., 0., 0.]),
  'dog': tensor([0., 1., 0.]),
  'rabbit': tensor([0., 0., 1.])}
PyTorch के साथ टेक्स्ट के लिए डीप लर्निंग

Bag-of-words

  • उदाहरण: "The cat sat on the mat"
  • Bag-of-words:
    • {'the': 2, 'cat': 1, 'sat': 1, 'on': 1, 'mat': 1}
  • हर डॉक्यूमेंट को बिना क्रम वाले शब्दों के संग्रह की तरह मानना
  • frequency पर फोकस, क्रम पर नहीं
PyTorch के साथ टेक्स्ट के लिए डीप लर्निंग

CountVectorizer

from sklearn.feature_extraction.text import CountVectorizer

vectorizer = CountVectorizer()
corpus = ['This is the first document.', 'This document is the second document.', 'And this is the third one.', 'Is this the first document?']
X = vectorizer.fit_transform(corpus)
print(X.toarray())
print(vectorizer.get_feature_names_out())
[[0 1 1 1 0 0 1 0 1]
 [0 2 0 1 0 1 1 0 1]
 [1 0 0 1 1 0 1 1 1]
 [0 1 1 1 0 0 1 0 1]]

['and' 'document' 'first' 'is' 'one' 'second' 'the' 'third' 'this']
PyTorch के साथ टेक्स्ट के लिए डीप लर्निंग

TF-IDF

  • Term Frequency-Inverse Document Frequency
    • किसी डॉक्यूमेंट में शब्दों के महत्त्व को स्कोर करता है
    • कम मिलने वाले शब्दों का स्कोर अधिक होता है
    • आम शब्दों का स्कोर कम होता है
    • सूचनात्मक शब्दों को उभारता है
PyTorch के साथ टेक्स्ट के लिए डीप लर्निंग

TfidfVectorizer

from sklearn.feature_extraction.text import TfidfVectorizer
vectorizer = TfidfVectorizer()

corpus = ['This is the first document.','This document is the second document.', 'And this is the third one.','Is this the first document?']
X = vectorizer.fit_transform(corpus)
print(X.toarray())
print(vectorizer.get_feature_names_out())
[[0.         0.         0.68091856 0.51785612 0.51785612 0.        ]
 [0.         0.         0.          0.51785612 0.51785612 0.68091856]
 [0.85151335 0.42575668 0.         0.32274454 0.32274454 0.        ]
 [0.         0.         0.68091856 0.51785612 0.51785612 0.        ]]

['and' 'document' 'first' 'is' 'one' 'second']
PyTorch के साथ टेक्स्ट के लिए डीप लर्निंग

TfidfVectorizer

TFIDF कोड

PyTorch के साथ टेक्स्ट के लिए डीप लर्निंग

एन्कोडिंग तकनीकें

तकनीकें: One-hot encoding, bag-of-words, और TF-IDF

  • मॉडल्स को टेक्स्ट समझने और प्रोसेस करने में मदद करता है
  • अनावश्यक दोहराव से बचने के लिए एक तकनीक चुनें
  • और भी तकनीकें मौजूद हैं
PyTorch के साथ टेक्स्ट के लिए डीप लर्निंग

अभ्यास करते हैं!

PyTorch के साथ टेक्स्ट के लिए डीप लर्निंग

Preparing Video For Download...