MLEM developed by iterative.ai – is one of the most popular technologies that helps users to integrate, package, and deploy machine learning models to new and existing projects and apps. MLEM saves machine learning models in a standard format that can be used in a variety of production scenarios, such as real-time REST serving or batch processing. However, this open-source tool is mostly Python-based, and integrating it into non-Python apps could require much more effort and time.
Therefore, Akvelon’s engineers developed several HTTP clients for MLEM that allow users to integrate MLEM with their non-Python projects far faster and easier.
What is MLEM?
MLEM is an open-source tool that allows users to simplify machine learning model deployment.
With MLEM, users can run their machine learning models anywhere by wrapping models as a Python package or Docker Image, or deploying them to Heroku (SageMaker, Kubernetes, and more platforms coming soon).
MLEM is written in Python, and runs as a microservice with applications calling for a simple HTTP API. Our HTTP client was written in C# and Java, and was basically designed to help software developers use a machine learning approach to create intelligent applications, based on Java or .NET, without needing a deep knowledge of MLEM.
What are .NET Client and Java Client for MLEM?
.NET and Java clients are libraries that allow users to connect with MLEM API simply and easily, as well as integrate the MLEM model functionality to their .NET or Java project. It also supports request body validation by schema received from the MLEM server, and also offers a standard logging interface to use.
To implement a client, Akvelon used a standard HTTP Client with a given host, logger, and base models for some cases. The client provides several methods for using MLEM technologies with given rules. This is the main part of creating our custom MLEM client for Java or .NET, because having a stable application with minimum functionality is a good way to support it now and makes for easier improvements in the future.
Getting Started with Java Client
To get started with MLEM Java Client, you first have to explore a project’s repository: https://github.com/akvelon/MLEM-SDK-for-Java. You also should install an IDE, create a project, and add
MlemJClient.jar to your application classpath. If you are familiar with the Java language, looking into the JavaDoc should be the easiest way for you to start. The
MlemJClient.java interface is the one you may want to look at first.
And that’s it, you are ready to go!
After the installation is complete, you can send some requests using MLEM Java Client:
1. Create the MlemJClient object
2. Create the request body
3. Send the /predict request
4. Send the /call request with Illegal path name
The response will be:
error text: The path predict_proba123 is not found in schema; Available path list: [sklearn_predict, predict_proba, predict, sklearn_predict_proba].
Getting Started with MLEM .NET Client
MLEM .Net client is a NET class library based on NET 6.
- Cloned repo – https://github.com/akvelon/MLEM-SDK-for-C-Sharp
- Visual Studio Code or vsbuild console tool – to enable building the MLEM-SDK project
To build the latest stable client version, you need to:
- Switch to ‘main’ branch (git checkout main)
- Build the project in Visual Studio (see build docs for more details) using release configuration. As result – there will be the following
dll/deps.jsonfiles in target binaries folder (usually it is <project path>\bin\Release\net<net version> ):
MlemApi.dll– main client
ModelRepository.dll– assembly containing some example models you can use to play with MLEM .Net client
MlemApi.deps.json– client dependencies file
Once a client is built – you can add this as reference to your existing Visual Studio project (see more).
And finally, you are ready to go!
Additionally feel free to explore https://github.com/akvelon/MLEM-SDK-for-C-Sharp also and share any improvement ideas or report issues.
The Client provides the ability to extend default logic like validation or serializing of a request object into the request body – see more examples and the API description in the mlem-sdk repo.
Example of client usage:
- Create the
MlemApiClientobject in a simple variant
var mlemClient = new MlemApiClient("https://example-mlem-get-started-app.herokuapp.com/");
2. Define the class for the request object
3. Define the input data
4. Do PredictAsync
5. Do CallAsync
For more examples – feel free to explore our MLEM client repo.
MLEM makes the process of integrating, packaging, and deploying machine learning models much easier. With Akvelon’s .NET and Java clients, it is now possible to apply MLEM models much easier for non-Python projects that were developed in .NET and Java.
It is now possible to use these clients with your existing or new applications:
- Web (ASP.Net, Java Spring)
- Mobile (Xamarin, Android)
- Desktop (WPF, WinForms, Java Spring, Java Swing)
Now, there is no need to spend excessive amounts of time on implementing your own integration with MLEM – get access to the benefits of MLEM’s features in your apps with the HTTP clients developed by Akvelon’s engineers!
This article was written by:
Alexander Dudko, Software Development Engineer at Akvelon
Anatoly Bolshakov, Software Development Engineer at Akvelon
Denis Nosov, Project Manager at Akvelon
Vladimir Krestov, Software Development Engineer at Akvelon