शुरू करेंमुफ़्त में शुरू करें

ट्वीट्स से stems

इस अभ्यास में, आप tweets नाम के एक array के साथ काम करेंगे. इसमें Twitter से एकत्र किए गए एयरलाइन sentiment डेटा का टेक्स्ट है.

आपका कार्य इस array के साथ काम करना और list comprehension का उपयोग करके इसे tokens की एक लिस्ट में बदलना है. उसके बाद, tokens की लिस्ट पर iterate करें और हर token का stem बनाएँ. याद रखें कि list comprehensions, for loops का एक one-line विकल्प हैं.

यह अभ्यास पाठ्यक्रम का हिस्सा है

Python में Sentiment Analysis

पाठ्यक्रम देखें

अभ्यास निर्देश

  • वह फंक्शन इम्पोर्ट करें जिसका उपयोग हमने strings को stems में बदलने के लिए किया था.
  • अभी-अभी इम्पोर्ट किए गए Porter stemmer फंक्शन को कॉल करें.
  • एक list comprehension का उपयोग करके tokens लिस्ट बनाएँ. इसमें tweets array से सभी word tokens होने चाहिए.
  • tokens लिस्ट पर iterate करें और लिस्ट के हर आइटम पर stemming फंक्शन लागू करें.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

# Import the function to perform stemming
____
from nltk import word_tokenize

# Call the stemmer
porter = ____()

# Transform the array of tweets to tokens
tokens = [____]
# Stem the list of tokens
stemmed_tokens = [[____.____(word) for word in tweet] for tweet in tokens] 
# Print the first element of the list
print(stemmed_tokens[0])
कोड संपादित करें और चलाएँ