Package org.apache.solr.ltr.model
Class NeuralNetworkModel
- java.lang.Object
-
- org.apache.solr.ltr.model.LTRScoringModel
-
- org.apache.solr.ltr.model.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,leakyreluand 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:
- Keras is a high-level neural networks API, written in Python. A Keras and Solr implementation of RankNet can be found at https://github.com/airalcorn2/RankNet.
Background reading:
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interfaceNeuralNetworkModel.ActivationclassNeuralNetworkModel.DefaultLayerstatic interfaceNeuralNetworkModel.Layer
-
Field Summary
-
Fields inherited from class org.apache.solr.ltr.model.LTRScoringModel
features, name, norms
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected NeuralNetworkModel.LayercreateLayer(Object o)org.apache.lucene.search.Explanationexplain(org.apache.lucene.index.LeafReaderContext context, int doc, float finalScore, List<org.apache.lucene.search.Explanation> featureExplanations)Similar to the score() function, except it returns an explanation of how the features were used to calculate the score.floatscore(float[] inputFeatures)Given a list of normalized values for all features a scoring algorithm cares about, calculate and return a score.voidsetLayers(Object layers)protected voidvalidate()Validate that settings make sense and throwsModelExceptionif they do not make sense.-
Methods inherited from class org.apache.solr.ltr.model.LTRScoringModel
equals, getAllFeatures, getFeatures, getFeatureStoreName, getInstance, getName, getNormalizerExplanation, getNorms, getParams, hashCode, normalizeFeaturesInPlace, ramBytesUsed, toString
-
-
-
-
Method Detail
-
createLayer
protected NeuralNetworkModel.Layer createLayer(Object o)
-
setLayers
public void setLayers(Object layers)
-
validate
protected void validate() throws ModelExceptionDescription copied from class:LTRScoringModelValidate that settings make sense and throwsModelExceptionif they do not make sense.- Overrides:
validatein classLTRScoringModel- Throws:
ModelException
-
score
public float score(float[] inputFeatures)
Description copied from class:LTRScoringModelGiven a list of normalized values for all features a scoring algorithm cares about, calculate and return a score.- Specified by:
scorein classLTRScoringModel- 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:LTRScoringModelSimilar to the score() function, except it returns an explanation of how the features were used to calculate the score.- Specified by:
explainin classLTRScoringModel- Parameters:
context- Context the document is indoc- Document to explainfinalScore- Original scorefeatureExplanations- Explanations for each feature calculation- Returns:
- Explanation for the scoring of a document
-
-