Protocol

MLFeatureProvider

An interface that represents a collection of values for either a model's input or its output.

Declaration

protocol MLFeatureProvider

Overview

Use MLFeatureProvider to customize the way your app gets data to and from your model when the model's dynamically generated interface doesn't meet your app's needs.

Consider adopting this protocol in your data source if any of the following apply:

  • Your data is collected asynchronously.

  • Using the autogenerated interface leads to copying excessive amounts of data.

  • Your data source is otherwise complicated.

The interface is mainly an accessor for MLFeatureValue instances, making it straightforward to implement. Adopting this protocol allows you to integrate your data directly with MLModel, which means the model can query your data sources without constructing a separate input instance.

To customize your app's interaction with a model:

  1. Adopt the MLFeatureProvider protocol in a class or structure so that the model can query it for input feature values via featureValue(for:).

  2. Pass your app's MLFeatureProvider to your MLModel with prediction(from:) or prediction(from:options:).

  3. Use the MLFeatureProvider returned from a prediction(from:) method to get the output feature values for that prediction.

Topics

Accessing Values

func featureValue(for: String) -> MLFeatureValue?

Accesses the feature value given the feature's name.

Required.

var featureNames: Set<String>

The set of valid feature names.

Required.

Relationships

See Also

Model Features

class MLFeatureValue

A feature's value and its type bundled as a read-only instance.

class MLDictionaryFeatureProvider

A convenience wrapper for the given dictionary of data.

protocol MLBatchProvider

An interface that represents a collection of feature providers.

class MLArrayBatchProvider

A convenience wrapper for batches of feature providers.