Created
August 15, 2018 18:44
-
-
Save sahil280114/d579a56fcdee78834f40c5e8c5acbd13 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
def features(sentence): | |
stop_words = stopwords.words('english') + list(punctuation) | |
words = word_tokenize(sentence) | |
words = [w.lower() for w in words] | |
filtered = [w for w in words if w not in stop_words and not w.isdigit()] | |
words = {} | |
for word in filtered: | |
if word in words: | |
words[word] += 1.0 | |
else: | |
words[word] = 1.0 | |
return words |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment