openlayer.OpenlayerClient.add_model#
- OpenlayerClient.add_model(task_type, model_config=None, model_config_file_path=None, model_package_dir=None, sample_data=None, force=False, project_id=None)#
Adds a model to a project’s staging area.
- Parameters
- model_configDict[str, any]
Dictionary containing the model configuration. This is not needed if
model_config_file_path
is provided.What’s in the model config dict?
The model configuration depends on the
TaskType
. Refer to the documentation for examples.- model_config_file_pathstr
Path to the model configuration YAML file. This is not needed if
model_config
is provided.What’s in the model config file?
The model configuration YAML depends on the
TaskType
. Refer to the documentation for examples.- model_package_dirstr, default None
Path to the directory containing the model package. Only needed if you are interested in adding the model’s artifacts.
What’s in the model_package_dir?
The model package directory must contain the following files:
prediction_interface.py
The prediction interface file.
model artifacts
The model artifacts. This can be a single file, multiple files or a directory. The model artifacts must be compatible with the prediction interface file.
requirements.txt
The requirements file. This file contains the dependencies needed to run the prediction interface file.
For instructions on how to create a model package, refer to the documentation.
- sample_datapd.DataFrame, default None
Sample data that can be run through the model. Only needed if model_package_dir is not None. This data is used to ensure the model’s prediction interface is compatible with the Openlayer platform.
Important
The sample_data must be a dataframe with at least two rows.
- forcebool
If
add_model
is called when there is already a model in the staging area, whenforce=True
, the existing staged model will be overwritten by the new one. Whenforce=False
, the user will be prompted to confirm the overwrite.
Examples
See also
Our sample notebooks and tutorials.
First, instantiate the client:
>>> import openlayer >>> client = openlayer.OpenlayerClient('YOUR_API_KEY_HERE')
Create a project if you don’t have one:
>>> from openlayer.tasks import TaskType >>> project = client.create_project( ... name="Churn Prediction", ... task_type=TaskType.TabularClassification, ... description="My first project!", ... )
If you already have a project created on the platform:
>>> project = client.load_project(name="Your project name")
If your project’s task type is tabular classification…
Let’s say your model expects to receive a dataset looks like the following as input:
>>> df CreditScore Geography Balance 0 618 France 321.92 1 714 Germany 102001.22 2 604 Spain 12333.15 .. ... ... ...
Then, you can add the model to the project with:
>>> project.add_model( ... model_config_file_path="path/to/model/config", ... model_package_dir="path/to/model/package") ... sample_data=df.iloc[:5, :], ... )
After adding the model to the project, it is staged, waiting to be committed and pushed to the platform. You can check what’s on your staging area with
status
. If you want to push the model right away with a commit message, you can use thecommit
andpush
methods:>>> project.commit("Initial model commit.") >>> project.push()
If your task type is text classification…
Let’s say your dataset looks like the following:
>>> df Text 0 I have had a long weekend 1 I'm in a fantastic mood today 2 Things are looking up .. ...
Then, you can add the model to the project with:
>>> project.add_model( ... model_config_file_path="path/to/model/config", ... model_package_dir="path/to/model/package") ... sample_data=df.iloc[:5, :], ... )
After adding the model to the project, it is staged, waiting to be committed and pushed to the platform. You can check what’s on your staging area with
status
. If you want to push the model right away with a commit message, you can use thecommit
andpush
methods:>>> project.commit("Initial model commit.") >>> project.push()