Introduction to NLP feature engineering

Feature Engineering for NLP in Python

Rounak Banik

Data Scientist

ข้อมูลตัวเลข

ชุดข้อมูล Iris

sepal length sepal width petal length petal width class
6.3 2.9 5.6 1.8 Iris-virginica
4.9 3.0 1.4 0.2 Iris-setosa
5.6 2.9 3.6 1.3 Iris-versicolor
6.0 2.7 5.1 1.6 Iris-versicolor
7.2 3.6 6.1 2.5 Iris-virginica
Feature Engineering for NLP in Python

One-hot encoding

sex
female
male
female
male
female
...
Feature Engineering for NLP in Python

One-hot encoding

sex one-hot encoding
female
male
female
male
female
... ...
Feature Engineering for NLP in Python

One-hot encoding

sex one-hot encoding sex_female sex_male
female 1 0
male 0 1
female 1 0
male 0 1
female 1 0
... ... ... ...
Feature Engineering for NLP in Python

One-hot encoding ด้วย pandas

# Import the pandas library
import pandas as pd

# Perform one-hot encoding on the 'sex' feature of df df = pd.get_dummies(df, columns=['sex'])
Feature Engineering for NLP in Python

ข้อมูลข้อความ

ชุดข้อมูลรีวิวภาพยนตร์

review class
This movie is for dog lovers. A very poignant... positive
The movie is forgettable. The plot lacked... negative
A truly amazing movie about dogs. A gripping... positive
Feature Engineering for NLP in Python

การประมวลผลข้อความเบื้องต้น

  • แปลงเป็นตัวพิมพ์เล็ก
    • ตัวอย่าง: Reduction เป็น reduction
  • แปลงเป็นรูปฐาน
    • ตัวอย่าง: reduction เป็น reduce
Feature Engineering for NLP in Python

Vectorization

review class
This movie is for dog lovers. A very poignant... positive
The movie is forgettable. The plot lacked... negative
A truly amazing movie about dogs. A gripping... positive
Feature Engineering for NLP in Python

Vectorization

0 1 2 ... n class
0.03 0.71 0.00 ... 0.22 positive
0.45 0.00 0.03 ... 0.19 negative
0.14 0.18 0.00 ... 0.45 positive
Feature Engineering for NLP in Python

ฟีเจอร์พื้นฐาน

  • จำนวนคำ
  • จำนวนตัวอักษร
  • ความยาวเฉลี่ยของคำ
  • Tweets

ทวีตของ Silverado Records

Feature Engineering for NLP in Python

POS tagging

Word POS
I Pronoun
have Verb
a Article
dog Noun
Feature Engineering for NLP in Python

Named Entity Recognition

  • คำนามนี้หมายถึงบุคคล องค์กร หรือประเทศ?

บุคคล ธงชาติ และโลโก้ของ TED

Noun NER
Brian Person
DataCamp Organization
Feature Engineering for NLP in Python

แนวคิดที่เรียนในบทนี้

  • การประมวลผลข้อความ
  • ฟีเจอร์พื้นฐาน
  • ฟีเจอร์คำ
  • Vectorization
Feature Engineering for NLP in Python

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

Feature Engineering for NLP in Python

Preparing Video For Download...