Please see the following blog post for more details about this code
Deep learning using Keras – The Basics