Module Index

Racket’s CLI

racket

racket CLI tool to:
  • Create new projects
  • Interact with racket server.
  • Manage model lifecycle

Check the help available for each command listed below.

racket [OPTIONS] COMMAND [ARGS]...

Options

-v, --verbose

Turn on debug logging

dashboard

racket dashboard [OPTIONS]

Options

-h, --host <host>

Host on which to server

-p, --port <port>

Port on which to expose app

-e, --env <env>

Environment (dev, test, or prod)

-c, --clean

Clean up database

init

Creates a new project

racket init [OPTIONS]

Options

--name <name>

Name of the project

--path <path>

Directory where the new project will be created

ls

List available models, filtering and sorting as desired

Running:

$ racket ls -a  # returns the active model's metadata

Will return:

  model_id  model_name      major    minor    patch    version_dir  active    created_at                  model_type    scoring_fn            score
----------  ------------  -------  -------  -------  -------------  --------  --------------------------  ------------  ------------------  -------
         1  base                0        1        0              1  True      2018-11-14 22:53:52.455635  regression    loss                9378.25
         1  base                0        1        0              1  True      2018-11-14 22:53:52.455635  regression    mean_squared_error  9378.25
racket ls [OPTIONS]

Options

-n, --name <name>

List available models with a specific name

-v, --version <version>

Retrieve modles of only a specific version, e.g. M1, m2, or p1 (M: Major, m: minor, p: patch

-t, --type <m_type>

Filter on model type

-a, --active

Returns currently active model

--id <model_id>

Filters on model id

serve

Serve a specific model.

This allows you to specify either a model-id or a the name + version of a specific model that you’d like to serve. If the model-id is specified, the name and versions are ignored.

Throws an error if the specified model do not exist.

racket serve [OPTIONS]

Options

--model-id <model_id>

Model unique identifier

--model-name <model_name>

Model name

--version <version>

Model version as major.minor.patch, or latest

v

Retrive the version of the current racket install

racket v [OPTIONS]

version

Retrive the version of the current racket install

racket version [OPTIONS]

Internals

class racket.Learner[source]

Abstract Base Class for any learner implemented (currently Keras only, but more are planned).

Note

This as an abstract class and cannot be instantiated

semantic

str – Semantic representation of the model version

major

int – Major version of the learner

minor

int – Minor version of the learner

patch

int – Patch version of the learner

model_name

str – Name of the model

model_type

str – Type of the model, either regression or classification

_model

Any – The instantiated model, such as a Keras compiled model

_val_loss

dict – Validation loss of the model according to the metrics defined in its implementation

path

Path on disk of the model :returns: :rtype: str

sql

SQLized representation of model metadata

Returns:The SQLAlchemy representation of the model
Return type:MLModel
class racket.KerasLearner[source]

Base class providing functionality for training & storing a model

build_model()[source]

Abstract method. Must be overridden. Raises: NotImplementedError if called from base class

fit(x, y, *args, **kwargs)[source]

Abstract method. Must be overridden. Raises: NotImplementedError if called from base class

Parameters:
  • x (array_like) – a numpy array, or matrix that serves as input to the model. Must have matching dimensions to the model input specs
  • y (array_like) – the targets for the input data
  • args – Other parameters to be fed to the model
  • kwargs – Other parameters to be fed to the model
historic_scores

Only available when model has been fit. Provides access to the latest validation scores

Returns:Dictionary of metric scores {metric: score}
Return type:dict
model

returns: The compiled model :rtype: Sequential

scores(x: Iterable, y: Iterable) → object[source]

Evaluate scores on a test set

Parameters:
  • x (array_like) – A numpy array, or matrix that serves as input to the model. Must have matching dimensions to the model input specs
  • y (array_like) – the targets for the input data
Returns:

Dictionary of metric scores {metric: score} evaluated on the test set

Return type:

dict

store(autoload: bool = False) → None[source]

Stores the model in three different ways/patterns:

  1. Keras serialization, that is a json + h5 object, from which it can be loaded into a TensorFlow session
  2. TensorFlow protocol buffer + variables. That is the canonical TensorFlow way of storing models
  3. Metadata, scores, and info about the model are stored in a relational database for tracking purposes
Returns:
Return type:None
tf_path

On disk path of the TensorFlow serialized model :returns: :rtype: str

class racket.operations.load.ModelLoader[source]

This class provides the interface to load new models into TensorFlow Serving. This is implemented through a gRPC call to the TFS api which triggers it to look for directories matching the name of the model specified

classmethod load(model_name: str) → None[source]

Load model

This will send the gRPC request. In particular, it will open a gRPC channel and communicate with the ReloadConfigRequest api to inform TFS of a change in configuration

Parameters:model_name (str) – Name of the model, as specified in the instantiated Learner class
Returns:
Return type:None
class racket.models.base.MLModel(**kwargs)[source]

The SQL DeclarativeMeta model responsible for storing a model’s metadata

Parameters:
  • model_id (int) – The model’s unique identifier
  • model_name (str) – Model name, usually defined with instantiating a Learner class
  • major (int) – Major version of the learner
  • minor (int) – Minor version of the learner
  • patch (int) – Patch version of the learner
  • version_dir (str) – Directory where the models will be stored inside TensorFlow serving and on-disk
  • created_at (dateteime.datetime) – When the model was created
  • model_type (str) – The model type usually either regression or classification
class racket.models.base.MLModelInputs(**kwargs)[source]
class racket.models.base.ModelScores(**kwargs)[source]

Scores of the model

Parameters:
  • model_id (int) – The model’s unique identifier
  • scoring_fn (str) – The name of the scoring function
  • score (float) – The cross-validation score associated with the scoring function and the model id
class racket.models.channel.Channel[source]

A gRPC channel implementation