NLP特徴量エンジニアリング入門

Pythonで学ぶNLPの特徴量エンジニアリング

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
Pythonで学ぶNLPの特徴量エンジニアリング

ワンホットエンコーディング

sex
female
male
female
male
female
...
Pythonで学ぶNLPの特徴量エンジニアリング

ワンホットエンコーディング

sex one-hot encoding
female
male
female
male
female
... ...
Pythonで学ぶNLPの特徴量エンジニアリング

ワンホットエンコーディング

sex one-hot encoding sex_female sex_male
female 1 0
male 0 1
female 1 0
male 0 1
female 1 0
... ... ... ...
Pythonで学ぶNLPの特徴量エンジニアリング

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'])
Pythonで学ぶNLPの特徴量エンジニアリング

テキストデータ

映画レビュー・データセット

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
Pythonで学ぶNLPの特徴量エンジニアリング

前処理

  • 小文字化
    • 例: Reductionreduction
  • 基本形への変換
    • 例: reductionreduce
Pythonで学ぶNLPの特徴量エンジニアリング

ベクトル化

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
Pythonで学ぶNLPの特徴量エンジニアリング

ベクトル化

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
Pythonで学ぶNLPの特徴量エンジニアリング

基本的な特徴量

  • 単語数
  • 文字数
  • 平均単語長
  • ツイート

シルベラード・レコーズのツイート

Pythonで学ぶNLPの特徴量エンジニアリング

品詞タグ付け(POS)

Word POS
I Pronoun
have Verb
a Article
dog Noun
Pythonで学ぶNLPの特徴量エンジニアリング

固有表現抽出(NER)

  • 名詞は人・組織・国のどれか?

人物、国旗、TEDのロゴ

Noun NER
Brian Person
DataCamp Organization
Pythonで学ぶNLPの特徴量エンジニアリング

学ぶ概念

  • テキスト前処理
  • 基本特徴量
  • 単語特徴量
  • ベクトル化
Pythonで学ぶNLPの特徴量エンジニアリング

Ayo berlatih!

Pythonで学ぶNLPの特徴量エンジニアリング

Preparing Video For Download...