snowflake.ml.model.custom_model.ModelContext

class snowflake.ml.model.custom_model.ModelContext(*, artifacts: Optional[Union[Dict[str, str], str, catboost.CatBoost, lightgbm.LGBMModel, lightgbm.Booster, CustomModel, sklearn.base.BaseEstimator, sklearn.pipeline.Pipeline, xgboost.XGBModel, xgboost.Booster, torch.nn.Module, torch.jit.ScriptModule, tensorflow.Module, base.BaseEstimator, mlflow.pyfunc.PyFuncModel, transformers.Pipeline, sentence_transformers.SentenceTransformer, HuggingFacePipelineModel]] = None, models: Optional[Union[Dict[str, Union[catboost.CatBoost, lightgbm.LGBMModel, lightgbm.Booster, CustomModel, sklearn.base.BaseEstimator, sklearn.pipeline.Pipeline, xgboost.XGBModel, xgboost.Booster, torch.nn.Module, torch.jit.ScriptModule, tensorflow.Module, base.BaseEstimator, mlflow.pyfunc.PyFuncModel, transformers.Pipeline, sentence_transformers.SentenceTransformer, HuggingFacePipelineModel]], str, catboost.CatBoost, lightgbm.LGBMModel, lightgbm.Booster, CustomModel, sklearn.base.BaseEstimator, sklearn.pipeline.Pipeline, xgboost.XGBModel, xgboost.Booster, torch.nn.Module, torch.jit.ScriptModule, tensorflow.Module, base.BaseEstimator, mlflow.pyfunc.PyFuncModel, transformers.Pipeline, sentence_transformers.SentenceTransformer, HuggingFacePipelineModel]] = None, **kwargs: Optional[Union[str, catboost.CatBoost, lightgbm.LGBMModel, lightgbm.Booster, CustomModel, sklearn.base.BaseEstimator, sklearn.pipeline.Pipeline, xgboost.XGBModel, xgboost.Booster, torch.nn.Module, torch.jit.ScriptModule, tensorflow.Module, base.BaseEstimator, mlflow.pyfunc.PyFuncModel, transformers.Pipeline, sentence_transformers.SentenceTransformer, HuggingFacePipelineModel]])

Bases: object

Context for a custom model showing paths to artifacts and mapping between model name and object reference.

artifacts

A dictionary mapping the name of the artifact to its path.

model_refs

A dictionary mapping the name of the sub-model to its ModelRef object.

Initialize the model context.

Parameters:
  • artifacts – A dictionary mapping the name of the artifact to its currently available path. Defaults to None.

  • models – A dictionary mapping the name of the sub-model to the corresponding model object. Defaults to None.

  • **kwargs – Additional keyword arguments to be used as artifacts or models.

Raises:
  • ValueError – Raised when the keyword argument is used as artifacts or models.

  • ValueError – Raised when the artifact name is duplicated.

  • ValueError – Raised when the model name is duplicated.

Methods

model_ref(name: str) ModelRef

Get a ModelRef object of a sub-model containing the name and model object, allowing direct method calls.

Parameters:

name – The name of the sub-model.

Returns:

The ModelRef object representing the sub-model.

path(key: str) str
Get the actual path to a specific artifact. This could be used when defining a Custom Model to retrieve

artifacts.

Parameters:

key – The name of the artifact.

Returns:

The absolute path to the artifact.

Language: English