Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Oryx Rescorer Examples?

Oryx Rescorer Examples?

Explorer

I've got an ALS model engine up and running, but due to a very high number of correlations between some popular products, most of my users have the same top recommendations.  I'd like to reduce the scores for those items as they're being served out.  So if a recommendation had a value of 0.85, I'd like to rescore it to a lower number (say by -0.30).

 

I've noticed there's a rescorer in the documentation, but is that part of the serving API?  Is there an example that we can refer to to learn a little bit more about it?  I'll also go grab the javadocs and do a little reading.

17 REPLIES 17

Re: Oryx Rescorer Examples?

Master Collaborator
You might get a good sense of it from usage in a unit test: https://github.com/cloudera/oryx/blob/master/als-common/src/test/java/com/cloudera/oryx/als/common/r... RescorerProvider is a factory object, and it makes a Rescorer on a per-request basis, optionally configured by stuff in a request parameter. It can return different Rescorers for different methods. You can implement AbstractRescorerProvider to only bother implementing the one you want for /recommend. The Rescorer can do whatever you like. It can filter or change scores for items. It's just two methods and you can do whatever you can do in Java there. Often one might read and cache some info about the items in order to make decisions. That can come from anywhere that you can access using Java code. You have an interesting case here, as you're trying to avoid "flooding". Just subtracting a value from all rec values, or even one that gets bigger as the values get smaller, won't change the ranking. I think the logic is more like penalizing based on similarity to things higher up the list? since the object will be used just for one request it can maintain state about what else it has seen. This gets a little hairy since you would also have to track which are the top N recs. And compute item similarities every time something makes it into the top N by calling back in the recommender. It works -- it's going to be a little bit involved. An alternative is to do it on the client side and fetch a lot more recs at a time. This is cruder but easier, potentially. I'm interested enough in anti-flooding support that I could work with you to make the above, but first let me confirm that's what you're after.

Re: Oryx Rescorer Examples?

Explorer

Thanks for the offer, Sean!  I'm working with our data governance team to see if we can share some of the data and get the ball rolling.

 

It is indeed very similar to penalizing based on similarity ... for example, if a consumer purchases a product which has multiple package sizes, I don't really want to provide 4 recommendations of the same product that they already purchased.

Re: Oryx Rescorer Examples?

New Contributor

+1

Do you have a Rescorer and a RescorerProvider class example ?

When I set my own RescorerProvider with just the minimum of code, then I call /mostPopularItems or /recommend, I always have an "empty" response. If I remove the "serving-layer.rescorer-provider-class" parameter, it works and give me results.

Re: Oryx Rescorer Examples?

Master Collaborator

Can you share your code, offline if needed? Maybe the fastest thing is for me to spot the issue in what you have.

Make sure the logic of 'isfiltered' is not backwards, or that you are not always return NaN or something from rescore().

Re: Oryx Rescorer Examples?

New Contributor

For the moment, It's a very simple rescorer with a isFiltered based on itemID. I also tried to always return false in isFiltered but API still give me empty return

I have a RescorerProvider class :

 

 

---------------

public abstract class EbRescorerProvider implements RescorerProvider {
  
  @Override
  public Rescorer getRecommendRescorer(String[] userIDs, OryxRecommender recommender, String... args) {
      return new EbRescorer(recommender);
  }

  @Override
  public Rescorer getRecommendToAnonymousRescorer(String[] itemIDs, OryxRecommender recommender, String... args) {
      return new EbRescorer(recommender);
  }

  @Override
  public Rescorer getMostPopularItemsRescorer(OryxRecommender recommender, String... args) {
      return new EbRescorer(recommender);
  }
}

-------------

 

And a rescorer :

-------------

public final class EbRescorer implements Rescorer {
    
  private final OryxRecommender recommender;
    
  EbRescorer(OryxRecommender recommender) {
    Preconditions.checkNotNull(recommender);
    this.recommender = recommender;
  }

  @Override
  public double rescore(String itemID, double value) {
    return value;
  }

  @Override
  public boolean isFiltered(String itemID) {
    if(itemID.startsWith("p_"))
        return false;
    return true;
  }

}

---------

Re: Oryx Rescorer Examples?

Master Collaborator

The logic is to only allow items whose ID starts with "p_". Without a rescorer, do you see any results starting with "p_" ?

Re: Oryx Rescorer Examples?

New Contributor

Yes, exactly. I only want items whose ID stats with "p_".

Without the rescorer  I have items with "p_".

But this code returns empty results too (so I think the problem is not the rescorer but how I implemented it):

 

public final class EbRescorer implements Rescorer {
    
  private final OryxRecommender recommender;
    
  EbRescorer(OryxRecommender recommender) {
    Preconditions.checkNotNull(recommender);
    this.recommender = recommender;
  }

  @Override
  public double rescore(String itemID, double value) {
    return value;
  }

  @Override
  public boolean isFiltered(String itemID) {
    return false;
  }

}

Re: Oryx Rescorer Examples?

Master Collaborator

That sounds very strange. This should have no effect on results.

When you say no results, do you mean an empty response or an HTTP error?

Are there errors in the log? I'm wondering if actually the whole thing did not start successfully because of failure to load the class.

Highlighted

Re: Oryx Rescorer Examples?

New Contributor

When I use the Oryx serving layer web interface, and make a /recommend without rescorer I have :

p_530f5aa122c3a7ed24ad800d,0.007898516
p_530f5aa222c3a7ed24ad82d0,0.007036238
p_530f5aa222c3a7ed24ad81b7,0.0065568457
p_530f5aa222c3a7ed24ad835b,0.0053064856
p_530f5aa122c3a7ed24ad7d5a,0.005270543
p_530f5aa122c3a7ed24ad7d3f,0.0051494255
p_530f5aa222c3a7ed24add524,0.0050481544
p_530f5aa222c3a7ed24ada2a8,0.0050481544
p_530f5aa222c3a7ed24ad9d66,0.0050481544
p_530f5aa222c3a7ed24ad8398,0.004889996

With the rescorer enabled in oryx.conf, I have :

[empty]

Nothing appear on logs.

Very strange...