Closed mk2424-cyber closed 1 month ago
My model file: it is a ightgbm model, v4 and has custom objective function using asymmetric focal loss.
There are three ways to approach this. I'm not familiar with the implementation of your custom objective function (OF), so I cannot suggest which way is the most appropriate here. But give them a try, and then tell me what worked for you.
First, is your custom OF compatible with some LightGBM's built-in OF? If it is, then simply edit your LightGBM model file and replace the contents of the [objective: ...]
attribute.
For example, if your OF is compatible with the most common regression target, insert the following into your LightGBM model file:
[objective: regression]
Second, the JPMML-LightGBM command-line application accepts a --objective
option. This way, you don't need to edit the LightGBM model file, and can make a "in-memory edit" to the file being converted:
$ java -jar pmml-lightgbm-example-executable-1.5-SNAPSHOT.jar --lgbm-input mymodel.txt --pmml-output mymodel.pmml --objective <your objective function's specification>
This command-line option was added based on some user's request a while ago. There should be a GitHub issue (in "closed" state) about its usage. Find it yourself.
Third, if your OF is performing actual computations during prediction time (such as applying some transformation to the interim LightGBM booster score), then you need to implement your own subclass of org.jpmml.lightgbm.ObjectiveFunction
, and register with the JPMML-LightGBM runtime.
You can browse the implementations of built-in OF classes for inspiration. For example, PoissonRegression and BinomialLogisticRegression
the JPMML-LightGBM command-line application accepts a --objective option
The Java code for parsing this command-line argument is here: https://github.com/jpmml/jpmml-lightgbm/blob/1.5.4/pmml-lightgbm/src/main/java/org/jpmml/lightgbm/LightGBMUtil.java#L97-L132
So, the syntax appears to be "Java OF class name, followed by a whitespace-separated list of OF config entries"
For example:
java -jar pmml-lightgbm-example-executable-1.5-SNAPSHOT.jar --objective "org.jpmml.lightgbm.Regression(metric:l2)" --lgbm-file <path> --pmml-file <path>
I simplified the format of command-line OF strings somewhat in the latest 1.5.5 version. Specifically, the "config section" is now optional.
Earlier:
java -jar pmml-lightgbm-example-executable-1.5.4.jar --objective "org.jpmml.lightgbm.Regression(regression metric:l2)" ...
Now:
java -jar pmml-lightgbm-example-executable-1.5.5.jar --objective org.jpmml.lightgbm.Regression ...
Some more command-line OF string examples: https://github.com/jpmml/jpmml-lightgbm/blob/1.5.5/pmml-lightgbm/src/test/java/org/jpmml/lightgbm/LightGBMUtilTest.java#L29-L58
Thank you very much! I went with option 1, it was the simplest for my use case. I added the objective in the model file and it worked like a charm. Cheers!
My model file: it is a ightgbm model, v4 and has custom objective function using asymmetric focal loss.
What I’ve tried: Using 1.5.4 jar file (also attempted 1.4.7) and unable to create pmml file for my lightgbm v4 model.
Command:
Error:
How do I solve this issue?