การสร้างโมเดล n-gram

Feature Engineering for NLP in Python

Rounak Banik

Data Scientist

ข้อจำกัดของ BoW

รีวิว ป้ายกำกับ
'The movie was good and not boring' เชิงบวก
'The movie was not good and boring' เชิงลบ

 

  • การแทนค่า BoW เหมือนกันทุกประการ!
  • บริบทของคำถูกละเลย
  • ความรู้สึกขึ้นอยู่กับตำแหน่งของคำว่า 'not'
Feature Engineering for NLP in Python

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'
    ]
    
Feature Engineering for NLP in Python

n-grams

'for you a thousand times over'
  • n = 3, n-grams:
    [
    'for you a',
    'you a thousand',
    'a thousand times',
    'thousand times over'
    ]
    
  • จับบริบทได้มากขึ้น
Feature Engineering for NLP in Python

การประยุกต์ใช้งาน

  • การเติมประโยคอัตโนมัติ
  • การแก้ไขคำสะกด
  • การแก้ไขการแปลภาษา
Feature Engineering for NLP in Python

การสร้างโมเดล n-gram ด้วย scikit-learn

สร้างเฉพาะ bigram

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

สร้าง unigram, bigram และ trigram

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

ข้อจำกัด

  • ปัญหา curse of dimensionality
  • n-gram อันดับสูงพบได้น้อย
  • ควรใช้ค่า n ที่เล็ก
Feature Engineering for NLP in Python

มาฝึกกันเถอะ!

Feature Engineering for NLP in Python

Preparing Video For Download...