# ML Models

{% hint style="info" %}
Spice Models are in beta for Design Partners. Get in touch for more info.
{% endhint %}

Spice Models enable the training and use of ML models natively on the Spice platform.

The platform currently supports time-series forecasting models, with other categories of models planned.

Hosted models have first-class access to co-located data for training and inferencing including: [Spice managed datasets](https://docs.spice.ai/features/broken-reference), [user managed datasets](https://github.com/spicehq/docs/blob/trunk/portal/external-data-sources.md), and [custom datasets and views](https://github.com/spicehq/docs/blob/trunk/portal/datasets-and-views.md). Additionally, [Spice Firecache](https://docs.spice.ai/features/federated-sql-query) can be leveraged to train and infer up to 10x faster.

### Defining a Model

Models are defined using a [model manifest](https://docs.spice.ai/features/broken-reference) YAML file. Model details such as data requirements, architecture, training parameters, and other important hyperparameters are defined in the `model.yaml.`

Add a `model.yaml` file to the repository path `/models/[model_name]/model.yaml` of a [GitHub connected Spice app](https://github.com/spicehq/docs/blob/trunk/portal/apps/connect-github.md), replacing `[model_name]` with the desired model name.

Refer to the [Models YAML specification](https://docs.spice.ai/features/broken-reference) for all available configuration options.

For example model manifests, see the [models samples repo](https://github.com/spiceai/samples/tree/trunk/.spice/models).

## Training a Model

In the [spice.ai Portal](https://spice.ai), navigate to the **Models** tab of the Spice app.

`model.yaml` files committed to the connected repository will be automatically detected and imported as Spice Models.

<figure><img src="https://2598723546-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7zBuS83AqN3ud9rWji7y%2Fuploads%2Fgit-blob-2dee5df99c157aab65f65f739c268394e8694057%2FCleanShot%202024-01-30%20at%2010.49.30%402x.png?alt=media" alt=""><figcaption><p>Spice Models defined in <code>model.yaml</code> files automatically detected and imported in the Portal.</p></figcaption></figure>

Navigating to a specific Model will show detailed information as defined in the `model.yaml`.

A training run can be started using the **Train** button.

<figure><img src="https://2598723546-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7zBuS83AqN3ud9rWji7y%2Fuploads%2Fgit-blob-aa32f7c169f5ab0e6b4e5332335e952546f4d125%2FCleanShot%202024-01-30%20at%2010.51.58%402x.png?alt=media" alt=""><figcaption><p>Details for a specific Model.</p></figcaption></figure>

**Training runs** in progress will be shown and updated, along with historical training runs.

<figure><img src="https://2598723546-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7zBuS83AqN3ud9rWji7y%2Fuploads%2Fgit-blob-a186e0f81cc4aeb1f330fa70a12c7f677b20bf5f%2FCleanShot%202024-01-30%20at%2010.53.08%402x.png?alt=media" alt=""><figcaption><p>A model training with status "Running".</p></figcaption></figure>

The **Training Status** will be updated to `Complete` for successfully completed training runs. Details and the Training Report, are available on the **Training Run** page.

<figure><img src="https://2598723546-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7zBuS83AqN3ud9rWji7y%2Fuploads%2Fgit-blob-8105fd56e8a06385c6f4e6b3e223c8eed51d79e6%2FCleanShot%202024-01-30%20at%2010.55.32%402x.png?alt=media" alt=""><figcaption><p>A successfully completed Model training run with status "Complete".</p></figcaption></figure>

### Running Model Predictions

{% hint style="info" %}
Spice Models (beta) currently supports **time-series forecasting**.

Additional categories of data science and machine learning are on our roadmap.
{% endhint %}

A successfully trained model can be used to make predictions.

The lookback data (inferencing data) is automatically provided by the platform and wired up to the inference, enabling a prediction to be made using a simple API call.

### AI Predictions in the Playground

Navigate to **AI Predictions** in the **Playground**.

Successfully trained models will be available for selection from the model selector drop down on the right.

Clicking **Predict** will demonstrate calling the predictions API using lookback data within the Spice platform. A graph of the predicted value(s) along with the lookback data will be displayed.

<figure><img src="https://2598723546-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7zBuS83AqN3ud9rWji7y%2Fuploads%2Fgit-blob-e7f98dc15b4fe2d09c505d4e0b7c2f1150f60851%2FCleanShot%202024-01-30%20at%2011.02.00%402x.png?alt=media" alt=""><figcaption><p>The AI Predictions playground.</p></figcaption></figure>

### Predictions by API

The **Training Runs** page provides training details including a copyable `curl` command to make a prediction from the command line.

For details on the API, see [Prediction Documentation](https://docs.spice.ai/features/broken-reference).

<figure><img src="https://2598723546-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7zBuS83AqN3ud9rWji7y%2Fuploads%2Fgit-blob-7d1be535dff31e92798ad8e9306a1234375fc1a3%2FCleanShot%202024-01-30%20at%2011.00.34%402x.png?alt=media" alt=""><figcaption><p>Detailed training run page with the predictions API</p></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.spice.ai/features/spice-models.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
