-
Notifications
You must be signed in to change notification settings - Fork 10
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
Create UserModel class #184
Merged
Merged
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b639f87
First attempt at creating the UserModel class
NoB0 5411404
Fix flake issue
NoB0 80e66cc
Update initialisation of UserModel
NoB0 de0f06b
Add method to store explicitly set preferences
NoB0 0b1ef36
Address review comments
NoB0 4f11fc7
Refactor user model
NoB0 7291c61
Merge branch 'main' into feature/128-Create-UserModel-class
NoB0 1b6ea9a
Add a method to save UserModel
NoB0 ee695c9
Fix typo
NoB0 72fef3e
Update moviebot/user_modeling/user_model.py
NoB0 c09866d
Address review comments
NoB0 2fa2bb8
Add tests for user model
NoB0 e044719
Merge branch 'main' into feature/128-Create-UserModel-class
NoB0 34f916b
Address review comments
NoB0 c406c88
Fix get_utterances_with_slot_preferences
NoB0 16940b2
Black
NoB0 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 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""This module is used to process the user's decision on a movie recommendation. | ||
""" | ||
|
||
from enum import Enum | ||
|
||
|
||
class RecommendationChoices(Enum): | ||
"""Enum class for recommendation choices.""" | ||
|
||
ACCEPT = "accept" | ||
REJECT = "reject" | ||
DONT_LIKE = "dont_like" | ||
WATCHED = "watched" | ||
|
||
|
||
def convert_choice_to_preference(choice: RecommendationChoices) -> float: | ||
"""Converts a choice to a preference within the range [-1,1]. | ||
|
||
Dislike is represented by a preference below 0, while like is | ||
represented by a preference above 0. If the choice does not express a | ||
preference (e.g., inquire), then the preference is neutral, i.e., 0. | ||
Possible choices are: accept, reject, dont_like, inquire, and watched. | ||
|
||
Args: | ||
choice: Choice. | ||
|
||
Returns: | ||
Preference within the range [-1,1]. | ||
""" | ||
if choice == RecommendationChoices.ACCEPT: | ||
return 1.0 | ||
elif choice in [ | ||
RecommendationChoices.REJECT, | ||
RecommendationChoices.DONT_LIKE, | ||
]: | ||
return -1.0 | ||
|
||
return 0.0 |
This file contains 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 |
---|---|---|
|
@@ -19,6 +19,10 @@ | |
from moviebot.nlu.annotation.slots import Slots | ||
from moviebot.nlu.annotation.values import Values | ||
from moviebot.nlu.data_loader import DataLoader | ||
from moviebot.nlu.recommendation_decision_processing import ( | ||
RecommendationChoices, | ||
convert_choice_to_preference, | ||
) | ||
|
||
PATTERN_BASIC = { | ||
UserIntents.ACKNOWLEDGE: ["yes", "okay", "fine", "sure"], | ||
|
@@ -334,15 +338,27 @@ def check_reject_intent( | |
] | ||
): | ||
dact.intent = UserIntents.REJECT | ||
dact.params = [ItemConstraint("reason", Operator.EQ, "dont_like")] | ||
preference = convert_choice_to_preference( | ||
RecommendationChoices.DONT_LIKE | ||
) | ||
dact.params = [ | ||
ItemConstraint("reason", Operator.EQ, "dont_like"), | ||
ItemConstraint("preference", Operator.EQ, preference), | ||
] | ||
elif any( | ||
[ | ||
re.search(r"\b{0}\b".format(pattern), utterance) | ||
for pattern in PATTERN_WATCHED | ||
] | ||
): | ||
dact.intent = UserIntents.REJECT | ||
dact.params = [ItemConstraint("reason", Operator.EQ, "watched")] | ||
preference = convert_choice_to_preference( | ||
RecommendationChoices.WATCHED | ||
) | ||
dact.params = [ | ||
ItemConstraint("reason", Operator.EQ, "watched"), | ||
ItemConstraint("preference", Operator.EQ, preference), | ||
Comment on lines
+361
to
+362
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. Please create an issue for creating enums for the possible contraints that can be expressed ("reason", "perference", etc.) 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. Follow-up issue #225 |
||
] | ||
if dact.intent != UserIntents.UNK: | ||
user_dacts.append(dact) | ||
return user_dacts | ||
|
Empty file.
Oops, something went wrong.
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.
This is fine, but why not just have the enum values as the preferences?
https://stackoverflow.com/questions/69716107/can-i-use-an-enum-with-floating-point-values-and-comparators-in-python-3-9-and-s
Not sure it needs Python 3.9, but also there is probably no reason for us not to use 3.9 for MovieBot.
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.
Follow-up issue #226