preference_model

User preference modeling interface.

Preferences are stored for (1) items in the collection and (2) slot-value pairs (for slots defined in the domain). Preferences are represented as real values in [-1,1], where zero corresponds to neutral.

Attributes

KEY_ITEM_ID

Classes

PreferenceModel

Initializes the preference model of a simulated user.

Module Contents

preference_model.KEY_ITEM_ID = 'ITEM_ID'
class preference_model.PreferenceModel(domain: usersimcrs.core.simulation_domain.SimulationDomain, item_collection: usersimcrs.items.item_collection.ItemCollection, historical_ratings: usersimcrs.items.ratings.Ratings, historical_user_id: str = None)

Bases: abc.ABC

Initializes the preference model of a simulated user.

A list of initial seen items is generated based on historical ratings. Further preferences are inferred along the way as the simulated user is being prompted by the agent for preferences.

Parameters:
  • domain – Domain.

  • item_collection – Item collection.

  • historical_ratings – Historical ratings.

  • historical_user_id (Optional) – If provided, the simulated user is based on this particular historical user; otherwise, it is based on a randomly sampled user. This is mostly added to make the class testable. Defaults to None.

PREFERENCE_THRESHOLD = 0.25
is_item_consumed(item_id: str) bool

Returns whether or not an item has been consumed by the user.

This is used to answer questions like: “Have you seen Inception?”

Parameters:

item_id – Item ID.

Returns:

True if the item has been consumed (i.e., appears among the historical ratings).

abstract get_item_preference(item_id: str) float

Returns a preference for a given item.

This is used to answer questions like: “How did you like it?”, where “it” refers to the movie mentioned previously.

Parameters:

item_id – Item ID.

Returns:

Item preference, which is generally in [-1,1].

Raises:

NotImplementedError – If not implemented in derived class.

abstract get_slot_value_preference(slot: str, value: str) float

Returns a preference on a given slot-value pair.

This is used to answer questions like: “Do you like action movies?”

Parameters:
  • slot – Slot name (needs to exist in the domain).

  • value – Slot value.

Returns:

Slot-value preference.

Raises:

NotImplementedError – If not implemented in derived class.

get_slot_preference(slot: str) Tuple[str, float]

Returns a preferred value for a given slot.

This is used to answer questions like: “What movie genre do you prefer?”

While in principle negative preferences could also be returned, here it is always a positive preference that is expressed.

Parameters:

slot – Slot name (needs to exist in the domain).

Returns:

A value and corresponding preferences; if no preference could be obtained for that slot, then (None, 0) are returned.

classmethod load_preference_model(path: str) PreferenceModel

Loads preference model from a file.

Parameters:

path – Path to preference model.

Raises:

FileNotFoundError – If file does not exist.

Returns:

Preference model.

save_preference_model(path: str) None

Saves preference model to a file.

Parameters:

path – Path to save preference model.