# Optimistic Machine Learning (OPML)

## Introduction

The **Optimistic Machine Learning (OPML) framework** connects off-chain machine learning computations with smart contracts. Results are provably correct and can be disputed on-chain to ensure trust and accountability, enabling efficient AI-driven decision-making in decentralized applications. **OPML** is a core component of the **AI Oracle**, playing a critical role in validating inference results.

### Workflow

1. **Initiate Request**: The user contract sends an inference request to AI Oracle by calling the `requestCallback` function.
2. **opML Request**: AI Oracle creates an opML request based on the user contract request.
3. **Event Emission**: AI Oracle emits a `requestCallback` event collected by the opML node.
4. **ML Inference**: The opML node performs the AI model computation.
5. **Result Submission**: The opML node uploads the result on-chain.
6. **Callback Execution**: The result is dispatched to the user's smart contract via a callback function.

<figure><img src="https://4087680299-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FllyHj70MVMOxu2WT7tZv%2Fuploads%2FkKdCTWRTUEbQKcOrWxlL%2Fimage.png?alt=media&#x26;token=526efcc4-f3ce-48fb-a9fc-0b2a75bb586a" alt=""><figcaption><p>AI Oracle and opML Architecture</p></figcaption></figure>

### Challenge Process

1. **Challenge Window**: Begins after the result is submitted on-chain (step 5 above).
2. **Verification**: opML validators or any network participant can check the results and challenge the output if it is incorrect.
3. **Result Update**: If a challenge is successful, the incorrect result is updated on-chain.
4. **Finality**: After the challenge period, the result is finalized onchain and made immutable.

<figure><img src="https://4087680299-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FllyHj70MVMOxu2WT7tZv%2Fuploads%2Fomfw3mWDfwUpRg4AlsYU%2Fimage.png?alt=media&#x26;token=39517efa-d42e-485d-8ff8-b9c04e8f57d6" alt=""><figcaption></figcaption></figure>
