prediction_input_unpack

verta.deployment.prediction_input_unpack(func)

Decorator for unpacking a dictionary passed in as the argument for predict().

Verta’s DeployedModel.predict() does not support passing multiple arguments to the model. If an existing model of yours was written to take multiple parameters, this decorator can bridge the gap to keep your model code clean by allowing you to pass in a dictionary of keyword arguments and values that will be unpacked for predict().

New in version 0.13.18.

Examples

Before:

class Model(object):
    def predict(self, data):
        x = data['x']
        y = data['y']
        z = data['z']
        return x + y + z

deployed_model.predict({'x': 0, 'y': 1, 'z': 2})
# 3

After:

class Model(object):
    @prediction_input_unpack
    def predict(self, x, y, z):
        return x + y + z

deployed_model.predict({'x': 0, 'y': 1, 'z': 2})
# 3