def _assemble_label_data( self, attribute_data: Data, domain: Domain ) -> RasaModelData: """Constructs data regarding labels to be fed to the model. The resultant model data should contain the keys `label_intent`, `label`. `label_intent` will contain the sequence, sentence and mask features for all intent labels and `label` will contain the numerical label ids. Args: attribute_data: Feature data for all intent labels. domain: Domain of the assistant. Returns: Features of labels ready to be fed to the model. """ label_data = RasaModelData() label_data.add_data(attribute_data, key_prefix=f"{LABEL_KEY}_") label_data.add_lengths( f"{LABEL}_{INTENT}", SEQUENCE_LENGTH, f"{LABEL}_{INTENT}", SEQUENCE, ) label_ids = np.arange(len(domain.intents)) label_data.add_features( LABEL_KEY, LABEL_SUB_KEY, [FeatureArray(np.expand_dims(label_ids, -1), number_of_dimensions=2)], ) return label_data
def _assemble_label_data(self, attribute_data: Data, domain: Domain) -> RasaModelData: """Constructs data regarding labels to be fed to the model. The resultant model data can possibly contain one or both of the keys - [`label_action_name`, `label_action_text`] but will definitely contain the `label` key. `label_action_*` will contain the sequence, sentence and mask features for corresponding labels and `label` will contain the numerical label ids. Args: attribute_data: Feature data for all labels. domain: Domain of the assistant. Returns: Features of labels ready to be fed to the model. """ label_data = RasaModelData() label_data.add_data(attribute_data, key_prefix=f"{LABEL_KEY}_") label_data.add_lengths( f"{LABEL}_{ACTION_TEXT}", SEQUENCE_LENGTH, f"{LABEL}_{ACTION_TEXT}", SEQUENCE, ) label_ids = np.arange(domain.num_actions) label_data.add_features( LABEL_KEY, LABEL_SUB_KEY, [ FeatureArray(np.expand_dims(label_ids, -1), number_of_dimensions=2) ], ) return label_data
def _create_model_data( self, tracker_state_features: List[List[Dict[Text, List["Features"]]]], label_ids: Optional[np.ndarray] = None, encoded_all_labels: Optional[List[Dict[Text, List["Features"]]]] = None, ) -> RasaModelData: """Combine all model related data into RasaModelData. Args: tracker_state_features: a dictionary of attributes (INTENT, TEXT, ACTION_NAME, ACTION_TEXT, ENTITIES, SLOTS, ACTIVE_LOOP) to a list of features for all dialogue turns in all training trackers label_ids: the label ids (e.g. action ids) for every dialogue turn in all training trackers encoded_all_labels: a list of dictionaries containing attribute features for labels ids Returns: RasaModelData """ model_data = RasaModelData(label_key=LABEL_KEY, label_sub_key=LABEL_SUB_KEY) if label_ids is not None and encoded_all_labels is not None: label_ids = np.array( [np.expand_dims(seq_label_ids, -1) for seq_label_ids in label_ids] ) model_data.add_features(LABEL_KEY, LABEL_SUB_KEY, [label_ids]) attribute_data, self.zero_state_features = convert_to_data_format( tracker_state_features ) else: # method is called during prediction attribute_data, _ = convert_to_data_format( tracker_state_features, self.zero_state_features ) model_data.add_data(attribute_data) model_data.add_lengths( DIALOGUE, LENGTH, next(iter(list(attribute_data.keys()))), MASK ) return model_data
def _create_model_data( self, tracker_state_features: List[List[Dict[Text, List["Features"]]]], label_ids: Optional[np.ndarray] = None, entity_tags: Optional[List[List[Dict[Text, List["Features"]]]]] = None, encoded_all_labels: Optional[List[Dict[Text, List["Features"]]]] = None, ) -> RasaModelData: """Combine all model related data into RasaModelData. Args: tracker_state_features: a dictionary of attributes (INTENT, TEXT, ACTION_NAME, ACTION_TEXT, ENTITIES, SLOTS, ACTIVE_LOOP) to a list of features for all dialogue turns in all training trackers label_ids: the label ids (e.g. action ids) for every dialogue turn in all training trackers entity_tags: a dictionary of entity type (ENTITY_TAGS) to a list of features containing entity tag ids for text user inputs otherwise empty dict for all dialogue turns in all training trackers encoded_all_labels: a list of dictionaries containing attribute features for label ids Returns: RasaModelData """ model_data = RasaModelData(label_key=LABEL_KEY, label_sub_key=LABEL_SUB_KEY) if label_ids is not None and encoded_all_labels is not None: label_ids = np.array([ np.expand_dims(seq_label_ids, -1) for seq_label_ids in label_ids ]) model_data.add_features( LABEL_KEY, LABEL_SUB_KEY, [FeatureArray(label_ids, number_of_dimensions=3)], ) attribute_data, self.fake_features = convert_to_data_format( tracker_state_features, featurizers=self.config[FEATURIZERS]) entity_tags_data = self._create_data_for_entities(entity_tags) if entity_tags_data is not None: model_data.add_data(entity_tags_data) else: # method is called during prediction attribute_data, _ = convert_to_data_format( tracker_state_features, self.fake_features, featurizers=self.config[FEATURIZERS], ) model_data.add_data(attribute_data) model_data.add_lengths(TEXT, SEQUENCE_LENGTH, TEXT, SEQUENCE) model_data.add_lengths(ACTION_TEXT, SEQUENCE_LENGTH, ACTION_TEXT, SEQUENCE) # add the dialogue lengths attribute_present = next(iter(list(attribute_data.keys()))) dialogue_lengths = np.array([ np.size(np.squeeze(f, -1)) for f in model_data.data[attribute_present][MASK][0] ]) model_data.data[DIALOGUE][LENGTH] = [ FeatureArray(dialogue_lengths, number_of_dimensions=1) ] # make sure all keys are in the same order during training and prediction model_data.sort() return model_data