Skip to content

Instantly share code, notes, and snippets.

@Dilaz
Last active March 3, 2020 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dilaz/c357ca99a2a36f441dd8da5b51178d97 to your computer and use it in GitHub Desktop.
Save Dilaz/c357ca99a2a36f441dd8da5b51178d97 to your computer and use it in GitHub Desktop.
import tensorflow as tf
def main():
training_data = [
(0, 0, 0),
(1, 0, 1),
(0, 1, 1),
(1, 1, 0)
]
x = [(i[0], i[1]) for i in training_data]
y = [i[2] for i in training_data]
model = tf.keras.models.Sequential([
tf.keras.layers.Dense(12, input_dim=2, activation='relu'),
tf.keras.layers.Dense(1, activation='sigmoid'),
])
model.compile(tf.keras.optimizers.Adam(learning_rate=0.001),
loss='mean_squared_error')
model.fit(x=x, y=y, epochs=300)
print(['{} XOR {} = {}'.format(
x[0], x[1], model.predict([x])[0][0].round()) for x in x])
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment