Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement