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?

Re: Oryx Rescorer Examples?

New Contributor

I don't know why I was getting this problem, but I made a "git pull" on Oryx and know it works.

I just realised there is a good example of Rescorer / RescorerProvider implementation in :

/als-serving/src/main/java/com/cloudera/oryx/als/serving/example

Re: Oryx Rescorer Examples?

Master Collaborator

That's good, but I can't think of any relevant change to this part recently. I can imagine a number of reasons why that might have fixed some accident of your build, but not sure. 

 

In any event your implementation looks fine. I will run something similar here as a sanity check to make sure there is not some obvious problem in this case.

Re: Oryx Rescorer Examples?

Master Collaborator

Hmm, there was this change:

 

https://github.com/cloudera/oryx/commit/6db07121045ec4d801f77df12e252afffd08b323

 

That's just a package move. I would imagine that if you were building against the class in the wrong package you would see a much clearer runtime error about not finding a class though.

 

Roughly what version were you using before updating to HEAD just now?

Re: Oryx Rescorer Examples?

Master Collaborator

By the way I noticed your RescorerProvider is abstract. It needs to be concrete. You probably want to extent AbstractRescorerProvider so as to not have to implement every method, as I see you have done. So maybe that is what you actually did in the code you ran?

Re: Oryx Rescorer Examples?

New Contributor

Yes, I changed the RescorerProvider to concrete before the code ran.

I didn't note the version of Oryx I used before my last pull.

 

Here is my working code :

 

 

public final class EbRescorer implements Rescorer, PairRescorer {
    
  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;
  }

  @Override
  public double rescore(String fromID, String toID, double originalScore) {
    return originalScore; // Assume we already checked whether it was filtered
  }

  @Override
  public boolean isFiltered(String fromID, String toID) {
    return false;
  }
  
}
public final 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);
  }

  @Override
  public PairRescorer getMostSimilarItemsRescorer(OryxRecommender recommender, String... args) {
    return new EbRescorer(recommender);
  }
}
And thanks a lot srowen for your reactivity. I was totally blocked and now I can start to play :)

Re: Oryx Rescorer Examples?

Master Collaborator

For what it's worth, it seemed to work fine for me on a toy example. I got the subset of results I expected with your filter.

 

(PS in your rescorer you don't actually need a reference to the recommender. It doesn't hurt, just superfluous)

Re: Oryx Rescorer Examples?

Explorer

Sean,

 

I have questions about Oryx rescorer...

 

(1) Can you explain about the workflow when applying the rescorer to /similarity/ end point ?

Say, /similarity/123, is it getting the list of similarity results' item IDs first and then apply the filtering and re-scoring ?

Or, it's applying the filtering and re-scoring first, and then compute the similarity scores for the filtered IDs (with the re-scores, if provided) ?

 

(2) Can you explain a little bit on the functions of interfaces RescorerProvider, Rescorer and PairRescorer? High level with calling workflow would be fine.

 

Thanks.

Re: Oryx Rescorer Examples?

Master Collaborator

The workflow should be: for each item, skip it if filtered. Otherwise, compute the similarity, then apply the rescoring.

 

RescorerProvider is a factory object that you provide to make Rescorer, or PairRescorer, implementations for use in various methods. PairRescorer is there as an optimization for the case where you're rescoring as a function of two IDs, not one.