-
Notifications
You must be signed in to change notification settings - Fork 436
fix: read trace post ids from info payload #209
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
Open
sztoplover-bit
wants to merge
1
commit into
camel-ai:main
Choose a base branch
from
sztoplover-bit:fix/recsys-trace-post-id
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,6 +61,25 @@ | |
| date_score = [] | ||
|
|
||
|
|
||
| def _extract_trace_post_id(trace: Dict[str, Any]) -> Any | None: | ||
| """Safely extract a post_id from a trace row's serialized info payload.""" | ||
| info = trace.get('info') | ||
| if info is None: | ||
| return None | ||
|
|
||
| if isinstance(info, dict): | ||
| return info.get('post_id') | ||
|
|
||
| try: | ||
| parsed_info = literal_eval(info) | ||
| except (ValueError, SyntaxError): | ||
| return None | ||
|
|
||
| if isinstance(parsed_info, dict): | ||
| return parsed_info.get('post_id') | ||
| return None | ||
|
|
||
|
|
||
| def get_twhin_tokenizer(): | ||
| global twhin_tokenizer | ||
| if twhin_tokenizer is None: | ||
|
|
@@ -367,10 +386,13 @@ def get_like_post_id(user_id, action, trace_table): | |
| list: List of post IDs. | ||
| """ | ||
| # Get post IDs from trace table for the given user and action | ||
| trace_post_ids = [ | ||
| literal_eval(trace['info'])["post_id"] for trace in trace_table | ||
| if (trace['user_id'] == user_id and trace['action'] == action) | ||
| ] | ||
| trace_post_ids = [] | ||
| for trace in trace_table: | ||
| if trace['user_id'] != user_id or trace['action'] != action: | ||
| continue | ||
| post_id = _extract_trace_post_id(trace) | ||
| if post_id is not None: | ||
| trace_post_ids.append(post_id) | ||
| """Only take the last 5 liked posts, if not enough, pad with the most | ||
| recently liked post. Only take IDs, not content, because calculating | ||
| embeddings for all posts again is very time-consuming, especially when the | ||
|
|
@@ -666,10 +688,13 @@ def get_trace_contents(user_id, action, post_table, trace_table): | |
| list: List of post contents. | ||
| """ | ||
| # Get post IDs from trace table for the given user and action | ||
| trace_post_ids = [ | ||
| trace['post_id'] for trace in trace_table | ||
| if (trace['user_id'] == user_id and trace['action'] == action) | ||
| ] | ||
| trace_post_ids = [] | ||
| for trace in trace_table: | ||
| if trace['user_id'] != user_id or trace['action'] != action: | ||
| continue | ||
| post_id = _extract_trace_post_id(trace) | ||
| if post_id is not None: | ||
| trace_post_ids.append(post_id) | ||
| # Fetch post contents from post table where post IDs match those in the | ||
| # trace | ||
| trace_contents = [ | ||
|
|
@@ -784,8 +809,10 @@ def rec_sys_personalized_with_trace( | |
| swap_free_ids = [ | ||
| post_id for post_id in post_ids | ||
| if post_id not in rec_post_ids and post_id not in [ | ||
| trace['post_id'] | ||
| for trace in trace_table if trace['user_id'] | ||
| trace_post_id for trace_post_id in ( | ||
| _extract_trace_post_id(trace) | ||
| for trace in trace_table | ||
| ) if trace_post_id is not None | ||
|
Comment on lines
+812
to
+815
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic changed compare to original implementation. In the original implementation, it is to get the |
||
| ] | ||
| ] | ||
| rec_post_ids = swap_random_posts(rec_post_ids, swap_free_ids, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Use
extract_trace_post_idinstead of_extract_trace_post_idmay better align with other functions, what do you think?