Utilities

class verta.utils.ModelAPI(x=None, y=None)

A file-like and partially dict-like object representing a Verta model API.

Parameters:
  • x (list, pd.DataFrame, or pd.Series of {None, bool, int, float, str, dict, list}) – A sequence of inputs for the model this API describes.
  • y (list, pd.DataFrame, or pd.Series of {None, bool, int, float, str, dict, list}) – A sequence of outputs for the model this API describes.
static from_file(f)

Reads and returns a ModelAPI from a file.

Parameters:f (str or file-like) – Model API JSON filesystem path or file.
Returns:ModelAPI
to_dict()

Returns a copy of this model API as a dictionary.

Returns:dict
class verta.utils.TFSavedModel(saved_model_dir, session=None)

Wrapper around a TensorFlow SavedModel for compatibility with Verta deployment.

Parameters:
  • saved_model_dir (str) – Directory containing a SavedModel.
  • session (tf.Session, optional) – Session to load the SavedModel into. This parameter is for using the model locally; the session will be handled automatically during deployment.

Warning

Use of this utility is discouraged in favor of the simpler and more flexible class-as-model setup. See the Client repository for an example.

Examples

class TextVectorizer(object):
    def __init__(self, saved_model_dir, word_to_index, max_input_length):
        self.saved_model = TFSavedModel(saved_model_dir)  # text embedding model
        self.word_to_index = word_to_index
        self.max_input_length = max_input_length

    def predict(self, input_strs):
        predictions = []
        for input_str in input_strs:
            words = input_str.split()
            batch_indices = list(map(self.word_to_index.get, words))
            padding = [self.word_to_index("<UNK>")]*(self.max_input_length - len(batch_indices))

            predictions.append(self.saved_model.predict(batch_indices=batch_indices+padding))
        return predictions
predict(**kwargs)
Parameters:**kwargs – Values for input tensors.
Returns:dict of string to np.array – Map of output names to values.

Examples

tf_saved_model.predict(x=[1], y=[2])
# {'x_plus_y': array([3], dtype=int32)}