Score Almost Any Machine Learning Model in Ruby

Ruby isn’t a common choice for machine learning, but companies running Ruby can get tremendous value from it.

I’m happy to announce it’s now possible to build advanced models in TensorFlow, Scikit-learn, PyTorch, and a number of other tools, and score them in Ruby with minimal friction.

To do this previously, you’d need to either:

  1. Shell out
  2. Create a microservice
  3. Use a bridge like PyCall or RSRuby

All of these approaches require managing another language in production. Luckily, there’s now a better way.

ONNX (pronounced “On-ix”) is a serialization format for storing models created by Facebook and Microsoft. It was designed for neural networks but now supports traditional ML models as well. Based on its current adoption, I won’t be surprised if it replaces PMML as the de facto interchange format for ML models.

To run ONNX models, Microsoft created ONNX Runtime, a “cross-platform, high performance scoring engine for ML models.” ONNX Runtime has a C API, which Ruby is happy to use. Thanks to FFI, it even works on JRuby!

ONNX Runtime Ruby

ONNX Runtime is designed to be fast, and Microsoft saw significant increases in performance for a number of models after deploying it.

This is another step forward for machine learning in Ruby. Earlier this month, XGBoost and LightGBM also came to Ruby.

Check out the ONNX Runtime gem today!

Published August 27, 2019 · Tweet


You might also enjoy

XGBoost and LightGBM Come to Ruby

Blind Index 1.0

Emotion Recognition in Ruby


All code examples are public domain.
Use them however you’d like (licensed under CC0).