Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. model = tf.keras.models.load_model( 'models/model.h5' )
  2. embedding_matrix = model.layers[0].get_weights()[0] # --- ( 1 )
  3. print( 'Embedding Shape ~> {}'.format( embedding_matrix.shape ) )
  4.  
  5. # ------------ ( 2 ) ---------------------
  6.  
  7. word_index : dict = pickle.load( open( 'glove_embedding/tokenizer.pkl' , 'rb' ) ).word_index
  8. word_index_2 = dict()
  9. for word , index in word_index.items():
  10. word_index_2[ index ] = word
  11. word_index = word_index_2
  12. embedding_dict = dict()
  13.  
  14. # --------------- ( 3 ) ------------------
  15.  
  16. for i in range( len( embedding_matrix ) - 1 ):
  17. embedding_dict[ word_index[ i + 1 ] ] = embedding_matrix[ i + 1 ].tolist()
  18.  
  19. # ----------------( 4 ) -------------------
  20.  
  21. with open( 'android/embedding.json' , 'w' ) as file:
  22. json.dump( embedding_dict , file )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement