There can be several reasons.

Make sure your inputs are not unitialized
check to see if you don’t have gradient explosion, that might lead to nan/inf. Smaller learning rate could help here
Check if you don’t have division by zero, etc

It’s difficult to say more without further details.