Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.