251 expand preference model#252
Conversation
| r"\bwithout\b.*\b{value}\b", | ||
| r"\b{value}\s+(?:heavy|packed)\b", | ||
| ) | ||
| POSITIVE_PATTERNS = ( |
There was a problem hiding this comment.
It's the easiest solution so far
I think we could use llm to extract prefs in the future
| continue | ||
| self._item_preferences.set_preference(KEY_ITEM_ID, item_id, rating) | ||
|
|
||
| def _collect_slot_value_ratings(self) -> Dict[str, Dict[str, List[float]]]: |
There was a problem hiding this comment.
This is later used to compute the user’s long term preference score for each slot value pair
|
|
||
| self._update_session_preference(slot, value, score) | ||
|
|
||
| def _update_existing_preference( |
There was a problem hiding this comment.
it looks up the current score for slot=value
checks whether the new signal is positive or negative
moves the score by one UPDATE_STEP in that direction
increments the count for that preference
| preference_store.set_preference(slot, value, new_score) | ||
| preference_counts[key] = max(1, old_count) + 1 | ||
|
|
||
| def _update_session_preference( |
There was a problem hiding this comment.
if the session preference already exists, it updates it using the normal step-based rule
if it is new, it creates it in the session layer with an initial score of 2 * UPDATE_STEP
| + session_count | ||
| ) | ||
|
|
||
| def _extract_matched_values(self, text_lower: str) -> List[Tuple[str, str]]: |
There was a problem hiding this comment.
it looks for known preference values already stored in the model
then it looks for possible values from the item catalog
|
|
||
| self._apply_text_update(text) | ||
|
|
||
| def _rank_preferences(self) -> List[Tuple[str, str, float]]: |
There was a problem hiding this comment.
it combines long-term and session preferences
if the same slot=value exists in both, the session version overrides the long-term one
| ), | ||
| ) | ||
|
|
||
| def get_preference_summary(self, max_preferences: int = 20) -> str: |
|
|
||
| @abstractmethod | ||
| def get_preference_summary(self, max_preferences: int = 10) -> str: | ||
| """Returns a compact preference summary for prompts.""" |
There was a problem hiding this comment.
Nit: Docstring does not follow guidelines (e.g., missing args and raises sections).
| item_collection=item_collection, | ||
| preference_model=preference_model, | ||
| ) | ||
| self._preference_model = self.preference_model |
There was a problem hiding this comment.
This is redundant, you can simple use self.preference_model.
| return ( | ||
| self._initial_prompt | ||
| + "\n" | ||
| + self._preference_context |
There was a problem hiding this comment.
Nit: Why note have a "\n" after like for the other elements of the prompt?
| persona_text = ( | ||
| self.persona.persona_description or stringified_characteristics | ||
| ) |
There was a problem hiding this comment.
Nit: you could avoid the creation of stringified_characteristics if the persona_description exist (similar comment for stop_prompt.py)
| NEGATIVE_PATTERNS = ( | ||
| r"\b(?:avoid|nothing|not|no|without|not into|not too|too much)\b.*" | ||
| r"\b{value}\b", | ||
| r"\bnot interested in\b.*\b{value}\b", | ||
| r"\b(?:anything but|other than|except|rather than)\b.*\b{value}\b", | ||
| r"\bnot a[n]?\b.*\b{value}\b", | ||
| r"\bnot in\b.*\b{value}\b(?:\s+genre)?\b", | ||
| r"\bwithout\b.*\b{value}\b", | ||
| r"\b{value}\s+(?:heavy|packed)\b", | ||
| ) | ||
| POSITIVE_PATTERNS = ( | ||
| r"\b(?:like|love|prefer|enjoy)\b.*\b{value}\b", | ||
| r"\blooking for\b.*\b{value}\b", | ||
| r"\binterested in\b.*\b{value}\b", | ||
| r"\breally looking for\b.*\b{value}\b", | ||
| r"\bcan you recommend\b.*\b{value}\b", | ||
| r"\bcould you suggest\b.*\b{value}\b", | ||
| r"\b(?:with|about|featuring|set in|centered around|based on)\b.*" | ||
| r"\b{value}\b", | ||
| r"\bthemes? of\b.*\b{value}\b", | ||
| r"\bmore\b.*\b{value}\b", | ||
| r"\bwithin the\b.*\b{value}\b(?:\s+genre)?\b", | ||
| r"\bin the\b.*\b{value}\b(?:\s+genre)?\b", | ||
| r"\b{value}\b.*\bover other genres\b", | ||
| r"\b{value}\s+focused\b", | ||
| ) | ||
| DIALOGUE_STOP_TOKENS = { | ||
| "exit", | ||
| "goodbye", | ||
| "bye", | ||
| "quit", | ||
| "stop", | ||
| "end", | ||
| "giveup", | ||
| } |
There was a problem hiding this comment.
I wonder if this could be used for initialisation of preferences based on historical dialogues, particularly interesting in a scenario with multiple session.
No description provided.