Last active
December 27, 2022 10:30
-
-
Save kshirsagarsiddharth/70698cb0de8dbf990d9bd7c80a8ed9fc 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 nltk | |
from nltk.corpus import stopwords | |
# Load the stop words | |
stop_words = set(stopwords.words('english')) | |
def remove_stop_words(text): | |
# Tokenize the text | |
tokens = nltk.word_tokenize(text) | |
# Remove stop words | |
clean_tokens = [token for token in tokens if token not in stop_words] | |
# Join the clean tokens into a single string | |
clean_text = ' '.join(clean_tokens) | |
return clean_text | |
# Test the function | |
text = "This is some sample text with stop words." | |
remove_stop_words(text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment