Tvorba modelů n-gramů

Feature Engineering for NLP in Python

Rounak Banik

Data Scientist

Nevýhody BoW

recenze štítek
'The movie was good and not boring' pozitivní
'The movie was not good and boring' negativní

 

  • Stejná reprezentace BoW!
  • Kontext slov je ztracen.
  • Sentiment závisí na pozici slova 'not'.
Feature Engineering for NLP in Python

N-gramy

  • Posloupnost n po sobě jdoucích prvků (nebo slov) v dokumentu.
  • n = 1 → bag-of-words
    'for you a thousand times over'
    
  • n = 2, n-gramy:
    [
    'for you',
    'you a',
    'a thousand',
    'thousand times',
    'times over'
    ]
    
Feature Engineering for NLP in Python

N-gramy

'for you a thousand times over'
  • n = 3, n-gramy:
    [
    'for you a',
    'you a thousand',
    'a thousand times',
    'thousand times over'
    ]
    
  • Zachycuje více kontextu.
Feature Engineering for NLP in Python

Aplikace

  • Doplňování vět
  • Oprava pravopisu
  • Oprava strojového překladu
Feature Engineering for NLP in Python

Tvorba modelů n-gramů pomocí scikit-learn

Generuje pouze bigramy.

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

Generuje unigramy, bigramy a trigramy.

ngrams = CountVectorizer(ngram_range=(1,3))
Feature Engineering for NLP in Python

Nevýhody

  • Prokletí dimenzionality
  • N-gramy vyššího řádu jsou vzácné
  • Udržujte n malé
Feature Engineering for NLP in Python

Pojďme si procvičit!

Feature Engineering for NLP in Python

Preparing Video For Download...