Search code examples
pythonnlpnltkstop-words

creating set of stopwords in nltk python


I know that NLTk stop words has a lot of languages but what if I want to create my own set of stop words and want to use them in NLTK stop words is that doable ?

import nltk
from nltk.corpus import stopwords
stops=set(stopwords.words('My own set'))
words=["Don't", 'hesitate','to','ask','questions']
print([word for word in words if word not in stops])

Solution

  • Store the set of stop words with space as dilimiter in a text file such as stop.txt stop_words = open('stop.txt','r').read().split()

    This would return the list with stop words in it.