Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
481 B
1
Indexable
Never
import nltk
from nltk.stem import WordNetLemmatizer

# Instantiate a lemmatizer object
lemmatizer = WordNetLemmatizer()

def lemmatize(sentence):
    # Tokenize the sentence
    tokenized_words=nltk.word_tokenize(sentence)
    
    #Lemmatize each word in a sentence
    lemmatized_words=[lemmatizer.lemmatize(word) for word in tokenized_words]
    
    #Join back in a sentence
    lemmatized_sentence=" ".join(lemmatized_words)
    
    return lemmatized_sentence