Created
February 19, 2018 23:29
-
-
Save omaraflak/9833bd54a98093b0ade2fc11e2c08cfc to your computer and use it in GitHub Desktop.
Simple XOR with Keras
This file contains 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.models import Sequential | |
from keras.layers.core import Dense | |
from keras.optimizers import SGD | |
import numpy as np | |
def main(): | |
X = np.array([[0,0],[0,1],[1,0],[1,1]]) | |
Y = np.array([[0],[1],[1],[0]]) | |
model = Sequential() | |
model.add(Dense(8, input_dim=2, activation='tanh')) | |
model.add(Dense(1, activation='sigmoid')) | |
model.compile(loss='binary_crossentropy', optimizer=SGD(lr=0.1)) | |
model.fit(X, Y, batch_size=1, nb_epoch=1000) | |
model.summary() | |
print(model.predict(X)) | |
if __name__=='__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment