I am trying to build a neural network to add two numbers. This is the code:
import tensorflow as tf
from keras.models import Sequential
from keras.layers import Dense
import numpy as np
num_train = 100000
X_train = np.random.rand(num_train, 2)
y_train = X_train[:, 0] + X_train[:, 1]
norm = tf.keras.layers.Normalization(axis=-1)
norm.adapt(X_train)
Xn = norm(X_train)
Xt = np.tile(Xn, (1000, 1))
yt = np.tile(y_train, (1000, 1))
model = Sequential(
[
Dense(10, activation='relu'),
Dense(1, activation ='relu')
]
)
model.compile(loss = 'mse', optimizer='adam')
batch_size = 32
epochs = 100
model.fit(Xt, yt, batch_size=batch_size, epochs=epochs, verbose = 0)
test_input = np.array([[1, 2]])
predicted_sum = model.predict(test_input)
print(predicted_sum)
Prior to adding the part where I tiled the data, the code at least worked, though the prediction was off. After I added it, though, I get the error message on running it:
line 114, in check_data_cardinality
raise ValueError(msg)
ValueError: Data cardinality is ambiguous. Make sure all arrays contain the same number of samples.'x' sizes: 10000000
0
'y' sizes: 1000
Why does y remain at 1000 size? After tiling it should be at 10000000 too, by my math.