Last active
January 3, 2019 22:00
-
-
Save lettergram/d6cc61298d0920fa4e0909bba9d19df7 to your computer and use it in GitHub Desktop.
For use on https://austingwalters.com
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
| def import_embedding(embedding_name="data/default"): | |
| if not embedding_name: | |
| return None, None | |
| file_flag = os.path.isfile(embedding_name+"_word_encoding.json") | |
| file_flag &= os.path.isfile(embedding_name+"_cat_encoding.json") | |
| if not file_flag: | |
| return None, None | |
| word_encoding = {} | |
| with open(embedding_name+"_word_encoding.json") as word_embedding: | |
| word_encoding = json.load(word_embedding) | |
| category_encoding = {} | |
| with open(embedding_name+"_cat_encoding.json") as cat_embedding: | |
| category_encoding = json.load(cat_embedding) | |
| return word_encoding, category_encoding | |
| def export_embedding(word_encoding, category_encoding, embedding_name="data/default"): | |
| if not embedding_name or (not word_encoding) or 2 > len(word_encoding) \ | |
| or (not category_encoding) or 2 > len(category_encoding): | |
| return | |
| with open(embedding_name+"_word_encoding.json", "w") as embedding: | |
| embedding.write(json.dumps(word_encoding)) | |
| with open(embedding_name+"_cat_encoding.json", "w") as embedding: | |
| embedding.write(json.dumps(category_encoding)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment