Skip to content

Commit

Permalink
Add user model to DST
Browse files Browse the repository at this point in the history
Fixes #247
  • Loading branch information
IKostric committed Feb 26, 2024
1 parent bcdb7a1 commit e14bd2c
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions moviebot/dialogue_manager/dialogue_state_tracker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Dialogue state tracker updates the current dialogue state."""


from copy import deepcopy
from typing import Any, Dict, List

Expand All @@ -12,6 +11,7 @@
from moviebot.nlu.annotation.operator import Operator
from moviebot.nlu.annotation.slots import Slots
from moviebot.nlu.annotation.values import Values
from moviebot.user_modeling.user_model import UserModel


class DialogueStateTracker:
Expand All @@ -23,6 +23,7 @@ def __init__(self, config: Dict[str, Any], isBot: bool) -> None:
config: The set of parameters to initialize the state tracker.
isBot: If the conversation is via bot or not.
"""
self.user_model = UserModel()
self.domain: MovieDomain = config.get("domain")
self.slots: List[str] = config.get("slots", [])
self.isBot = isBot
Expand Down Expand Up @@ -158,9 +159,9 @@ def update_state_user( # noqa: C901
param.slot
] = param.value
else:
self.dialogue_state.frame_CIN[
param.slot
] = param.value
self.dialogue_state.frame_CIN[param.slot] = (
param.value
)

# checks if two parameters have the same value:
self.dialogue_state.agent_must_clarify = False
Expand Down Expand Up @@ -262,6 +263,8 @@ def update_state_user( # noqa: C901
self.dialogue_state.agent_can_lookup = True
break

self.update_user_model(self.dialogue_state.frame_CIN)

def update_state_agent(self, agent_dacts: List[DialogueAct]) -> None:
"""Updates the current dialogue state and context based on agent
dialogue acts.
Expand Down Expand Up @@ -371,6 +374,33 @@ def update_state_db(
self.dialogue_state.agent_should_make_offer = False
self.dialogue_state.agent_made_offer = False

def update_user_model(self, frame_CIN: Dict[str, Any]) -> None:
"""Updates the user model based on the current dialogue state.
Args:
frame_CIN: Current information needs of the user.
"""

def add_to_user_model(value: str):
"""Helper function to assign value to the user model."""
is_negative = value.startswith(".NOT.")
if is_negative:
value = value[5:]
self.user_model.slot_preferences[slot][value] = (
-1 if is_negative else 1
)

for slot, value in frame_CIN.items():
if not value:
continue

if slot in self.domain.multiple_values_CIN:
for val in value:
add_to_user_model(val)

else:
add_to_user_model(value)

def get_state(self) -> DialogueState:
"""Returns the current dialogue state.
Expand Down

0 comments on commit e14bd2c

Please sign in to comment.