शब्द आवृत्ति विश्लेषण
बधाई हो! आप अभी-अभी PyBooks से जुड़े हैं. PyBooks एक बुक रिकमेंडेशन सिस्टम बना रहा है और अपनी सिफारिशों को बेहतर करने के लिए वे टेक्स्ट में पैटर्न और ट्रेंड्स खोजना चाहते हैं.
शुरू करने के लिए, आप दिए गए टेक्स्ट में शब्दों की आवृत्ति समझेंगे और बहुत कम आने वाले शब्दों को हटाएँगे.
ध्यान दें कि वास्तविक दुनिया के डेटासेट आमतौर पर इस उदाहरण से बड़े होते हैं.
यह अभ्यास पाठ्यक्रम का हिस्सा है
PyTorch के साथ टेक्स्ट के लिए डीप लर्निंग
अभ्यास निर्देश
torchtextसेget_tokenizerऔरnltkलाइब्रेरी सेFreqDistइम्पोर्ट करें.- English के लिए टोकनाइज़र इनिशियलाइज़ करें और दिए गए
textको टोकनाइज़ करें. tokensका फ़्रीक्वेंसी डिस्ट्रीब्यूशन निकालें और लिस्ट कॉम्प्रिहेंशन का उपयोग करके दुर्लभ शब्द हटाएँ.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Import the necessary functions
from torchtext.data.utils import ____
from nltk.probability import ____
text = "In the city of Dataville, a data analyst named Alex explores hidden insights within vast data. With determination, Alex uncovers patterns, cleanses the data, and unlocks innovation. Join this adventure to unleash the power of data-driven decisions."
# Initialize the tokenizer and tokenize the text
tokenizer = ____("basic_english")
tokens = tokenizer(____)
threshold = 1
# Remove rare words and print common tokens
freq_dist = ____(____)
common_tokens = [token for token in tokens if ____[token] > ____]
print(common_tokens)