Question

I have a PMML file of a trained Artificial Neural Network (ANN). I would like to create a Java method which simply takes in the inputs and returns the targeted value.

This seems pretty easy, but I do not know how realize it.

The PMML Version = 3.0

Update: 24.05.2013

I tried to use the jpmml Java API.

This is how I have done:

(1) Downloaded via Maven Central Repository (link) three .Jar files:

  • pmml-manager-1.0.2.jar
  • pmml-model-1.0.2.jar
  • pmml-evaluator-1.0.2.jar

(2) Used eclipse to "configure Build path" and added those three external .Jar's

(3) Import my PMML-File named "text.xml" ( an artificial neural network (ANN)) PMML version="3.0"

(4) Tried to run an example "TreeModelTraversalExample.java" provided by the jpmml-project

Obviously it did not work for some reasons:

  • the mentioned example is not for ANN's. How to rewrite it?
  • my PMML-file is in XML-format. Is it the right format?
  • I do not know how to handle or to add Java API's. Should I even add those by "configure build path" in eclipse?

Obvious fact #2, I have no clue what I do :-)

Thanks again and kindest regards.

Stefan

Was it helpful?

Solution

JPMML should be able to handle PMML 3.X and newer versions of NeuralNetwork models without problem. Moreover, it should be able to handle all the normalization and denormalization transformations that may accompany such models.

I could use a clarification that why are you interested in converting PMML models to Java code in the first place. This complicates the whole matter a lot and it doesn't add any value. The JPMML library itself is rather compact and has minimal external dependencies (at the moment of writing this, it only depends on commons-math). There shouldn't be much difference performance-wise. You can reasonably expect to obtain up to 10'000 scorings/sec on a modern desktop computer.

The JPMML codebase has recently moved to GitHub: http://github.com/jpmml/jpmml

Fellow coders in Turn Inc. have forked this codebase and are implementing PMML-to-Java translation (see top-level module "pmml-translation") for selected model types: https://github.com/turn/jpmml

At the moment I recommend you to check out the Openscoring project (uses JPMML internally): http://www.openscoring.org

Then, you could try the following:

  1. Deploy your XML file using the HTTP PUT method.
  2. Get your model summary information using the HTTP GET method. If the request succeeds (as opposed to failing with an HTTP status 500 error code) then your model is well supported.
  3. Execute the model either in single prediction mode or batch prediction mode using the HTTP POST method. Try sending larger batches to see if it meets your performance requirements.
  4. Undeploy the model using the HTTP DELETE method.

You can always try contacting project owners for more insight. I'm sure they are nice people.

OTHER TIPS

Another approach would be to use the Cascading API. There's a library called "Pattern" for Cascading, which translates PMML models into Cascading apps in Java. https://github.com/Cascading/pattern

Generally those are for Hadoop jobs; however, if you use the "local mode" flow planner in Cascading, it can be built as a JAR file to include with some other Java app.

There is work in progress for ANN models. Check on the developer email list: https://groups.google.com/forum/?fromgroups#!forum/pattern-user

I think this might do what you need. It is an open source library that claims to be able to read and evaluate pmml neural networks. I have not tried it.

https://code.google.com/p/jpmml/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top