Utils

Functions from backprop.utils are used for model inference, finetuning, saving, loading and uploading.

This page covers saving, loading and uploading. See the full reference in backprop.utils.

Save

It is recommended to save a model via a task instead (i.e task.save())

save(model, name: Optional[str] = None, description: Optional[str] = None, tasks: Optional[List[str]] = None, details: Optional[Dict] = None, path=None)[source]
Saves the provided model to the backprop cache folder using:
  1. provided name

  2. model.name

  3. provided path

The resulting folder has three files:

  • model.bin (dill pickled model instance)

  • config.json (description and task keys)

  • requirements.txt (exact python runtime requirements)

Parameters
  • model – Model object

  • name – string identifier for the model. Lowercase letters and numbers. No spaces/special characters except dashes.

  • description – String description of the model.

  • tasks – List of supported task strings

  • details – Valid json dictionary of additional details about the model

  • path – Optional path to save model

Example:

import backprop

backprop.save(model_object, "my_model")
model = backprop.load("my_model")

Load

load(path)[source]

Loads a saved model and returns it.

Parameters

path – Name of the model or full path to model.

Example:

import backprop

backprop.save(model_object, "my_model")
model = backprop.load("my_model")

Upload

It is recommended to upload a model via a task instead (i.e task.upload())

For a successful upload, ensure that the model is valid by following the check list in Models.

upload(model, name: Optional[str] = None, description: Optional[str] = None, tasks: Optional[List[str]] = None, details: Optional[Dict] = None, path=None, api_key: Optional[str] = None)[source]

Saves and deploys a model to Backprop.

Parameters
  • model – Model object

  • api_key – Backprop API key

  • name – string identifier for the model. Lowercase letters and numbers. No spaces/special characters except dashes.

  • description – String description of the model.

  • tasks – List of supported task strings

  • details – Valid json dictionary of additional details about the model

  • path – Optional path to save model

Example:

import backprop

tg = backprop.TextGeneration("t5_small")

# Any text works as training data
inp = ["I really liked the service I received!", "Meh, it was not impressive."]
out = ["positive", "negative"]

# Finetune with a single line of code
tg.finetune({"input_text": inp, "output_text": out})

# Use your trained model
prediction = tg("I enjoyed it!")

print(prediction)
# Prints
"positive"

# Upload to Backprop for production ready inference

model = tg.model
# Describe your model
name = "t5-sentiment"
description = "Predicts positive and negative sentiment"

backprop.upload(model, name=name, description=description, api_key="abc")