Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException when passing properties as primitives #32

Closed
enragedginger opened this issue Jan 26, 2025 · 4 comments
Closed

NullPointerException when passing properties as primitives #32

enragedginger opened this issue Jan 26, 2025 · 4 comments

Comments

@enragedginger
Copy link

I was training a basic SGD regression model like so:

(def sgd-ada-model-pipeline
  (ml-core/pipeline
    {:metamorph/id :model}
    (ml-mm/model
      {:model-type          :scicloj.ml.tribuo/regression
       :tribuo-components   [{:name "squared"
                              :type "org.tribuo.regression.sgd.objectives.SquaredLoss"}
                             {:name "ada"
                              :type "org.tribuo.math.optimisers.AdaGrad"
                              :properties {:initialLearningRate 0.01
                                           :epsilon 1.0E-6
                                           :initialValue 0.0}}
                             {:name       "trainer"
                              :type       "org.tribuo.regression.sgd.linear.LinearSGDTrainer"
                              :properties {:optimiser "ada"
                                           :epochs        "100"
                                           :minibatchSize "1"
                                           :objective     "squared"}}]
       :tribuo-trainer-name "trainer"})))

(let [eval-ds {:train (:train-ds split-dataset)
               :test  (:test-ds split-dataset)}]
  (ml/evaluate-pipelines [sgd-ada-model-pipeline] [eval-ds] ml-loss/rmse :loss))

This resulted in a NullPointerException that looked something like this:

malli.core/-instrument/fn                       core.cljc: 2634
                                                                          clojure.core/apply                        core.clj:  667
                                                                                         ...                                      
                                                                   malli.core/-instrument/fn                       core.cljc: 2616
                                                                          clojure.core/apply                        core.clj:  667
                                                                                         ...                                      
                                                     scicloj.metamorph.ml/evaluate-pipelines                          ml.clj:  503
                                                                                         ...                                      
                                                                   malli.core/-instrument/fn                       core.cljc: 2634
                                                                          clojure.core/apply                        core.clj:  667
                                                                                         ...                                      
                                                                   malli.core/-instrument/fn                       core.cljc: 2616
                                                                          clojure.core/apply                        core.clj:  667
                                                                                         ...                                      
                                                     scicloj.metamorph.ml/evaluate-pipelines                          ml.clj:  480
                                                                           clojure.core/mapv                        core.clj: 6971
                                                                         clojure.core/reduce                        core.clj: 6887
                                                                 clojure.core.protocols/fn/G                   protocols.clj:   13
                                                                   clojure.core.protocols/fn                   protocols.clj:   75
                                                           clojure.core.protocols/seq-reduce                   protocols.clj:   24
                                                                            clojure.core/seq                        core.clj:  139
                                                                                         ...                                      
                                                            clojure.core/map-indexed/mapi/fn                        core.clj: 7377
                                                            pppmap.core/map-with-progress/fn                        core.clj:   72
                                                  scicloj.metamorph.ml/evaluate-pipelines/fn                          ml.clj:  470
                                                  scicloj.metamorph.ml/evaluate-one-pipeline                          ml.clj:  230
                                                                           clojure.core/mapv                        core.clj: 6971
                                                                         clojure.core/reduce                        core.clj: 6887
                                                                 clojure.core.protocols/fn/G                   protocols.clj:   13
                                                                   clojure.core.protocols/fn                   protocols.clj:   75
                                                           clojure.core.protocols/seq-reduce                   protocols.clj:   24
                                                                            clojure.core/seq                        core.clj:  139
                                                                                         ...                                      
                                          scicloj.metamorph.ml/evaluate-one-pipeline/iter/fn                          ml.clj:  210
                                       scicloj.metamorph.ml/evaluate-one-pipeline/iter/fn/fn                          ml.clj:  213
                                                            scicloj.metamorph.ml/calc-metric                          ml.clj:  130
                                                                     clojure.core/partial/fn                        core.clj: 2641
                                                       scicloj.metamorph.core/local-pipeline                        core.clj:   35
                                                                         clojure.core/reduce                        core.clj: 6886
                                                                                         ...                                      
                                                    scicloj.metamorph.core/process-operation                        core.clj:   25
                                                                                         ...                                      
                                                                   malli.core/-instrument/fn                       core.cljc: 2616
                                                                          clojure.core/apply                        core.clj:  667
                                                                                         ...                                      
                                                               scicloj.metamorph.ml/model/fn                          ml.clj:  901
                                                                                         ...                                      
                                                                   malli.core/-instrument/fn                       core.cljc: 2616
                                                                          clojure.core/apply                        core.clj:  667
                                                                                         ...                                      
                                                                  scicloj.metamorph.ml/train                          ml.clj:  616
                                                          scicloj.ml.tribuo/train-regression                      tribuo.clj:  167
                                                              scicloj.ml.tribuo/make-trainer                      tribuo.clj:   16
                                                                 tech.v3.libs.tribuo/trainer                      tribuo.clj:  326
                               com.oracle.labs.mlrg.olcut.config.ConfigurationManager.lookup       ConfigurationManager.java: 1321
                               com.oracle.labs.mlrg.olcut.config.ConfigurationManager.lookup       ConfigurationManager.java: 1378
                          com.oracle.labs.mlrg.olcut.config.ConfigurationManager.innerLookup       ConfigurationManager.java: 1395
                                    com.oracle.labs.mlrg.olcut.config.PropertySheet.getOwner              PropertySheet.java:  259
                                    com.oracle.labs.mlrg.olcut.config.PropertySheet.getOwner              PropertySheet.java:  326
                                                 java.security.AccessController.doPrivileged           AccessController.java:  571
                           com.oracle.labs.mlrg.olcut.config.PropertySheet.lambda$getOwner$1              PropertySheet.java:  341
                         com.oracle.labs.mlrg.olcut.config.PropertySheet.setConfiguredFields              PropertySheet.java:  444
                            com.oracle.labs.mlrg.olcut.config.PropertySheet.parseSimpleField              PropertySheet.java:  825
                               com.oracle.labs.mlrg.olcut.config.ConfigurationManager.lookup       ConfigurationManager.java: 1321
                               com.oracle.labs.mlrg.olcut.config.ConfigurationManager.lookup       ConfigurationManager.java: 1378
                          com.oracle.labs.mlrg.olcut.config.ConfigurationManager.innerLookup       ConfigurationManager.java: 1395
                                    com.oracle.labs.mlrg.olcut.config.PropertySheet.getOwner              PropertySheet.java:  259
                                    com.oracle.labs.mlrg.olcut.config.PropertySheet.getOwner              PropertySheet.java:  326
                                                 java.security.AccessController.doPrivileged           AccessController.java:  571
                           com.oracle.labs.mlrg.olcut.config.PropertySheet.lambda$getOwner$1              PropertySheet.java:  341
                         com.oracle.labs.mlrg.olcut.config.PropertySheet.setConfiguredFields              PropertySheet.java:  442
                                 com.oracle.labs.mlrg.olcut.config.PropertySheet.flattenProp              PropertySheet.java:  209
                               com.oracle.labs.mlrg.olcut.config.PropertySheet.flattenString              PropertySheet.java:  213
com.oracle.labs.mlrg.olcut.config.property.ImmutableGlobalProperties.replaceGlobalProperties  ImmutableGlobalProperties.java:  129
                                                             java.util.regex.Pattern.matcher                    Pattern.java: 1180
                                                              java.util.regex.Matcher.<init>                    Matcher.java:  256
                                                               java.util.regex.Matcher.reset                    Matcher.java:  432
                                                       java.util.regex.Matcher.getTextLength                    Matcher.java: 1779

I spent 30+ minutes debugging this and fixed the error by passing the values in :properties as strings instead of primitives as I have it above.

Passing these values as strings is fine IMO, but it'd be nice to have a helpful validation check to alert me of this error in the future. Thoughts?

@behrica
Copy link
Member

behrica commented Jan 26, 2025

Yes, the tribuo configuration requires String for the properties.
The Clojure code in "scicloj.ml.tribuo" (https://github.com/scicloj/scicloj.ml.tribuo)
(so not in this library)

does only "forward" what it gets to Tribuo Java.

And this seems not do do any error checking or giving better error messages for this specific case.
(it gives better errors for other cases, like unknown parameters)

@behrica
Copy link
Member

behrica commented Jan 26, 2025

Currently we do "zero parsing or error checking" on the configuration map and I would not know where to start and where to stop this validation.

In my view, Tribuo needs to solve this.

In this folder there are lots of "edn" examples:

https://github.com/oracle/olcut/tree/main/olcut-config-edn/src/test/resources/com/oracle/labs/mlrg/olcut/config/edn/test

I updated as well the documentation and hint on this issue:
https://github.com/scicloj/scicloj.ml.tribuo/blob/master/README.md

@behrica
Copy link
Member

behrica commented Jan 26, 2025

I opened a bug report with "olcut":
oracle/olcut#74

@enragedginger
Copy link
Author

Sounds good. Thanks for looking into this and opening that other bug!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants