-
Notifications
You must be signed in to change notification settings - Fork 9
<feat/recommendation> Implement a simple ranking model #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
from recommendation_system.ranking_layer.base import BaseRankingModel | ||
|
||
class SimpleRankingModel(BaseRankingModel): | ||
def __init__(self) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx for annotating mypy typing!
"ranking_model": "demo", | ||
"ranking_model": "simple", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! we have ranking right now~
def rank(self, user_features: Dict, candidates: List[List[Dict]], top_k: int) -> List[Dict]: | ||
candidates = self.process_data(candidates=candidates) | ||
rankings = self.calc_candidate_score(candidates=candidates) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, very clear!
def get_item(self, item): | ||
return deepcopy(self._items_mapping[item]) | ||
|
||
def calc_candidate_score(self, candidates): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def calc_candidate_score(self, candidates): | |
def _calc_candidate_score(self, candidates): |
|
||
return sorted(candidate_ranking.items(), key=lambda d: d[1], reverse=True) | ||
|
||
def process_data(self, candidates: List[List[Dict]]) -> List[List[Tuple]]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def process_data(self, candidates: List[List[Dict]]) -> List[List[Tuple]]: | |
def _process_data(self, candidates: List[List[Dict]]) -> List[List[Tuple]]: |
return sorted(candidate_ranking.items(), key=lambda d: d[1], reverse=True) | ||
|
||
def process_data(self, candidates: List[List[Dict]]) -> List[List[Tuple]]: | ||
items_mapping = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
items_mapping = {} | |
items_mapping = defaultdict(dict) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, would you add typing
for items_mapping
? seems to me it's the key data structure of your algorithm. Might be worth annotating~
items_mapping = {} | ||
new_candidates = [] | ||
|
||
for ranker in candidates: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why ranker
is in candidates?
I'm not sure if I understand what does this ranker stand for 😅
new_item = self.get_item(item) | ||
new_item['score'] = score |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you'd calculated score in calc_candiate_score
func, then maybe you can return item along with score
field right? thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall LGTM
Fixes #[include a number of issue this PR is fixing].
Summary of changes proposed in this Pull Request:
PR checklist: