You can download this code by clicking the button below.
This code is now available for download.
This function removes stopwords from the given text. Stopwords are common words that are generally considered to have little semantic value, such as 'and', 'the', 'is', etc.
Technology Stack : nltk.corpus.stopwords, nltk.tokenize.word_tokenize
Code Type : Text processing
Code Difficulty : Intermediate
import random
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
def remove_stopwords_from_text(text):
stop_words = set(stopwords.words('english'))
word_tokens = word_tokenize(text)
filtered_text = [w for w in word_tokens if not w.lower() in stop_words]
return ' '.join(filtered_text)