Package org.apache.solr.ltr.model
Class LTRScoringModel
java.lang.Object
org.apache.solr.ltr.model.LTRScoringModel
- All Implemented Interfaces:
org.apache.lucene.util.Accountable
- Direct Known Subclasses:
AdapterModel,LinearModel,MultipleAdditiveTreesModel,NeuralNetworkModel
A scoring model computes scores that can be used to rerank documents.
A scoring model consists of
- a list of features (
Feature) and - a list of normalizers (
Normalizer) plus - parameters or configuration to represent the scoring algorithm.
Example configuration (snippet):
{
"class" : "...",
"name" : "myModelName",
"features" : [
{
"name" : "isBook"
},
{
"name" : "originalScore",
"norm": {
"class" : "org.apache.solr.ltr.norm.StandardNormalizer",
"params" : { "avg":"100", "std":"10" }
}
},
{
"name" : "price",
"norm": {
"class" : "org.apache.solr.ltr.norm.MinMaxNormalizer",
"params" : { "min":"0", "max":"1000" }
}
}
],
"params" : {
...
}
}
LTRScoringModel is an abstract class and concrete classes must implement the score(float[]) and explain(LeafReaderContext, int, float, List) methods.
-
Field Summary
FieldsFields inherited from interface org.apache.lucene.util.Accountable
NULL_ACCOUNTABLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanabstract 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.static LTRScoringModelgetInstance(SolrResourceLoader solrResourceLoader, String className, String name, List<Feature> features, List<Normalizer> norms, String featureStoreName, List<Feature> allFeatures, Map<String, Object> params) getName()org.apache.lucene.search.ExplanationgetNormalizerExplanation(org.apache.lucene.search.Explanation e, int idx) getNorms()inthashCode()voidnormalizeFeaturesInPlace(float[] modelFeatureValues) Goes through all the stored feature values, and calculates the normalized values for all the features that will be used for scoring.longabstract floatscore(float[] modelFeatureValuesNormalized) Given a list of normalized values for all features a scoring algorithm cares about, calculate and return a score.toString()protected voidvalidate()Validate that settings make sense and throwsModelExceptionif they do not make sense.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.lucene.util.Accountable
getChildResources
-
Field Details
-
name
-
features
-
norms
-
-
Constructor Details
-
LTRScoringModel
-
-
Method Details
-
getInstance
public static LTRScoringModel getInstance(SolrResourceLoader solrResourceLoader, String className, String name, List<Feature> features, List<Normalizer> norms, String featureStoreName, List<Feature> allFeatures, Map<String, Object> params) throws ModelException- Throws:
ModelException
-
validate
Validate that settings make sense and throwsModelExceptionif they do not make sense.- Throws:
ModelException
-
getNorms
- Returns:
- the norms
-
getName
- Returns:
- the name
-
getFeatures
- Returns:
- the features
-
getParams
-
hashCode
public int hashCode() -
equals
-
ramBytesUsed
public long ramBytesUsed()- Specified by:
ramBytesUsedin interfaceorg.apache.lucene.util.Accountable
-
getAllFeatures
-
getFeatureStoreName
-
score
public abstract float score(float[] modelFeatureValuesNormalized) Given a list of normalized values for all features a scoring algorithm cares about, calculate and return a score.- Parameters:
modelFeatureValuesNormalized- 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 abstract org.apache.lucene.search.Explanation explain(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.- 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
-
toString
-
normalizeFeaturesInPlace
public void normalizeFeaturesInPlace(float[] modelFeatureValues) Goes through all the stored feature values, and calculates the normalized values for all the features that will be used for scoring. -
getNormalizerExplanation
public org.apache.lucene.search.Explanation getNormalizerExplanation(org.apache.lucene.search.Explanation e, int idx)
-