tus_feature_handler¶
Feature handler for the TUS simulator.
For simplicity, the feature handler supports a single domain unlike the original implementation.
Classes¶
Initializes the feature handler. |
Module Contents¶
- class tus_feature_handler.TUSFeatureHandler(domain: usersimcrs.core.simulation_domain.SimulationDomain, max_turn_feature_length: int, context_depth: int, agent_actions: List[str], user_actions: List[str] = ['inform', 'request'])¶
Bases:
usersimcrs.simulator.neural.core.feature_handler.FeatureHandler
Initializes the feature handler.
- Parameters:
domain – Domain knowledge.
max_turn_feature_length – Maximum length of a turn feature vector.
context_depth – Number of previous turns to include in the input vector.
agent_actions – Agent actions.
user_actions – User actions. Defaults to [“inform”, “request”].
- reset() None ¶
Resets the feature handler.
- reset_user_feature_history() None ¶
Resets the user feature history.
- update_action_slots(slots: Iterable[str]) None ¶
Updates the action slots.
Action slots are slots present in the information need and mentioned during the conversation.
- Parameters:
slots – Slots mentioned in an utterance.
- get_basic_information_feature(slot: str, information_need: usersimcrs.core.information_need.InformationNeed, state: usersimcrs.dialogue_management.dialogue_state.DialogueState, previous_state: usersimcrs.dialogue_management.dialogue_state.DialogueState) usersimcrs.simulator.neural.core.feature_handler.FeatureVector ¶
Builds feature vector for basic information.
It concatenates the value in agent state, user state, slot type, completion status, and first mention.
- Parameters:
slot – Slot.
information_need – Information need.
state – Current state.
previous_state – Previous state.
- Returns:
Feature vector for basic information.
- get_agent_action_feature(agent_dialogue_acts: List[dialoguekit.core.dialogue_act.DialogueAct]) usersimcrs.simulator.neural.core.feature_handler.FeatureVector ¶
Builds feature vector for agent action.
It concatenates action vectors represented as 3-dimensional vectors that describe whether the slot and value are absent, only slot is present, or both slot and value are present.
- Parameters:
agent_dialogue_acts – Agent dialogue acts.
- Returns:
Feature vector for agent action.
- get_slot_index_feature(slot: str) usersimcrs.simulator.neural.core.feature_handler.FeatureVector ¶
Builds feature vector for slot index.
- Parameters:
slot – Slot.
- Returns:
Feature vector for slot index.
- get_slot_feature_vector(slot: str, previous_state: usersimcrs.dialogue_management.dialogue_state.DialogueState, state: usersimcrs.dialogue_management.dialogue_state.DialogueState, information_need: usersimcrs.core.information_need.InformationNeed, agent_dialogue_acts: List[dialoguekit.core.dialogue_act.DialogueAct], user_action_vector: torch.Tensor = None) usersimcrs.simulator.neural.core.feature_handler.FeatureVector ¶
Builds the feature vector for a slot.
It concatenates the basic information, user action, agent action, and slot index feature vectors.
- Parameters:
slot – Slot.
previous_state – Previous state.
state – Current state.
information_need – Information need.
agent_dialogue_acts – Agent dialogue acts.
user_action_vector – User action feature vector (output vector for previous turn). Defaults to None.
- Returns:
Feature vector for the slot.
- get_turn_feature_vectors(agent_dialogue_acts: List[dialoguekit.core.dialogue_act.DialogueAct], previous_state: usersimcrs.dialogue_management.dialogue_state.DialogueState, state: usersimcrs.dialogue_management.dialogue_state.DialogueState, information_need: usersimcrs.core.information_need.InformationNeed, user_action_vectors: Dict[str, torch.Tensor] = {}) List[usersimcrs.simulator.neural.core.feature_handler.FeatureVector] ¶
Builds the feature vectors for a turn.
It comprises the feature vectors for all slots that in the information need and mentioned during the conversation.
- Parameters:
agent_dialogue_acts – Agent dialogue acts.
previous_state – Previous state.
state – Current state.
information_need – Information need.
user_action_vectors – User action feature vectors per slot. Defaults to an empty dictionary.
- Returns:
Feature vectors for the turn.
- build_input_vector(agent_dialogue_acts: List[dialoguekit.core.dialogue_act.DialogueAct], previous_state: usersimcrs.dialogue_management.dialogue_state.DialogueState, state: usersimcrs.dialogue_management.dialogue_state.DialogueState, information_need: usersimcrs.core.information_need.InformationNeed, user_action_vectors: Dict[str, torch.Tensor] = {}) Tuple[List[usersimcrs.simulator.neural.core.feature_handler.FeatureVector], usersimcrs.simulator.neural.core.feature_handler.FeatureMask] ¶
Builds the input vector $V_{input}$ for a turn.
It concatenates the feature vectors for the last n turns separated by a special token. Note that is inferred from the list of feature vectors provided. The input vector is structured as follows: [CLS] $V^t$ [SEP] $V^{t-1}$ [SEP] … [SEP] $V^{t-n}$ [SEP] {padding}, where {padding} indicates the padding to reach the maximum length.
- Parameters:
agent_dialogue_acts – Agent dialogue acts.
previous_state – Previous state.
state – Current state.
information_need – Information need.
user_action_vectors – User action feature vectors per slot. Defaults to an empty dictionary.
- Returns:
Input vector.
- get_label_vector(user_utterance: dialoguekit.core.annotated_utterance.AnnotatedUtterance, current_state: usersimcrs.dialogue_management.dialogue_state.DialogueState, information_need: usersimcrs.core.information_need.InformationNeed) usersimcrs.simulator.neural.core.feature_handler.FeatureVector ¶
Builds the label vector for a turn.
- Parameters:
user_utterance – User utterance with annotations.
current_state – Current state.
information_need – Information need.
- Returns:
Label vector for the turn.
- save_handler(path: str) None ¶
Saves the feature handler.
- Parameters:
path – Path to the output file.
- classmethod load_handler(path: str) TUSFeatureHandler ¶
Loads a feature handler from a given path.
- Parameters:
path – Path to load the feature handler from.
- Raises:
FileNotFoundError – If the file is not found.
- Returns:
Feature handler.