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
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:
- 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 ClassesModifier and TypeClassDescriptionprotected static interfaceclassstatic interface -
Field Summary
Fields inherited from class org.apache.solr.ltr.model.LTRScoringModel
features, name, normsFields inherited from interface org.apache.lucene.util.Accountable
NULL_ACCOUNTABLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected NeuralNetworkModel.Layerorg.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.voidprotected 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, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.lucene.util.Accountable
getChildResources
-
Constructor Details
-
NeuralNetworkModel
-
-
Method Details
-
createLayer
-
setLayers
-
validate
Description 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
-