To solve the error message, replace input_dim by inputs as keras.model() parameter.
For the problem with the loss value becoming NaN after 3 epochs:
first check that there is no NaN in your data but as the first epochs run it should be the case
probably that you are dealing with exploding gradients. Several possible solutions to try:
replace ReLU by tanh
decrease the learning rate
add gradient clipping
add weights regularisation