A general purpose model builder equipped with generic train, and predict functions which takes parameters for optimization strategy, mini-batch, etc...

class generic_model.Model(objective, placeholderdict, maxbadcount=20, momentum=None, mb=1000, verbose=True, epochs=50, learnrate=0.003, save=False, opt='grad', decay=[1, 1.0], evaluate=None, predictions=None, logdir='log/', random_seed=None, model_name='generic', clip_gradients=0.0, make_histograms=False, best_model_path='/tmp/model.ckpt', save_tensors={}, tensorboard=False, train_evaluate=None, debug=False)[source]

Generic model builder for training and predictions.

  • objective – Loss function
  • placeholderdict – A dictionary of placeholders
  • maxbadcount – For early stopping
  • momentum – The momentum for tf.MomentumOptimizer
  • mb – The mini-batch size
  • verbose – Whether to print dev error, and save_tensor evals
  • epochs – maximum number of epochs to train for.
  • learnrate – learnrate for gradient descent
  • save – Save best model to best_model_path.
  • opt – Optimization strategy. May be ‘adam’, ‘ada’, ‘grad’, ‘momentum’
  • decay – Parameter for decaying learn rate.
  • evaluate – Evaluation metric
  • predictions – Predictions selected from feed forward pass.
  • logdir – Where to put the tensorboard data.
  • random_seed – Random seed for TensorFlow initializers.
  • model_name – Name for model
  • clip_gradients – The limit on gradient size. If 0.0 no clipping is performed.
  • make_histograms – Whether or not to make histograms for model weights and activations
  • best_model_path – File to save best model to during training.
  • save_tensors – A hashmap of str:Tensor mappings. Tensors are evaluated during training. Evaluations of these tensors on best model are accessible via property evaluated_tensors.
  • tensorboard – Whether to make tensorboard histograms of weights and activations, and graphs of dev_error.



The average number of seconds to complete an epoch.


Number of epochs completed during at point of best dev eval during training (fractional)


The best dev error reached during training.


Number of epochs completed during training (fractional)

eval(tensor_in, data, supplement=None)[source]

Evaluation of model.

Parameters:dataDataSet to evaluate on.
Returns:Result of evaluating on data for self.evaluate

A dictionary of evaluations on best model for tensors and keys specified by save_tensors argument to constructor.


Dictionary of model placeholders

predict(data, supplement=None)[source]
Parameters:dataDataSet to make predictions from.
Returns:A set of predictions from feed forward defined by self.predictions
train(train, dev=None, supplement=None, eval_schedule='epoch', train_dev_eval_factor=3)[source]
Parameters:dataDataSet to train on.
Returns:A trained Model
generic_model.get_feed_list(batch, placeholderdict, supplement=None, train=1, debug=False)[source]
  • batch – A dataset object.
  • placeholderdict – A dictionary where the keys match keys in batch, and the values are placeholder tensors
  • supplement – A dictionary of numpy input matrices with keys corresponding to placeholders in placeholderdict, where the row size of the matrices do not correspond to the number of datapoints. For use with input data intended for embedding_lookup.
  • dropouts – Dropout tensors in graph.
  • dropout_flag – Whether to use Dropout probabilities for feed forward.

A feed dictionary with keys of placeholder tensors and values of numpy matrices


Helper function to parse numeric value from tf.scalar_summary

Parameters:summary_str – Return value from running session on tf.scalar_summary
Returns:A dictionary containing the numeric values.