Skip to main content

Machine learning model contracts with machine learning infrastructure

Project description

Twinn-ml-interface

PyPI Latest Release Downloads License Code style: black

Twinn-ml-interface is a Python package for data contracts between machine learning code and infrastructure. This contract ensures smooth onboarding of machine learning models onto the Twinn-ml-platform by Royal HaskoningDHV.

Author: Royal HaskoningDHV

Installation

The easiest way to install this package is using pip:

pip install twinn-ml-interface

Model Interface

Purpose

The Model Interface defines the required methods and attributes that any ML model needs to have in order to run in the Royal HaskoningDHV Twinn-ml infrastructure.

Testing compliance of your model with the data contract

Instance of the Model Interface

Once all the attributes and methods from the Protocol ModelInterfaceV4 are implemented, including the correct type-hints / annotations, we can check if a model is compliant with the interface by doing an isinstance check with ModelInterfaceV4. You can find a base test in twinn_ml_interface/interface/model_test.py. The Darrow-Poc is an example of a model that follows the ModelInterfaceV4.

Mock Executors

The executor class takes care of running the model either for training or predictions in the Twinn-ml infrastructure. Here, we implemented a mock executor to emulate that behaviour to some extent, which hopefully makes it a little clearer in what context the model class will be used. Any model compliant with the ModelInterface should be able to train and predict using the ExecutorMock that can be found in twinn_ml_interface/mocks/mocks.py. The Darrow-Poc is an example of a model that follows ModelInterfaceV4 and can run using the ExecutorMock.

The steps and methods that the infrastructure and the mock executor run during training are:

  1. Read config:
    • get_target_template()
    • get_train_window_finder_config_template()
  2. Initialize the model
    • initialize()
  3. Given the configuration for the train window finder in the previous steps, validate possible windows:
    • validate_input_data()
  4. Read the data configuration to download all the needed data in a window selected by the previous step:
    • get_data_config_template()
  5. Transform the input data as needed:
    • preprocess()
  6. Train:
    • train()
  7. Store the model:
    • dump()

When the training is finished, the model can be used for predicting. The prediction steps are:

  1. Retrieve the model from storage and load it:
    • load()
  2. Fetch the data needed for prediction based on either:
    • base_features - if present
    • get_data_config_template() - otherwise
  3. Predict:
    • predict()
  4. Load configuration to post predictions:
    • get_result_template()

Example of the Model Interface

Darrow Poc

The Darrow-Poc is an example of a model that follows ModelInterfaceV4. It contains more detailed explanations of the data model, interface methods and the onboarding process.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

twinn_ml_interface-0.7.0.dev0.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

twinn_ml_interface-0.7.0.dev0-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file twinn_ml_interface-0.7.0.dev0.tar.gz.

File metadata

  • Download URL: twinn_ml_interface-0.7.0.dev0.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for twinn_ml_interface-0.7.0.dev0.tar.gz
Algorithm Hash digest
SHA256 78d458f74c862165a5f796793de278e149645a7f3808fca37bd3bebc44e6a320
MD5 a5b550a5e30f1ce8fa8a37cec27505f6
BLAKE2b-256 2d3055c134e967cf7c351634771b58cb673b4a68b860780e3e9496ddb1091735

See more details on using hashes here.

Provenance

The following attestation bundles were made for twinn_ml_interface-0.7.0.dev0.tar.gz:

Publisher: publish-to-pypi.yml on RoyalHaskoningDHV/twinn-ml-interface

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file twinn_ml_interface-0.7.0.dev0-py3-none-any.whl.

File metadata

File hashes

Hashes for twinn_ml_interface-0.7.0.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 b51152fdb731575805a00e7131c01be0ecef4e90024b1daec14ee6c361143851
MD5 81b54d20394eeea3e0c54c9b9e5b2015
BLAKE2b-256 00c48231c4203ca2ee14eb3398f2ab3d7d59a9b66a23ac72959e2fba7c14c005

See more details on using hashes here.

Provenance

The following attestation bundles were made for twinn_ml_interface-0.7.0.dev0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on RoyalHaskoningDHV/twinn-ml-interface

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page