from keras.models import Sequential from keras.layers import Activation, Dense # xor model model = Sequential() model.add(Dense(4, input_dim=2, activation="relu")) model.add(Dense(2, activation="softmax")) model.compile(optimizer="sgd", loss="categorical_crossentropy") # training data import numpy as np x = np.array([[0, 0], [0, 1], [1, 0], [1, 1]], dtype=np.float32) y1 = np.logical_xor(x[:, 0], x[:, 1]) y0 = np.logical_not(y1) y = np.array([y0, y1]).T.astype(np.float32) # train model.fit(x, y, nb_epoch=15000) print("\n[weight and bias]") for layer in model.layers: print(layer.get_weights()) pass # predict pred_x = x[0:4] pred_y = model.predict(pred_x) print("\n[predicate]") print([pred_x, pred_y]) # => [[1, 0], [0, 1], [0, 1], [1, 0]]?