Skip to content
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 explainable user model classes #223

Merged
merged 4 commits into from
Oct 27, 2023

Conversation

IKostric
Copy link
Collaborator

No description provided.

@IKostric
Copy link
Collaborator Author

Simple Explainable user model based on tags.

@IKostric IKostric requested review from kbalog and NoB0 September 26, 2023 09:16
@github-actions
Copy link

Current Branch Main Branch
Coverage Badge Coverage Badge

Copy link
Contributor

@NoB0 NoB0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly nits and suggestions. As for PR #184, we may need few iterations.

def generate_explanation(
self, user_preferences: UserPreferences
) -> AnnotatedUtterance:
"""Generate an explanation based on the provided input data.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Generate an explanation based on the provided input data.
"""Generates an explanation based on the provided input data.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

generated.

Returns:
The generated explanation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Maybe this could be more precise, like utterance containing explanation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 I was wondering why the return type was AnnotatedUtterance, so it would be worth mentioning here that the explanation is to be returned as a system utterance.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

UserPreferences,
)

_DEFAULT_TEMPLATE_FILE = "moviebot/explainability/explanation_templates.yaml"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would argue to put this file in the folder data.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


class ExplainableUserModelTagBased(ExplainableUserModel):
def __init__(self, template_file: str = _DEFAULT_TEMPLATE_FILE):
"""Initialize the ExplainableUserModelTagBased class.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: conjugate verb in docstring.

Suggested change
"""Initialize the ExplainableUserModelTagBased class.
"""Initializes the ExplainableUserModelTagBased class.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Args:
template_file: Path to the YAML file containing explanation
templates. Defaults to _DEFAULT_TEMPLATE_FILE.
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: check if file exists raise exception otherwise.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

def generate_explanation(
self, user_preferences: UserPreferences
) -> AnnotatedUtterance:
"""Generate an explanation based on the provided user preferences.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: conjugate verb in docstring.

Suggested change
"""Generate an explanation based on the provided user preferences.
"""Generates an explanation based on the provided user preferences.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"""Generate an explanation based on the provided user preferences.

Args:
user_preferences: Nested dictionary of user preferences.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: simply user preferences?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


Args:
template: Template containing negative keyword.
remove: If True, remove the negative keyword.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: add defaults value.

Suggested change
remove: If True, remove the negative keyword.
remove: If True, remove the negative keyword. Defaults to True.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done



@pytest.fixture
def explainable_model():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: missing return type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@pytest.fixture
def explainable_model():
return ExplainableUserModelTagBased(
"moviebot/explainability/explanation_templates.yaml"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if it you be best to make _DEFAULT_TEMPLATE_FILE public and reuse it here?

Copy link
Collaborator Author

@IKostric IKostric Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We dont even need to make it public. It defaults to the default path :)

Copy link
Contributor

@kbalog kbalog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming that UserPreferences contains item-based preferences, there is a missing step of inferring preferences for tags. That should take place in this class (by talking to the movie DB).

generated.

Returns:
The generated explanation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 I was wondering why the return type was AnnotatedUtterance, so it would be worth mentioning here that the explanation is to be returned as a system utterance.

@@ -0,0 +1,81 @@
"""This module contains the ExplainableUserModelTagBased class.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most modules contain a single class, so this docstring is not that informative. Suggestion instead: "Tag-based user model explanation."

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


Args:
template_file: Path to the YAML file containing explanation
templates. Defaults to _DEFAULT_TEMPLATE_FILE.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: second line should be indented.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

@kbalog kbalog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accidentally approved it, ignore

Copy link
Contributor

@kbalog kbalog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments

@IKostric IKostric requested a review from kbalog October 17, 2023 23:35
@IKostric
Copy link
Collaborator Author

Assuming that UserPreferences contains item-based preferences, there is a missing step of inferring preferences for tags. That should take place in this class (by talking to the movie DB).

Since we have attribute preferances readily available, we can start with those. Later, we can expand to item-based preferances.

Copy link
Contributor

@kbalog kbalog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (see one nit)

The class generates explanations for user preferences in the movie domain based
on templates loaded from a YAML file.
The class generates explanations for user preferences in the movie domain.
Currently, the explanations are based on the explicit movie tags/attributes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: "... are based on movie tags/attributes that were explicitly mentioned by the user in the conversation."

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@IKostric IKostric merged commit cc39825 into main Oct 27, 2023
2 checks passed
@IKostric IKostric deleted the feature/222-Add-ExplainableUserModel-Class branch October 27, 2023 08:52
@IKostric IKostric mentioned this pull request Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants