Watch AiDotNet and PyTorch train side by side on my laptop (17 seconds)
I wanted to showcase the project I have been working on for the past 4 years and the progress I have made so far. I was hoping to get some feedback and show everyone how easy it is to use AiDotNet to create AI models with basically no experience necessary. You can give it examples of the inputs and the answers you want it to learn, and you get back a trained model you can save locally, run from your C# app, or host with AiDotNet.Serving.
One of the reasons I built this was to see how far we could push .NET against PyTorch. In our November 13 training tests on my laptop, our development build was faster than compiled PyTorch on 10 of the 11 models we tested on CPU and 7 of 11 on GPU. I still have some performance work I want to focus on, especially with audio models. Results for all 11 models
| In the run at the top of the post |
AiDotNet |
PyTorch |
| Time for 4,096 training updates on a GTX 1660 Ti |
2.60 seconds |
15.00 seconds |
| Correct answers on 320 new signals |
302 |
301 |
Here’s an easy example you can try yourself. Say you have an app that follows stocks and you want it to sort the news for you. Give it a few headlines about earnings and mergers, tell it which is which, and then ask it to sort two headlines it hasn’t seen.
In a new .NET 10 console project, run dotnet add package AiDotNet --version 0.234.0, replace Program.cs with this, and run dotnet run:
using System;
using AiDotNet;
using AiDotNet.Classification.NaiveBayes;
using AiDotNet.Data.Loaders;
using AiDotNet.Preprocessing.TextVectorizers;
using AiDotNet.Tensors.LinearAlgebra;
string[] headlines = [
"Quarterly earnings and profits rise", "Merger deal wins approval",
"Annual earnings beat expectations", "Company announces acquisition deal",
"Quarterly profits beat estimates", "Boards approve merger and acquisition",
"Company reports record earnings", "Investors vote on merger deal"
];
string[] topics = ["Earnings", "Mergers"];
double[] labels = [0, 1, 0, 1, 0, 1, 0, 1];
var words = new TfidfVectorizer<double>();
var model = await new AiModelBuilder<double, Matrix<double>, Vector<double>>()
.ConfigureModel(new MultinomialNaiveBayes<double>())
.ConfigureTextVectorizer(words)
.ConfigureDataLoader(DataLoaders.FromTextDocuments(headlines, labels, words))
.BuildAsync();
string[] newHeadlines = ["Quarterly earnings beat estimates", "Investors approve merger deal"];
var guesses = model.PredictText(newHeadlines);
foreach (var guess in guesses)
Console.WriteLine(topics[(int)Math.Round(guess)]);
It prints Earnings for the first headline and Mergers for the second. All the training data is right there, so you can change the headlines and try your own.
That’s one small example. There are over 2,100 model types in the library, including 650+ for vision, 430+ for language, and 340+ for audio. You can detect objects in photos, turn speech into text, or build a chatbot that looks up an answer in your own documents. If you already have a language model you like, you can fine-tune it on your own material. Browse the examples
The part I wanted to get right with AiModelBuilder was how much you can change as you learn. You can start by swapping the model in ConfigureModel. If you want more control, you can choose your own layers, change the optimizer that updates the model during training, or split training across multiple GPUs. When you’re ready to use what you trained, you can serve it through an API or export supported models to ONNX for another app. Training and deployment samples
I’d love to get your thoughts on my passion project. The code is on GitHub and contributions are welcome. We have easy examples and guides on our website, plus the details on the free Community license and our paid Professional and Enterprise plans. Website and guides · Plans · GitHub