Tokenizasyon ve Lemmatizasyon

Python ile NLP için Özellik Mühendisliği

Rounak Banik

Data Scientist

Metin kaynakları

  • Haber yazıları
  • Tweetler
  • Yorumlar
Python ile NLP için Özellik Mühendisliği

Metni makineye uygun hâle getirme

  • Dogs, dog
  • reduction, REDUCING, Reduce
  • don't, do not
  • won't, will not
Python ile NLP için Özellik Mühendisliği

Metin ön işleme teknikleri

  • Kelimeleri küçük harfe çevirme
  • Baştaki/sondaki boşlukları kaldırma
  • Noktalama işaretlerini kaldırma
  • Durdurma kelimelerini kaldırma
  • Kısaltmaları açma
  • Özel karakterleri kaldırma (sayılar, emojiler vb.)
Python ile NLP için Özellik Mühendisliği

Tokenizasyon

"I have a dog. His name is Hachi."

Tokenlar:

["I", "have", "a", "dog", ".", "His", "name", "is", "Hachi", "."]
"Don't do this."

Tokenlar:

["Do", "n't", "do", "this", "."]
Python ile NLP için Özellik Mühendisliği

spaCy ile tokenizasyon

import spacy

# Load the en_core_web_sm model nlp = spacy.load('en_core_web_sm')
# Initiliaze string string = "Hello! I don't know what I'm doing here."
# Create a Doc object doc = nlp(string)
# Generate list of tokens tokens = [token.text for token in doc] print(tokens)
['Hello','!','I','do',"n't",'know','what','I',"'m",'doing','here','.']
Python ile NLP için Özellik Mühendisliği

Lemmatizasyon

  • Kelimeyi kök hâline çevir
    • reducing, reduces, reduced, reductionreduce
    • am, are, isbe
    • n'tnot
    • 'vehave
Python ile NLP için Özellik Mühendisliği

spaCy ile lemmatizasyon

import spacy

# Load the en_core_web_sm model
nlp = spacy.load('en_core_web_sm')
# Initiliaze string
string = "Hello! I don't know what I'm doing here."
# Create a Doc object
doc = nlp(string)

# Generate list of lemmas lemmas = [token.lemma_ for token in doc] print(lemmas)
['hello','!','-PRON-','do','not','know','what','-PRON','be','do','here', '.']
Python ile NLP için Özellik Mühendisliği

Haydi pratik yapalım!

Python ile NLP için Özellik Mühendisliği

Preparing Video For Download...