snowflake.ml.model.model_signature.FeatureSpec

class snowflake.ml.model.model_signature.FeatureSpec(name: str, dtype: DataType, shape: Optional[Tuple[int, ...]] = None)

Bases: BaseFeatureSpec

Specification of a feature in Snowflake native model packaging.

Initialize a feature.

Parameters:
  • name – Name of the feature.

  • dtype – Type of the elements in the feature.

  • shape

    Used to represent scalar feature, 1-d feature list, or n-d tensor. Use -1 to represent variable length. Defaults to None.

    Examples:

    • None: scalar

    • (2,): 1d list with a fixed length of 2.

    • (-1,): 1d list with variable length, used for ragged tensor representation.

    • (d1, d2, d3): 3d tensor.

Raises:
  • SnowflakeMLException – TypeError: When the dtype input type is incorrect.

  • SnowflakeMLException – TypeError: When the shape input type is incorrect.

Methods

as_dtype() Union[dtype[Any], None, Type[Any], _SupportsDType[dtype[Any]], str, Tuple[Any, int], Tuple[Any, Union[SupportsIndex, Sequence[SupportsIndex]]], List[Any], _DTypeDict, Tuple[Any, Any]]

Convert to corresponding local Type.

as_snowpark_type() DataType

Convert to corresponding Snowpark Type.

classmethod from_dict(input_dict: Dict[str, Any]) FeatureSpec

Deserialize the feature specification from a dict.

Parameters:

input_dict – The dict containing information of the feature specification.

Returns:

A feature specification instance deserialized and created from the dict.

classmethod from_mlflow_spec(input_spec: Union[mlflow.types.ColSpec, mlflow.types.TensorSpec], feature_name: str) FeatureSpec
to_dict() Dict[str, Any]

Serialize the feature group into a dict.

Returns:

A dict that serializes the feature group.

Attributes

name

Name of the feature.