Stemming และ Lemmatization

Sentiment Analysis ด้วย Python

Violeta Misheva

Data Scientist

Stemming คืออะไร?

Stemming คือกระบวนการแปลงคำให้เป็นรูปรากศัพท์ แม้ว่ารากศัพท์นั้นอาจไม่ใช่คำที่ถูกต้องในภาษาก็ตาม

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

Sentiment Analysis ด้วย Python

Lemmatization คืออะไร?

Lemmatization คล้ายกับ Stemming แต่ต่างตรงที่จะลดรูปคำให้เป็นรากศัพท์ที่เป็นคำจริงในภาษา

stay, stays, staying, stayed ----> stay
house, houses, housing ----> house
Sentiment Analysis ด้วย Python

Stemming vs. Lemmatization

Stemming

  • ได้รากศัพท์ของคำ
  • รวดเร็วและมีประสิทธิภาพ

Lemmatization

  • ได้คำที่ถูกต้องตามพจนานุกรม
  • ช้ากว่า Stemming และอาจขึ้นอยู่กับ part-of-speech
Sentiment Analysis ด้วย Python

การทำ Stemming กับสตริง

from nltk.stem import PorterStemmer

porter = PorterStemmer()
porter.stem('wonderful')
'wonder'
Sentiment Analysis ด้วย Python

Stemmer สำหรับภาษาอื่น

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'
Sentiment Analysis ด้วย Python

การทำ Stemming กับประโยค

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', '!']
Sentiment Analysis ด้วย Python

การทำ Lemmatization กับสตริง

from nltk.stem import WordNetLemmatizer

WNlemmatizer = WordNetLemmatizer()
WNlemmatizer.lemmatize('wonderful', pos='a')
'wonderful'
Sentiment Analysis ด้วย Python

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

Sentiment Analysis ด้วย Python

Preparing Video For Download...