title: How to save my own trained word embedding model (Using Keras) like word2vec and Glove
body: <p>I trained my own word embedding model using my own data set. Now, after training the Keras Embeddings layer,  I want to save the model in a text file so I can use for later classification of the unknown data set.</p>
  <p><strong>Source Code</strong>: <a href="https://machinelearningmastery.com/use-word-embedding-layers-deep-learning-keras/#comment-507619" rel="nofollow noreferrer">https://machinelearningmastery.com/use-word-embedding-layers-deep-learning-keras/#comment-507619</a>:</p>
  <pre><code>from numpy import array
  from keras.preprocessing.text import one_hot
  from keras.preprocessing.sequence import pad_sequences
  from keras.models import Sequential
  from keras.layers import Dense
  from keras.layers import Flatten
  from keras.layers.embeddings import Embedding
  # define documents
  docs = ['Well done!',
          'Good work',
          'Great effort',
          'nice work',
          'Excellent!',
          'Weak',
          'Poor effort!',
          'not good',
          'poor work',
          'Could have done better.']
  # define class labels
  labels = array([1,1,1,1,1,0,0,0,0,0])
  # integer encode the documents
  vocab_size = 50
  encoded_docs = [one_hot(d, vocab_size) for d in docs]
  print(encoded_docs)
  # pad documents to a max length of 4 words
  max_length = 4
  padded_docs = pad_sequences(encoded_docs, maxlen=max_length, padding='post')
  print(padded_docs)
  # define the model
  model = Sequential()
  model.add(Embedding(vocab_size, 8, input_length=max_length))
  model.add(Flatten())
  model.add(Dense(1, activation='sigmoid'))
  # compile the model
  model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
  # summarize the model
  print(model.summary())
  # fit the model
  model.fit(padded_docs, labels, epochs=50, verbose=0)
  # evaluate the model
  loss, accuracy = model.evaluate(padded_docs, labels, verbose=0)
  print('Accuracy: %f' % (accuracy*100))
  </code></pre>
  <p>However, I tried to save the model using a different format (.txt),</p>
  <pre><code>model.save('My_Model.txt')
  </code></pre>
  <p>however, the problem is that when I open the file, the data seems to have weird characters.</p>
  <p>I also got Embedding weights  by this:</p>
  <p><a href="https://i.stack.imgur.com/KRAHN.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KRAHN.jpg" alt="enter image description here" /></a></p>
  <p>How I could save my model in the same format of Glove and word2vec, the word followed by its vector..?</p>
  <p>Please guide me, how to save it like</p>
  <p>the  -6.07421696e-02, -3.59963439e-02,  4.38806415e-02, -3.08707543e-02, -1.51436431e-02, -5.56904338e-02, 5.70665635e-02, -8.34236890e-02</p>