Package: rho-ml
Rho MLRho MLprovides athin,thoughtful, andproveninterface for
putting Data Science to work in production and enterprise-grade
environments.RhousesRho MLfor
workloads as varied asNLP, toComputer VisiontoDecision Modelingfor professional racing. We seeRho MLas
having a few key benefits.#.Any Model(we won't dictate your libraries of choice!)Any Model with a Python interfacePyTorchTensorflowspaCyKeras[insert your preferred library here]... or some other custom Python code
#.Out-of-the-Box Versioning(yet customizable)Versioning is a common blind-spot in data science as compared to the
de facto standard ofSemverin much of
software engineering and modern CI/CD workflows.Rho MLprovides thisout-of-the-box, no strings attached.That said, we get that not all versioning is created equal, and provide
easy access to customizing version patterns.
#.Default Serialization and Deserialization(yet customizable)Storing models for production workloads is non-trivial.Frequently, libraries (including those listed above) provide their
"hello world" and "quickstart" guides expecting you're on a local
development machine with a "save to disk" type interface.Rho MLprovides instant-access to easy, production-grade, methods to
store and retrieve models.The default option may not work, soRho MLprovides easy
modification as necessary for advanced use cases.
#.Cloud and Cache(speed versus cost)A "model" is not created equal with respect to production workloads.
Storing and retrieving from the cloud versus locally (cached locally)
makes a tremendous difference in speed and cost when dealing with models
that often exceed 10s of megabytes / gigabytes.Rho MLprovides a sensible default for managing storage in both
scenarios.
#.Shameless Plug(enterprise deployments)EveryRho MLmodel has instant compatibilty withSermosfor enterprise-scale deployments
that need 10s to 10s of millions of transactions, scheduled tasks,
models behind public APIs, or complexpipelines.Rho ML is extremely easy to use and has only two external dependenciesattrs, andInstallInstall this software? Easy:pip install rho-mlQuickstart GuideHere is a trivial example of a rules-based "model" implemented as aRhoModel,
including serialization.from rho_ml import RhoModel, ValidationFailedError, Version, LocalModelStorage

class MyModel(RhoModel):

    def predict_logic(self, prediction_data):
        """ Logic for running the model on some prediction data """
        return prediction_data * 5

    def validate_prediction_input(self, prediction_data):
        """ Ensure data has an appropriate type before prediction """
        if not (isinstance(prediction_data, int)
            or isinstance(prediction_data, float)):
            raise ValidationError("Prediction data wasn't numeric!")

    def validate_prediction_output(self, data):
        """ Ensure the prediction result is between 0 and 5 """
        if not 0 <= data <= 5:
            raise ValidationError("Prediction result should always be
            between 0 and 5!")


 some_instance = MyModel(name='some_name',
                         version=Version.from_string("0.0.1"))
 result = some_instance.predict(0.5, run_validation=True)  # works!
 result_2 = some_instance.predict(10, run_validation=True)  # fails!

 local_storage = LocalModelStorage(base_path='./some-folder')
 local_storage.store(some_instance)

 stored_key = local_storage.get_key_from_pattern(model_name='some_name',
                                                 version_pattern='0.*.*')
 deserialized = local_storage.retrieve(key=stored_key)Core ConceptsRho ModelTheRhoModelbase class is the central concept inRhoML. ARhoModelis a basic wrapper that enforces what we believe are the central tasks a
machine learning model should accomplish, provides a consistent interface
to 'all models', and provides the scaffolding for writing models that have
validated input and output.TODO: Add additional detail on each component of a RhoModel and provide
several examples.Model LocatorA "model locator" in Rho ML is the combination of themodel name, themodel version, and adelimiterbetween them.This is important for storage and retrieval of models as they evolve over
time. Using the default settings is highly recommended but each component is
configurable.By default:Model names can be any alphanumeric characterDelimeter is "_" (the underscore character)Model versions must adhere tosemver versioninge.g.MyModel_0.1.0SerializationTODO: Describe concept of serializing/deserializing.TestingTo run the tests you need to havepyenvrunning on your system, along with
all python versions listed intox.iniunderenvlist.Install the required Python versions noted intox.ini, e.g.pyenv install 3.7.4Install the testing requirements locally.pip install -e .[test]Now, run the tests:tox