Skip to content

Commit

Permalink
Merge pull request #113 from NillionNetwork/fix/aivm
Browse files Browse the repository at this point in the history
fix: AIVM Docs
  • Loading branch information
jcabrero authored Oct 24, 2024
2 parents f10914d + d770d2c commit 46477d6
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 28 deletions.
37 changes: 37 additions & 0 deletions docs/aivm-supported-models.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Supported Models

AIVM currently supports the following pre-trained models for specific learning tasks. You can either utilize these existing models or use the [training scripts](https://github.com/NillionNetwork/nillion-aivm/blob/main/examples) to produce your own custom-trained versions:

## BertTiny

- [SMS Spam Classification](https://github.com/NillionNetwork/nillion-aivm/blob/main/examples/1-getting-started.ipynb)
- Binary classification for detecting spam messages
- Input: Text string
- Output: Binary classification (spam/not spam)
- [Movie Rating Sentiment Analysis](https://github.com/NillionNetwork/nillion-aivm/blob/main/examples/3a-upload-your-bert-tiny-model.ipynb)
- [Training Script](https://github.com/NillionNetwork/nillion-aivm/blob/main/examples/2a-fine-tuning-bert-tiny.ipynb)
- Sentiment analysis for movie reviews
- Input: Text string
- Output: Sentiment score (-1 to 1) for positive and negative
- [Tweet Sentiment Analysis](https://github.com/NillionNetwork/nillion-aivm/blob/main/examples/3c-upload-your-bert-tiny-for-tweet-sentiment.ipynb)
- [Training Script](https://github.com/NillionNetwork/nillion-aivm/blob/main/examples/2c-fine-tuning-bert-tiny-tweet-dataset.ipynb)
- Sentiment analysis for tweets in
- Input: Text string
- Output: Sentiment score (-1 to 1) for positive, neutral and negative

## LeNet5

- [Handwritten Digit Recognition (MNIST)](https://github.com/NillionNetwork/nillion-aivm/blob/main/examples/1-getting-started.ipynb)
- Classification of handwritten digits
- Input: 28x28 grayscale image
- Output: Digit classification (0-9)
- [Cats vs Dogs Classification](https://github.com/NillionNetwork/nillion-aivm/blob/main/examples/3b-upload-your-lenet5-model.ipynb)
- [Training Script](https://github.com/NillionNetwork/nillion-aivm/blob/main/examples/2b-fine-tuning-lenet5.ipynb)
- Binary image classification
- Input: 28x28 grayscale image
- Output: Binary classification (cat/dog)

## Project Ideas

- [Nillion AIVM Discord bot for message sentiment analysis](https://github.com/NillionNetwork/aivm-discord-bot)
- [Nillion AIVM Slack not for hotdog image detection](https://github.com/crypblizz8/hotdog_or_not_aivm)
77 changes: 49 additions & 28 deletions docs/aivm.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,24 @@

## Supported Models

AIVM currently supports the following pre-trained models for specific learning tasks. You can either utilize these existing models or deploy your own custom-trained versions:

### BertTiny
- SMS Spam Classification
- Binary classification for detecting spam messages
- Input: Text string
- Output: Binary classification (spam/not spam)
- Movie Rating Sentiment Analysis
- Sentiment analysis for movie reviews
- Input: Text string
- Output: Sentiment score (-1 to 1)

### LeNet5
- Handwritten Digit Recognition (MNIST)
- Classification of handwritten digits
- Input: 28x28 grayscale image
- Output: Digit classification (0-9)
- Cats vs Dogs Classification
- Binary image classification
- Input: 28x28 grayscale image
- Output: Binary classification (cat/dog)
AIVM currently supports the following pre-trained models for specific learning tasks. You can either utilize these existing models or use the [training scripts](https://github.com/NillionNetwork/nillion-aivm/examples) to produce your own custom-trained versions:

- BertTiny
- SMS Spam Classification
- Movie Rating Sentiment Analysis
- Tweet Sentiment Analysis
- LeNet5
- Handwritten Digit Recognition (MNIST)
- Cats vs Dogs Classification

We also have real-life project examples using these models including a Discord Bot for sentiment analysis and hotdog image detection.

More information on the supported models and project ideas can be found [here](./aivm-supported-models.md)

## Installation

### Recommended Installation

Installing Nillion AIVM is straightforward:

1. Create a virtual environment:
Expand Down Expand Up @@ -60,9 +54,9 @@ Installing Nillion AIVM is straightforward:
pip install "nillion-aivm[examples]"
```

This command installs all necessary dependencies for performing secure inference on AIVM.
This command installs all necessary dependencies for performing secure inference on AIVM. You can now check the [examples to test Nillion AIVM](https://github.com/NillionNetwork/nillion-aivm)

### Starting the Development Network
#### Starting the Development Network

Launch the AIVM development network with:

Expand All @@ -78,6 +72,16 @@ This command starts a persistent process that manages the secure computation inf
If you get stuck on this with VSCode, ensure the correct venv is selected. If it asks to pip install your packages / no pip is found, you can use `pip install ipykernel -U --force-reinstall` to install it.
:::

### Using Docker to deploy `aivm-devnet`

You can choose to use Docker for deploying `aivm-devnet`. For that, you **must have a working Docker installation**. The only required command is:

```shell
docker run -it -p 50050:50050 nillion/aivm-devnet
```

This commands forwards port 50050 from the Docker to your local machine, which is the port used to connect with the cluster.

## Performing Secure Inference

### Basic Usage
Expand All @@ -92,20 +96,37 @@ available_models = aic.get_supported_models()
print(available_models)
```

2. Prepare your input data. Here's an example using PyTorch to generate a random input:
2. Prepare your input data. Here's an example using PyTorch to load an MNIST dataset input:

```python
# Load the libraries
import torch

# Create a sample input (e.g., for LeNet5 MNIST)
random_input = torch.randn((1, 1, 28, 28)) # Batch size 1, 1 channel, 28x28 pixels
import torchvision.datasets as dset
import torchvision.transforms as transforms

# Define the required transformations for MNIST dataset
trans = transforms.Compose(
[
transforms.ToTensor(), # Transform to tensor
transforms.Resize((28, 28)), # Resize to (28 x 28)
transforms.Normalize((0.5,), (1.0,)), # Normalize the image
]
)
# Load the dataset
dataset = dset.MNIST(
root="/tmp/mnist", train=True, transform=trans, download=True
)

# Get entry #20 of the dataset
inputs, _ = dataset[20]
inputs = inputs.reshape(1, 1, 28, 28)
```

3. Encrypt your input using the appropriate Cryptensor:

```python
# Encrypt the input
encrypted_input = aic.LeNet5Cryptensor(random_input)
encrypted_input = aic.LeNet5Cryptensor(inputs)
```

4. Perform secure inference:
Expand Down
1 change: 1 addition & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ const sidebars = {
},
items: [
'aivm-reference',
'aivm-supported-models',
],
},
'limitations',
Expand Down

0 comments on commit 46477d6

Please sign in to comment.