vae.UnsupervisedModel

class vae.UnsupervisedModel(n_inputs, n_labels=None, optimizer='Adam', learning_rate=0.001, learning_rate_decay_fn=None, clip_gradients=None, model_dir=None, debug=False)

Base abstract class for unsupervised models

Parameters:
n_inputs : int

Length of the input vector.

n_labels : int or None, optional (default=None)

Length of the label vector. If not provided, assumes data is un-labeled.

optimizer : str, optional (default=’Adam’)

Optimizer to use for training the model. See tf.contrib.layers.OPTIMIZER_CLS_NAMES for available options.

learning_rate : float, optional (default=0.001)

Learning rate for training the model.

learning_rate_decay_fn : optional (default=None)

Function for decaying the learning rate. Takes learning_rate and global_step, and returns the decayed learning rate.

clip_gradients : float or None, optional (default=None)

If provided, global clipping is applied to prevent the gradient norms from exceeding the provided value.

model_dir : str or None, optional (default=None)

Path to the model directory. Defaults to the current working directory.

debug : bool, optional (default=False):

Whether to open the TensorFlow session in debug mode.

Attributes:
model_dir

str: Directory for saving and restoring the model

Methods

collect_stats(data, tensors[, enable_summaries]) Collect statistics on the provided data
evaluate(data[, tensors, combine_func, …]) Evaluate the model on the provided data.
fit(train_data[, validation_data, epochs, …]) Train the model using the provided training data
collect_stats(data, tensors, enable_summaries=False, **feed_dict)

Collect statistics on the provided data

Parameters:
data

Input data. Can be a NumPy array, a SciPy sparse matrix, or a Dataset object.

tensors: list of str

List containing names of statistics to collect.

enable_summaries : bool, optional (default=False)

Whether to write summaries to disk.

**feed_dict

Additional keyword arguments to append to the feed dictionary used for evaluation.

Returns:
results : list

The collected statistics.

evaluate(data, tensors=None, combine_func=<function _concat>, enable_summaries=False, batch_size=100, **feed_dict)

Evaluate the model on the provided data.

Parameters:
data

Input data. Can be a NumPy array, a SciPy sparse matrix, or a Dataset object.

tensors : list of str or None, optional (default=None)

List of tensor names to collect. Defaults to all available tensors.

combine_func : optional

Function to use to combine collected data from all batches. If set to None, each batch is returned separately. Defaults to concatenation along the first axis.

enable_summaries : bool, optional (default=False)

Whether to write summaries to disk.

batch_size : int, optional (default=100)

Size of mini-batches.

**feed_dict

Additional keyword arguments to append to the feed dictionary used for evaluation.

Yields:
results : list

If combine_func is None, a list containing outputs from a single batch, otherwise yields the combined results from all batches at once.

fit(train_data, validation_data=None, epochs=1, shuffle=True, restore=False, summary_steps=None, init_feed_dict={}, validation_feed_dict={}, batch_size=100, **train_feed_dict)

Train the model using the provided training data

Parameters:
train_data

Training data. Can be a NumPy array, a SciPy sparse matrix, or a Dataset object.

validation_data : optional (default=None)

Validation data. Can be a NumPy array, a SciPy sparse matrix, or a Dataset object.

epochs : int (default=1)

Number of training epochs.

shuffle : bool, optional (default=True)

Whether to shuffle training data before each epoch. Ignored if training data is a Dataset object.

restore : bool, optional (default=False)

Whether to restore the model from a previous checkpoint.

summary_steps : int or None, optional (default=None)

Number of steps between writing summaries, or None for disabling summaries.

init_feed_dict : dict, optional (default={})

Feed dictionary to append for initialization.

validation_feed_dict : dict, optional (default={})

Feed dictionary to append for validation.

batch_size : int, optional (default=100)

Size of mini-batches.

**feed_dict

Additional keyword arguments to append to the feed dictionary used for training

Returns:
self
model_dir

str: Directory for saving and restoring the model