Menu

Lemmatization

Lemmatization

Explanation

Different forms of a word often carry the same meaning.

For example:

  • Running → Run
  • Studies → Study
  • Bought → Buy
  • Cars → Car

Lemmatization converts words to their base form, helping the model recognize similar words as the same feature.

Code

lemmatizer = WordNetLemmatizer()

Create Function

def lemmatize_text(text):
words = text.split()
words = [
lemmatizer.lemmatize(word)
for word in words
]
return " ".join(words)

Apply Function

df['clean_review'] = df['clean_review'].apply(lemmatize_text)

View Results

df[['review','clean_review']].head()