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.models import Sequential from tensorflow.keras.layers import Dense
def generate_data(samples=1000):
x1 = np.random.rand(samples)
x2 = np.random.rand(samples)
y = x1 + x2
return np.vstack((x1, x2)).T, y
x_train, y_train = generate_data(10000)
x_val, y_val = generate_data(1000)
model = Sequential()
model.add(Dense(8, input_dim=2,activation='relu')) model.add(Dense(1)) model.compile(optimizer='adam', loss='mean_squared_error')
model.fit(x_train, y_train, epochs=100, batch_size=32, validation_data=(x_val, y_val)) x_test, y_test = generate_data(10)
predictions = model.predict(x_test)
for i in range(len(x_test)):
print(f"Input: {x_test[i]}, Predicted Sum: {predictions[i][0]}, Actual Sum: {y_test[i]}")