Kelime torbası modeli oluşturma

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

Rounak Banik

Data Scientist

ML algoritmaları için veri biçimi özeti

Her ML algoritması için,

  • Veri tablo biçiminde olmalıdır
  • Eğitim özellikleri sayısal olmalıdır
Python ile NLP için Özellik Mühendisliği

Kelime torbası modeli

  • Sözcük belirteçleri çıkarın
  • Sözcük sıklıklarını hesaplayın
  • Bu sıklıklar ve derlemin söz varlığıyla bir sözcük vektörü kurun
Python ile NLP için Özellik Mühendisliği

Kelime torbası modeli örneği

Derlem

"The lion is the king of the jungle"
"Lions have lifespans of a decade"
"The lion is an endangered species"
Python ile NLP için Özellik Mühendisliği

Kelime torbası modeli örneği

Söz varlığıa, an, decade, endangered, have, is, jungle, king, lifespans, lion, Lions, of, species, the, The

"The lion is the king of the jungle"
[0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 2, 1]
"Lions have lifespans of a decade"
[1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0]
"The lion is an endangered species"
[0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1]
Python ile NLP için Özellik Mühendisliği

Metin ön işleme

  • Lions, lionlion
  • The, thethe
  • Noktalama yok
  • Stop sözcük yok
  • Daha küçük söz varlığına yol açar
  • Boyut sayısını azaltmak performansı iyileştirir
Python ile NLP için Özellik Mühendisliği

sklearn ile kelime torbası modeli

corpus = pd.Series([
    'The lion is the king of the jungle',
    'Lions have lifespans of a decade',
    'The lion is an endangered species'
])
Python ile NLP için Özellik Mühendisliği

sklearn ile kelime torbası modeli

# Import CountVectorizer
from sklearn.feature_extraction.text import CountVectorizer

# Create CountVectorizer object vectorizer = CountVectorizer()
# Generate matrix of word vectors bow_matrix = vectorizer.fit_transform(corpus) print(bow_matrix.toarray())
array([[0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 3],
       [0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0],
       [1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1]], dtype=int64)
Python ile NLP için Özellik Mühendisliği

Hadi pratik yapalım!

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

Preparing Video For Download...