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 string | |
import re |
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
remove_punctuation = re.compile('[%s]' % re.escape(string.punctuation)) | |
tokens = [remove_punctuation.sub('', w) for w in tokenized] |
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
from nltk.corpus import stopwords | |
stop_words = set(stopwords.words('english')) | |
tokens = [w for w in tokens if w not in stop_words] |
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
from nltk.stem.porter import PorterStemmer | |
porter = PorterStemmer() | |
stemmed_words = [porter.stem(word) for word in tokens] |
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
from collections import Counter | |
vocably = Counter() | |
vocably.update(stemmed_words) |
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
indexing_words = {} | |
i = 0 | |
for word in vocably: | |
indexing_words[word] = i | |
i +=1 | |
vector = np.zeros(len(vocably)) | |
for key, times in vocably.items(): | |
vector[indexing_words[key]] = times |
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
unique_words = list(set(stemmed_words)) |
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
vector = np.zeros(len(unique_words)) |
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
vector = np.zeros(len(unique_words)) | |
for w in stemmed_words: | |
for i, word in enumerate(unique_words): | |
if w == word: | |
vector[i] +=1 |
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 string | |
import re | |
from nltk.corpus import stopwords | |
from collections import Counter | |
from nltk.stem.porter import PorterStemmer | |
import numpy as np | |
text = 'What a beautiful day to be outside, incredibly beautiful day!' | |
text = text.lower() |