> For the complete documentation index, see [llms.txt](https://docs.natml.ai/js/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.natml.ai/js/api/mlmodeldata.md).

# MLModelData

class MLModelData

The `MLModelData` class is a self-contained archive containing an [`MLModel`](/js/api/mlmodel.md) along with supplemental data that is useful to make predictions with the model.

## Fetching Model Data

```typescript
/**
 * Fetch ML model data from NatML Hub.
 * @param tag Predictor tag.
 * @param accessKey Hub access key.
 * @returns ML model data.
 */
static fromHub (tag: string, accessKey?: string): Promise<MLModelData>;
```

NatML provides a model hosting, delivery, inference, and analytics service called [**NatML Hub**](https://hub.natml.ai). **INCOMPLETE.**

## Creating a Model

```typescript
/**
 * Deserialize the model data to create an ML model that can be used for prediction.
 * You MUST dispose the model once you are done with it.
 * @returns ML model.
 */
deserialize (): MLModel;
```

An [`MLModel`](/js/api/mlmodel.md) is created from model data. The model can then be used with a predictor to make predictions.

{% hint style="warning" %}
You must `dispose` the model when you are done with it. Failing to do so will result in severe resource leaks.
{% endhint %}

## Using Predictor Data

Model data contains additional information needed to make a prediction with a model.

### Classification Labels

```typescript
/**
 * Predictor classification labels.
 * This is `undefined` if the predictor does not have use classification labels.
 */
labels: string[] | undefined;
```

For classification and detection models, this field contains the list of class labels associated with each class in the output distribution. If class labels don't apply to the model, it will return `undefined`.

### Feature Normalization

```csharp
/**
 * Expected feature normalization for predictions with this model.
 * This is `undefined` if the predictor does not use normalization.
 */
normalization: Normalization | undefined;
```

Vision models often require that images be [normalized](https://en.wikipedia.org/wiki/Normalization_\(image_processing\)) to a specific mean and standard deviation. As such, `MLModelData` provides a `Normalization` object containing the per-channel normalization coefficients:

```typescript
// Feature normalization constants.
interface Normalization {
    // Per-channel normalization means.
    mean: number[];
    // Per-channel normalization standard deviations.
    std: number[];
}
```

### Image Aspect Mode

```csharp
/**
 * Expected image aspect mode for predictions with this model.
 * This is `undefined` for predictors that do not work with images.
 */
aspectMode: AspectMode | undefined;
```

Vision models might require that input image features be scaled a certain way when they are resized to fit the model's input size. The `aspectMode` can be passed directly to an [`MLImageFeature`](broken://pages/-MWMi7KrASK8m0hnxc3P).

### Audio Format

```csharp
/**
 * Expected audio format for predictions with this model.
 * This is `undefined` for predictors that do not work with audio.
 */
audioFormat: AudioFormat | undefined;
```

Audio and speech models often require or produce audio data with a specific sample rate and channel count. As such, `MLModelData` provides an `AudioFormat` object containing the audio format description:

```typescript
// Audio format description for models that work on audio data.
interface AudioFormat {
    // Sample rate.
    sampleRate: number;
    // Channel count.
    channelCount: number;
}
```
