Skip to content

Instantly share code, notes, and snippets.

@amita-shukla
Last active March 26, 2020 19:24
Show Gist options
  • Save amita-shukla/451f65089e0af5edb36bd0688a0a1033 to your computer and use it in GitHub Desktop.
Save amita-shukla/451f65089e0af5edb36bd0688a0a1033 to your computer and use it in GitHub Desktop.
import nltk
nltk.download('wordnet')
from nltk.stem import WordNetLemmatizer
from nltk import word_tokenize
wnl = WordNetLemmatizer()
def lemmatize_text(text):
tokens = word_tokenize(text)
lemmatized_tokens = [wnl.lemmatize(token) for token in tokens if not (isNumber(token) and token!='.' and token!=',')]
lemmatized_sentence = ' '.join(lemmatized_tokens)
return lemmatized_sentence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment