Training model functions.