LIBLINEAR model lacks weight(s) when training for SolrFeatures in LTR

271 views Asked by At

I am using Solr 7.4.0, and using LIBLINEAR to do the training for the LTR model based on this example: https://github.com/bloomberg/lucene-solr/blob/master-ltr/solr/contrib/ltr/example/README.md

However, I found that when I wanted to train for solr filter query with the class SolrFeature, I will get the following error saying that the model lacks weight(s):

Exception: Status: 400 Bad Request
Response: {
  "responseHeader":{
    "status":400,
    "QTime":1},
  "error":{
     "metadata":[
      "error-class","org.apache.solr.common.SolrException",
      "root-error-class","org.apache.solr.ltr.model.ModelException"],
      "msg":"org.apache.solr.ltr.model.ModelException: Model myModel lacks weight(s) for [category]",

This is how I define it in my feature JSON file:

  {
    "store" : "myFeatures",
    "name" : "category",
    "class" : "org.apache.solr.ltr.feature.SolrFeature",
    "params" : {
        "fq": ["{!terms f=category}book"]
    }
  }

What could be the reason that causes this, and how can we resolve this issue?

2

There are 2 answers

2
Balaji Swaminathan On

The reason could be weights param missing on *model.json you created using the above feature json file. So, please make sure you have included weight param for each feature defined on your feature json file.

Your *model.json file should look something like below,

{
  "class" : "org.apache.solr.ltr.model.LinearModel",
  "name" : "myModel",
  "features" : [
    { "name" : "documentRecency" },
    { "name" : "isBook" },
    { "name" : "originalScore" }
  ],
  **"params" : {
    "weights" : {
      "documentRecency" : 1.0,
      "isBook" : 0.1,
      "originalScore" : 0.5
    }
  }**
}

For more info please refer Solr 7.4 documentation.

Thanks.

0
Edwin Yeo On

I have found that it is due to insufficient training data that are related to that feature, and it could not teach the model of the appropriate weight for the feature, which resulted in the error.

After I add more entries that are related to that features to the training data, the issues did not occur.