Created
December 27, 2022 09:33
-
-
Save kshirsagarsiddharth/f90182c16ac2699ecb898f6787921a57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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