Stemming và lemmatization

Phân tích cảm xúc với Python

Violeta Misheva

Data Scientist

Stemming là gì?

Stemming là việc đưa từ về dạng gốc, dù phần gốc có thể không phải từ hợp lệ trong ngôn ngữ.

staying, stays, stayed ----> stay
house, houses, housing ----> hous

Phân tích cảm xúc với Python

Lemmatization là gì?

Lemmatization khá giống stemming nhưng khác ở chỗ nó đưa từ về gốc là các từ hợp lệ trong ngôn ngữ.

stay, stays, staying, stayed ----> stay
house, houses, housing ----> house
Phân tích cảm xúc với Python

Stemming vs. lemmatization

Stemming

  • Tạo gốc của từ
  • Nhanh, tính toán hiệu quả

Lemmatization

  • Tạo ra từ thực
  • Chậm hơn stemming và có thể phụ thuộc vào loại từ (POS)
Phân tích cảm xúc với Python

Stemming cho chuỗi

from nltk.stem import PorterStemmer

porter = PorterStemmer()
porter.stem('wonderful')
'wonder'
Phân tích cảm xúc với Python

Stemmers cho ngôn ngữ khác tiếng Anh

Snowball Stemmer: Danish, Dutch, English, Finnish, French, German, Hungarian,Italian, Norwegian, Portuguese, Romanian, Russian, Spanish, Swedish

from nltk.stem.snowball import SnowballStemmer

DutchStemmer = SnowballStemmer("dutch")
DutchStemmer.stem("beginnen")
'begin'
Phân tích cảm xúc với Python

Cách stem một câu?

porter.stem('Today is a wonderful day!')
'today is a wonderful day!'
tokens = word_tokenize('Today is a wonderful day!')
stemmed_tokens = [porter.stem(token) for token in tokens]
stemmed_tokens
['today', 'is', 'a', 'wonder', 'day', '!']
Phân tích cảm xúc với Python

Lemmatization cho chuỗi

from nltk.stem import WordNetLemmatizer

WNlemmatizer = WordNetLemmatizer()
WNlemmatizer.lemmatize('wonderful', pos='a')
'wonderful'
Phân tích cảm xúc với Python

Ayo berlatih!

Phân tích cảm xúc với Python

Preparing Video For Download...