I'm trying to implement a model of a recurrent neural network to solve a temporal version of the XOR problem, but I am not still able to do that. Any hints?
Asked
Active
Viewed 1,152 times
2 Answers
0
I think following this link helps you, I have gone trough those tutorials previously. Also take a look at this tutorial .
Green Falcon
- 14,308
- 10
- 59
- 98
Sampath Madala
- 157
- 1
- 7
0
Use the following code:
import keras
import numpy as np
a = np.array([[1, 1], [0, 1], [1, 0], [0, 0]])
b = np.array([[0], [1], [1], [0]])
model = keras.Sequential()
model.add(keras.layers.Dense(2, activation = 'sigmoid', input_shape = (2, )))
model.add(keras.layers.Dense(1, activation = 'sigmoid'))
model.compile(optimizer = keras.optimizers.rmsprop(), metrics = ['accuracy'], loss = 'binary_crossentropy')
model.fit(x = a, y = b, epochs = 750)
If you don't get 100% accuracy increase the number of epochs. Also take a look at here which may help you how increasing the size of each layer affects the learning process.
Green Falcon
- 14,308
- 10
- 59
- 98