Last active
August 29, 2015 14:22
-
-
Save vzhong/3f96d11ebb02280c89de 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
from keras.layers.embeddings import Embedding | |
from keras.models import Sequential | |
from keras.layers.recurrent import LSTM | |
from keras.layers.core import Dense, Activation, Dropout | |
model = Sequential() | |
model.add(Embedding(10, 20)) | |
model.add(LSTM(20, 10)) | |
model.add(Dropout(0.5)) | |
model.add(Dense(10, 5)) | |
model.add(Activation('softmax')) | |
model.compile(loss='categorical_crossentropy', optimizer='sgd') | |
import numpy as np | |
X = np.random.randint(0, 10, size=(5, 10)) | |
Y = np.random.randint(0, 5, size=(5, 5)) | |
model.fit(X, Y, nb_epoch=2) | |
print model.predict(X) | |
print model.predict_classes(X) | |
""" | |
Epoch 0 | |
5/5 [==============================] - 0s - loss: 10.9368 | |
Epoch 1 | |
5/5 [==============================] - 0s - loss: 10.9237 | |
5/5 [==============================] - 0s | |
[[ 0.19954167 0.2032648 0.20230913 0.20168537 0.19319904] | |
[ 0.19952643 0.20361215 0.20237164 0.20141158 0.1930782 ] | |
[ 0.20005952 0.20260406 0.20279311 0.20199704 0.19254628] | |
[ 0.19930014 0.20366372 0.20246421 0.20164138 0.19293055] | |
[ 0.20006272 0.20291759 0.20239519 0.20154302 0.19308148]] | |
5/5 [==============================] - 0s | |
[1 1 2 1 1] | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment