Created
June 13, 2019 05:27
-
-
Save shubham0204/1c3fa78d38b4a6ce9a792e238679c85f 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
model = tf.keras.models.load_model( 'models/model.h5' ) | |
embedding_matrix = model.layers[0].get_weights()[0] # --- ( 1 ) | |
print( 'Embedding Shape ~> {}'.format( embedding_matrix.shape ) ) | |
# ------------ ( 2 ) --------------------- | |
word_index : dict = pickle.load( open( 'glove_embedding/tokenizer.pkl' , 'rb' ) ).word_index | |
word_index_2 = dict() | |
for word , index in word_index.items(): | |
word_index_2[ index ] = word | |
word_index = word_index_2 | |
embedding_dict = dict() | |
# --------------- ( 3 ) ------------------ | |
for i in range( len( embedding_matrix ) - 1 ): | |
embedding_dict[ word_index[ i + 1 ] ] = embedding_matrix[ i + 1 ].tolist() | |
# ----------------( 4 ) ------------------- | |
with open( 'android/embedding.json' , 'w' ) as file: | |
json.dump( embedding_dict , file ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment