fork download
  1. from keras.models import Sequential
  2. from keras.layers import Dense, Activation
  3.  
  4. model = Sequential([
  5. Dense(32, input_dim=784),
  6. Activation('relu'),
  7. Dense(10),
  8. Activation('softmax'),
  9. ])
Success #stdin #stdout 3.27s 321220KB
stdin
import numpy as np 
from tensorflow.keras.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]}") 
stdout
Standard output is empty