DataFrame में TED Talks की सफाई
इस अभ्यास में, हम पहले चैप्टर वाले TED Talks पर फिर से काम करेंगे. आपके पास ted नाम का एक dataframe है जिसमें 5 TED Talks हैं. आपका काम है इन talks को पहले सीखी गई techniques से साफ करना: एक preprocess फंक्शन लिखिए और उसे dataframe के transcript फीचर पर apply कीजिए.
Stopwords की सूची stopwords के रूप में उपलब्ध है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में NLP के लिए Feature Engineering
अभ्यास निर्देश
textके लिए Doc ऑब्जेक्ट बनाइए. फिलहालdisableargument को ignor कीजिए.- list comprehension का इस्तेमाल करते हुए
lemma_attribute से lemmas बनाइए. - if condition में
isalpha()का उपयोग करके non-alphabetic कैरेक्टर हटाइए.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Function to preprocess text
def preprocess(text):
# Create Doc object
doc = nlp(____, disable=['ner', 'parser'])
# Generate lemmas
lemmas = [token.____ for token in doc]
# Remove stopwords and non-alphabetic characters
a_lemmas = [lemma for lemma in lemmas
if lemma.____ and lemma not in stopwords]
return ' '.join(a_lemmas)
# Apply preprocess to ted['transcript']
ted['transcript'] = ted['transcript'].apply(____)
print(ted['transcript'])