Skip to content

Instantly share code, notes, and snippets.

@kshirsagarsiddharth
Created December 27, 2022 09:33
Show Gist options
  • Save kshirsagarsiddharth/f90182c16ac2699ecb898f6787921a57 to your computer and use it in GitHub Desktop.
Save kshirsagarsiddharth/f90182c16ac2699ecb898f6787921a57 to your computer and use it in GitHub Desktop.
import spacy
# Load the English model
nlp = spacy.load("en_core_web_sm")
def lemmatize_text(text):
# Process the text
doc = nlp(text)
# Extract the lemmas
lemmas = [token.lemma_ for token in doc]
# Join the lemmas into a single string
lemmatized_text = ' '.join(lemmas)
return lemmatized_text
# Test the function
text = "I am running to the store to buy milk"
lemmatize_text(text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment