Nyoka - yet another snake in the Python Zoo

Support for data science with Python

In this article we introduce Nyoka, a new Python-based library that exports predictive models from popular machine learning/deep learning frameworks to PMML. Using Nyoka, data scientists can standardize and accelerate the deployment process for predictive models.

By Alexander Lemm, Sr. Product Manager, Predictive Analytics, Software AG and Dr. Rainer Burkhardt, Sr. Director, AI Analytics, Software AG

Issue 4, 2018 Download PDF


In August, Software AG released Nyoka on GitHub®, a Python library for data scientists. But what is Nyoka exactly and what does it stand for? Using Nyoka, a data scientist can export predictive models created with popular Python-based machine learning or deep learning frameworks into PMML (see figure 1 below). "Nyoka" originates from Zulu and means "snake," hence the close connection to its Python cousin.

Fig 1: Supported Machine Learning and Deep Learning Frameworks

PMML is an XML-based predictive model interchange format and the leading standard for statistical and machine learning models. The Data Mining Group (DMG) is an independent, vendor-led consortium that supports and drives the development of PMML for nearly 20 years now.

Nyoka underscores Software AG's Artificial Intelligence (AI) strategy and vision of open industry standards: PMML as the unifying standard for machine learning AND deep learning models.

Nyoka in action

Let us check out a simple example on how you can use Nyoka to export a pre-trained MobileNet model for image recognition from Keras to PMML. Here we assume that you already loaded all necessary libraries into memory.

# load pretrained keras mobilenet model
model = mobilenet.MobileNet(input_shape=(224, 224, 3), alpha=1.0, depth_multiplier=1,
                            dropout=1e-3, include_top=True, weights='imagenet',
                            input_tensor=None, pooling=None, classes=1000)
# convert mobilnet model to PMML
cnn_pmml = KerasToPmml(model, model_name="KerasMobileNet", dataSet="ImageNet")
# Save mobilenet PMML to disk
cnn_pmml.export(open("mobilenet_demo.pmml, "w"),0)

Constructing an object named cnn_pmml as an instance of the Nyoka class KerasToPMML() is all you need to do to convert the MobileNet model into its PMML representation. Saving it to disk is done by calling the method export().

But what is a PMML file good for when you don't leverage it for predicting new and unseen values – which are in our case unclassified images?

To do just this, we use one execution engine for PMML files, the Zementis Server, Software AG's flagship product in the AI domain. Therefore, deploying the created PMML file from the example above to a Zementis Server instance is next. We assume again that you already loaded all necessary libraries into memory.

pmml_file = open(mobilenet_demo.pmml,"r")
pmml = {'file': pmml_file}
pmml_upload = requests.post(adapaRS + "model/", files=pmml, auth=auth, verify=False,
                            params = {"applyCleanser": "FALSE"})

The model is now deployed to a Zementis Server instance and can be executed to classify any unseen image. We will send the following picture to the server showing a great white shark.

Fig 2: Image we are going to Classify

f = open("shark_224_224.png", "rb")
files ={'file':f.read()}
 resp = requests.post(adapaRS+'apply/KerasMobileNet' , auth=auth,

Curious what the classification result from the Zementis Server is? Let's check it out!

  "model" : "KerasMobileNet",
  "outputs" : [ {
    "top1_prob" : 0.9951145648956299,
    "predictedValue_predictions" : "great_white_shark",
    "top5_prob" : "great_white_shark:0.9951145648956299,tiger_shark:0.0029412976000458,sturgeon:0.0012288052821531892,dugong:3.0053118825890124E-4,killer_whale:2.2845140483696014E-4"
  } ]

As you can see, the deployed MobileNet model classifies the image as a great white shark with an probability of 99.5%.
Examining the output you see that Zementis Server not just gives you the best classification result and the respective probability but in fact the five best results.


In this article we just scratched the surface of Nyoka's capabilities. With Nyoka you can even create your own exporters for specialized/individual model types.

You would like to learn more about Nyoka and make a deep dive yourself? Please check out the following links:

  • Nyoka is available on GitHub including Docs and comes with Jupyter notebook based tutorials. And if you have feedback and questions about Nyoka - just open a GitHub issue and we'll get back to you!
  • If you would like to go one step further and put your generated PMML files into action, get a free trial license for Zementis Server, our PMML execution engine.

Learn more about Zementis and download your free trial today.