Created
March 24, 2018 19:07
-
-
Save NMZivkovic/f4c4baa4067775de165fc17f4d589132 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 numpy as np | |
| import collections | |
| class DataHandler: | |
| def read_data(self, fname): | |
| with open(fname) as f: | |
| content = f.readlines() | |
| content = [x.strip() for x in content] | |
| content = [content[i].split() for i in range(len(content))] | |
| content = np.array(content) | |
| content = np.reshape(content, [-1, ]) | |
| return content | |
| def build_datasets(self, words): | |
| count = collections.Counter(words).most_common() | |
| dictionary = dict() | |
| for word, _ in count: | |
| dictionary[word] = len(dictionary) | |
| reverse_dictionary = dict(zip(dictionary.values(), dictionary.keys())) | |
| return dictionary, reverse_dictionary |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment