टेक्स्ट क्लीनिंग

Python में NLP के लिए Feature Engineering

Rounak Banik

Data Scientist

टेक्स्ट क्लीनिंग तकनीकें

  • फालतू whitespaces और escape sequences
  • Punctuations
  • स्पेशल कैरेक्टर्स (numbers, emojis, आदि)
  • Stopwords
Python में NLP के लिए Feature Engineering

isalpha()

"Dog".isalpha()
True
"3dogs".isalpha()
False
"12347".isalpha()
False
"!".isalpha()
False
"❤".isalpha()
False
Python में NLP के लिए Feature Engineering

एक सावधानी

  • संक्षेप: U.S.A, U.K, आदि
  • विशेष संज्ञाएँ: word2vec और xto10x.
  • सूक्ष्म मामलों के लिए अपना कस्टम फंक्शन (regex के साथ) लिखें.
Python में NLP के लिए Feature Engineering

गैर-अक्षरीय कैरेक्टर्स हटाना

string = """
OMG!!!! This is like    the best thing ever \t\n. 
Wow, such an amazing song! I'm hooked. Top 5 definitely. ❤
"""

import spacy # Generate list of tokens nlp = spacy.load('en_core_web_sm') doc = nlp(string) lemmas = [token.lemma_ for token in doc]
Python में NLP के लिए Feature Engineering

गैर-अक्षरीय कैरेक्टर्स हटाना

...
...
# Remove tokens that are not alphabetic
a_lemmas = [lemma for lemma in lemmas 
            if lemma.isalpha() or lemma == '-PRON-']

# Print string after text cleaning print(' '.join(a_lemmas))
'omg this be like the good thing ever wow such an amazing song -PRON- be hooked top definitely'
Python में NLP के लिए Feature Engineering

Stopwords

  • बहुत आम तौर पर आने वाले शब्द
  • जैसे: articles, be verbs, pronouns, आदि
Python में NLP के लिए Feature Engineering

spaCy से stopwords हटाना

# Get list of stopwords
stopwords = spacy.lang.en.stop_words.STOP_WORDS

string = """ OMG!!!! This is like the best thing ever \t\n. Wow, such an amazing song! I'm hooked. Top 5 definitely. ❤ """
Python में NLP के लिए Feature Engineering

spaCy से stopwords हटाना

...
...
# Remove stopwords and non-alphabetic tokens
a_lemmas = [lemma for lemma in lemmas 
            if lemma.isalpha() and lemma not in stopwords]
# Print string after text cleaning
print(' '.join(a_lemmas))
'omg like good thing wow amazing song hooked definitely'
Python में NLP के लिए Feature Engineering

अन्य टेक्स्ट प्रीप्रोसेसिंग तकनीकें

  • HTML/XML टैग्स हटाना
  • accented कैरेक्टर्स (जैसे é) बदलना
  • स्पेलिंग त्रुटियाँ सुधारना
Python में NLP के लिए Feature Engineering

एक सावधानी

हमेशा वही टेक्स्ट प्रीप्रोसेसिंग तकनीकें अपनाएँ जो आपकी एप्लिकेशन के लिए प्रासंगिक हों.

Python में NLP के लिए Feature Engineering

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

Python में NLP के लिए Feature Engineering

Preparing Video For Download...