I'm learning TensorFlow and I'm trying to solve the XOR problem. I created a 3 layers neural network to do that but after 500 or 1000 epochs its not learning at all. What am I doing wrong?
I'm using TensorFlow 2.3.0 in colab.research.google.
from tensorflow.keras.layers import Dense
from tensorflow.keras.losses import MeanSquaredError
from tensorflow.keras.optimizers import SGD
from tensorflow.keras.metrics import Accuracy
from tensorflow.keras import Sequential
import numpy as np
x = np.array([[0., 0.],
[1., 1.],
[1., 0.],
[0., 1.]], dtype=np.float32)
y = np.array([[0.],
[0.],
[1.],
[1.]], dtype=np.float32)
model = Sequential()
model.add(Dense(2, activation='sigmoid'))
model.add(Dense(2, activation='sigmoid'))
model.add(Dense(1, activation='sigmoid'))
model.compile(optimizer='SGD', loss='mean_squared_error', metrics='accuracy')
model.fit(x, y, batch_size=1, epochs=1000, verbose=False)
pred = model.predict_on_batch(x)
print(pred)