n-gram मॉडल बनाना

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

Rounak Banik

Data Scientist

BoW की कमियाँ

review label
'The movie was good and not boring' positive
'The movie was not good and boring' negative

 

  • दोनों में बिल्कुल समान BoW representation!
  • शब्दों का संदर्भ खो जाता है।
  • भावना 'not' की position पर निर्भर।
Python में NLP के लिए Feature Engineering

n-grams

  • किसी दस्तावेज़ में n तत्वों (या शब्दों) का लगातार क्रम।
  • n = 1 → bag-of-words
    'for you a thousand times over'
    
  • n = 2, n-grams:
    [
    'for you',
    'you a',
    'a thousand',
    'thousand times',
    'times over'
    ]
    
Python में NLP के लिए Feature Engineering

n-grams

'for you a thousand times over'
  • n = 3, n-grams:
    [
    'for you a',
    'you a thousand',
    'a thousand times',
    'thousand times over'
    ]
    
  • अधिक संदर्भ कैप्चर करता है।
Python में NLP के लिए Feature Engineering

उपयोग

  • वाक्य पूर्ण करना
  • वर्तनी सुधार
  • मशीन अनुवाद सुधार
Python में NLP के लिए Feature Engineering

scikit-learn से n-gram मॉडल बनाना

सिर्फ bigrams बनाता है।

bigrams = CountVectorizer(ngram_range=(2,2))

unigrams, bigrams और trigrams बनाता है।

ngrams = CountVectorizer(ngram_range=(1,3))
Python में NLP के लिए Feature Engineering

कमियाँ

  • Curse of dimensionality
  • उच्च-क्रम n-grams दुर्लभ होते हैं
  • n छोटा रखें
Python में NLP के लिए Feature Engineering

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

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

Preparing Video For Download...