<jupyter_start><jupyter_text>Build, train and save RNN Dynamics Model<jupyter_code>import models_dict_utils
# Each RNN model can be identified by its model_id string. 
# We will save checkpoints separately for each model. 
# Models can have different architectures, parameter dimensions etc. and are specified in models_dict.json
model_id = "learned_from_modulo"
# Specify input / output dimensions and hidden size
n_timesteps = 100
n_inputdim = 20
n_outputdim = 10
n_hidden = 32

# If you are creating a new RNN model or just to check if it already exists:
# Only needs to be done once for each model

models_dict_utils.check_model_exists_or_create_new(model_id, n_inputdim, n_hidden, n_outputdim)
# Load model from latest checkpoint 
dmodel = dm.DynamicsModel(model_id=model_id, timesteps=100, load_checkpoint=True)
# important to cast preds as numpy array. 
preds = np.array(dmodel.predict(x_test[:1]))
print preds.shape
print preds[0,0]
# Load model with different number of timesteps from checkpoint
# Since RNN weights don't depend on # timesteps (weights are the same across time), we can load in the weights for 
# any number of timesteps. The timesteps parameter describes the # of timesteps in the input data.
generator_model = dm.DynamicsModel(model_id=model_id, timesteps=1, load_checkpoint=True)
# make a prediction
preds = generator_model.predict(x_test[:1,:1, :])
print preds[0][0]<jupyter_output>[0.359197199344635, 0.4389760196208954, 0.3493378162384033, 0.27990731596946716, 0.2703004479408264, 0.25046560168266296, 0.26783278584480286, 0.22879324853420258, 0.24082358181476593, 0.22392180562019348]
StarcoderdataJupyterStructuredCleanDedup