Machine Learning Service
What is the Machine Learning Service?
The Machine Learning (ML) Service provides a space for ML and artificial intelligence (AI) enrichment within the broader context of a running Totara instance.
Explaining recommendations in the two different systems: Legacy Recommender vs Machine Learning Service
The Totara Recommendations system was introduced as part of Engage in Totara 13. The initial implementation was called Recommenders (located in the codebase under extensions/ml_recommender). This was a cron-based system that works by building a model and generating recommendations in an overnight job, which were then imported into Totara. The Recommender communicates via a series of shell scripts. While this system is relatively simple to implement, it does not scale well for large sites. Recommendations are generated every cycle rather than in real time, which means new users or new content do not have recommendations until the next cycle.
Totara 15 adopted a different approach for the deployment of the Recommenders engine. In Totara 15 we introduced the Machine Learning Service (located in the codebase under extensions/ml_service from Totara 15 to 19) as a host for the Recommenders engine. In the ML Service, the Recommenders engine runs as a subcomponent. The recommendations are generated in real time based on a model that is refreshed periodically. This brings obvious improvements to the experience for the end user, but it also allows for better system efficiency and site performance. The ML Service is a separate module that can run on a separate host from the Totara site if required. Communication between Totara and the ML Service is via API calls in real time. Updates to the Recommender will happen based on user activity.
From Totara 20 the ML Service is no longer embedded in Totara, rather it is distributed independently via git like Mobile is. This version is designed and will still work with Totara 15 onwards.
Service | Supported Range | Notes |
|
|---|---|---|---|
Recommenders ( | Totara 13 to Totara 16 | Deprecated from Totara 17 | Compatible with only the linked Totara version |
Machine Learning Service ( | Totara 15 to Totara 19 | Moved in Totara 20 (see below) | Compatible with only the linked Totara version |
Machine Learning Service (external repository) | Totara 15 onwards | Introduced at Totara 20 | Compatible with Totara 15 onwards |
As long as you are running Totara 15 or later, you are able to upgrade to the new Machine Learning Service from the external repository.
Installing
Configuration
The URL of the ML Service and secret key need to be configured in Totara for the successful connection with the service. This can be done from via https://[your_domain]/server/admin/settings.php?section=machine_learning_environment or from the config.php script by adding the following lines:
$CFG->ml_service_url = 'http://mlservice:5000'; // The URL of the ML Service
$CFG->ml_service_key = 'authenticationkey';You will also need to make sure the communication port is not blocked in Totara (defaults to 5000).
This can be accessed via the Security > IP Blocker page.
Code Access
You can download the machine learning service by using git and cloning the ml repository.
$ git clone ssh://git@code.totaralms.com:totara-ml-service
If you have access to the regular Totara distribution repo, you automatically have access to the machine learning repo. If you need access please raise a support ticket with the request.
The major installation steps are documented in the service’s readme file. Follow those instructions to get the engine running.
After the ML Service is successfully installed, the data export script must be scheduled to run via cron:
php server/ml/recommender/cli/export_data.phpThe frequency depends on how rapidly the content changes in your Totara site. Once every 24 hours is a sensible starting point.
The ML Service will fetch the data cached by this task on regular intervals. The default frequency with which the ML Service fetches the data and upgrades the recommendation model is once every 24 hours. This can be modified by following the instructions in the service’s readme file.
Note that the ML Service requires two directories: one for ML models and one for logs. These directories can be configured for the ML Service with the environment variables ML_MODELS_DIR and ML_LOGS_DIR on the hosting platform. Users should make sure that the service has write access to these directories.
The ML Service can be installed and run on the same host machine as Totara (in a Docker or without) but we do not recommend it. It’s best to run the service on its own, in a private network only accessible to the backend of your Totara instance.
The ML Service address must never be available to the general internet.
Upgrading between versions
From the legacy system to the latest Machine Learning service
If you’re running Totara 13 or 14, you first must upgrade to at least 15 to proceed.
If you’re running Totara 15 to 19 and have the legacy recommender system running, you can still upgrade to the latest version without changing Totara itself.
The legacy Recommender works via the execution of three separate scripts:
Export data (
php server/ml/recommender/cli/export_data.php).Train recommender model (
eval `eval `php server/ml/recommender/cli/recommender_comma`nd.php`).Import data back to server (
php server/ml/recommender/cli/import_recommendations.php).
The new Machine Learning Service does not require tasks 2 and 3. Task 1 is still required to be scheduled. If you have task 2 and 3 scheduled in cron, disable those but leave task 1 running.
All three of these tasks are included in the script server/ml/recommender/cli/run.sh. If you have run.sh scheduled, disable it and schedule export_data.php (Task 1 above). A sensible schedule for export_data.php is once every 24 hours.
Once the above steps are completed, install the new Machine Learning Service by following the installation steps above and the recommenders engine configurations on Totara. When the service is successfully installed, and is running and configured on Totara, the recommenders engine model will train in the ML Service and Totara will start getting recommendations from the service.
From Totara 15-19 Machine Learning service to Totara 20+ Machine Learning service
Shutdown any running python or docker service based on the server/extensions/ml_service codebase, then checkout and upgrade Totara’s codebase. You’ll note that the server/extensions/ml_service directory no longer exists.
Follow the instructions in the installation steps above to resume the recommendations system.
Note for Windows users: The Recommenders engine in the ML Service uses a library called LightFM for modelling the recommendations. The LightFM library needs to be compiled with an OpenMP-enabled C compiler for multi-threading. As this is hard to set up on Windows, all model fitting will be single-threaded. If you’d like to use the multi-threading capabilities of LightFM on these platforms, you should try using ML Service via Docker.
© Copyright 2022 Totara Learning Solutions. All rights reserved.