Core Concepts

All You Need to Know

You do not need to be an expert in AI research to develop or deploy ML models. NatML focuses on making ML deployment as painless as possible for web developers. We have a separate project which focuses on making the model development process accessible and seamless (ask us about it).

Across both aspects, it is crucial to understand a few core concepts, and how they interact with one another. These concepts are:

  • Models

  • Model data

  • Features

  • Predictors

Models

An ML model is a 'black box' which receives one or more features and outputs one or more features. For example, a vision classifier receives an image feature and produces a probability distribution feature, telling you how likely the image is one label or another.

Under the hood, an ML model is a computation graph. This graph is what empowers ML models with the ability to learn and make predictions on new data.

NatML supports the ONNX and TorchScript model formats. NatML is designed to be able to run models either in the Hub cloud or on-device using predictors (more on this below). In both cases, you will create a model from model data:

// Fetch the model data from NatML Hub
const modelData = await MLModelData.fromFile("@author/model");
// Deserialize the model
const model = modelData.deserialize();

Model Data

INCOMPLETE.

Features

A feature is any data that can be produced or consumed by an MLModel. For example, you will use a lot of image features when working with vision models. NatML has built-in support for common features that might be used with ML models:

// Array feature for typed arrays
const arrayFeature: MLArrayFeature<Float32Array> = ...;
// Audio feature for audio data
const audioFeature: MLAudioFeature = ...;
// Image feature for images
const imageFeature: MLImageFeature = ...;
// Text feature for plain text
const textFeature: MLTextFeature = ...;

Every MLFeature has a corresponding MLFeatureType. This type describes the feature and data that is contained within it. Similarly, every MLModel has a set of input and output feature types, describing what data the model can consume and produce, respectively.

Predictors

Predictors are lightweight primitives that use one or more models to make predictions on features. They are self-contained units that know how to transform inputs into a format that a model expects. But more importantly, they are able to transform outputs of a model into a usable format. For example, we can create a classification predictor that works with image classifier models:

const labels = ["cat", "dog", ...];
const predictor = new MobileNetv2Predictor(model, labels);

Whereas a standard classification model outputs a probability distribution, the classification predictor can transform this raw output into a form which is much more usable by developers. It simply returns a class label (string) along with a classification score (float):

const [label, confidence] = await predictor.predict(...);
console.log(`Model predicted ${label} with confidence ${confidence}`);

You can create predictors for your own models and share them on NatML Hub!

Last updated