Class NeuralNetworkModel

  • All Implemented Interfaces:
    org.apache.lucene.util.Accountable

    public class NeuralNetworkModel
    extends LTRScoringModel
    A scoring model that computes document scores using a neural network.

    Supported activation functions are: identity, relu, sigmoid, tanh, leakyrelu and contributions to support additional activation functions are welcome.

    Example configuration:

     {
       "class" : "org.apache.solr.ltr.model.NeuralNetworkModel",
       "name" : "rankNetModel",
       "features" : [
         { "name" : "documentRecency" },
         { "name" : "isBook" },
         { "name" : "originalScore" }
       ],
       "params" : {
         "layers" : [
           {
             "matrix" : [ [ 1.0, 2.0, 3.0 ],
                          [ 4.0, 5.0, 6.0 ],
                          [ 7.0, 8.0, 9.0 ],
                          [ 10.0, 11.0, 12.0 ] ],
             "bias" : [ 13.0, 14.0, 15.0, 16.0 ],
             "activation" : "sigmoid"
           },
           {
             "matrix" : [ [ 17.0, 18.0, 19.0, 20.0 ],
                          [ 21.0, 22.0, 23.0, 24.0 ] ],
             "bias" : [ 25.0, 26.0 ],
             "activation" : "relu"
           },
           {
             "matrix" : [ [ 27.0, 28.0 ],
                          [ 29.0, 30.0 ] ],
             "bias" : [ 31.0, 32.0 ],
             "activation" : "leakyrelu"
           },
           {
             "matrix" : [ [ 33.0, 34.0 ],
                          [ 35.0, 36.0 ] ],
             "bias" : [ 37.0, 38.0 ],
             "activation" : "tanh"
           },
           {
             "matrix" : [ [ 39.0, 40.0 ] ],
             "bias" : [ 41.0 ],
             "activation" : "identity"
           }
         ]
       }
     }
     

    Training libraries:

    Background reading:

    • Method Detail

      • setLayers

        public void setLayers​(Object layers)
      • score

        public float score​(float[] inputFeatures)
        Description copied from class: LTRScoringModel
        Given a list of normalized values for all features a scoring algorithm cares about, calculate and return a score.
        Specified by:
        score in class LTRScoringModel
        Parameters:
        inputFeatures - List of normalized feature values. Each feature is identified by its id, which is the index in the array
        Returns:
        The final score for a document
      • explain

        public org.apache.lucene.search.Explanation explain​(org.apache.lucene.index.LeafReaderContext context,
                                                            int doc,
                                                            float finalScore,
                                                            List<org.apache.lucene.search.Explanation> featureExplanations)
        Description copied from class: LTRScoringModel
        Similar to the score() function, except it returns an explanation of how the features were used to calculate the score.
        Specified by:
        explain in class LTRScoringModel
        Parameters:
        context - Context the document is in
        doc - Document to explain
        finalScore - Original score
        featureExplanations - Explanations for each feature calculation
        Returns:
        Explanation for the scoring of a document