def _process_event_with_trackers(self, event, trackers): # type: (Event, List[FeaturizedTracker]) -> TrackerResult """Logs an event to all trackers. Removes trackers that create equal featurizations. From multiple trackers that create equal featurizations we only need to keep one. Because as we continue processing events and story steps, all trackers that created the same featurization once will do so in the future (as we feed the same events to all trackers).""" # collected trackers that created different featurizations unique_trackers = [] featurizations = set() # collected training data features = [] labels = [] for tracker in trackers: if isinstance(event, ActionExecuted): state_features = tracker.feauturize_current_state(self.domain) feature_vector = self.domain.slice_feature_history( self.featurizer, state_features, self.config.max_history) hashed = utils.HashableNDArray(feature_vector) # only continue with trackers that created a # featurization we haven't observed at this event if (hashed not in featurizations or not self.config.remove_duplicates): featurizations.add(hashed) if not event.unpredictable: # only actions which can be predicted at a stories start a_idx = self.domain.index_for_action(event.action_name) features.append(feature_vector) labels.append(a_idx) unique_trackers.append(tracker) else: unique_trackers.append(tracker) tracker.update(event) if not isinstance(event, ActionExecuted): action_name = tracker.previously_executed_action() self.events_metadata[action_name].add(event) return TrackerResult(features, labels, unique_trackers)
def _process_event_with_trackers( self, event, # type: Event trackers, # type: List[FeaturizedTracker] max_history # type: int ): """Logs an event to all trackers. Removes trackers that create equal featurizations. From multiple trackers that create equal featurizations we only need to keep one. Because as we continue processing events and story steps, all trackers that created the same featurization once will do so in the future (as we feed the same events to all trackers).""" # collected trackers that created different featurizations unique_trackers = [] featurizations = set() # collected training data training_features = [] training_labels = [] for tracker in trackers: if isinstance(event, ActionExecuted): state_features = tracker.feauturize_current_state(self.domain) feature_vector = self.domain.slice_feature_history( self.featurizer, state_features, max_history) hashed = utils.HashableNDArray(feature_vector) # only continue with trackers that created a # featurization we haven't observed at this event if hashed not in featurizations: featurizations.add(hashed) if not event.unpredictable: # only actions which can be predicted at a stories start training_features.append(feature_vector) training_labels.append( self.domain.index_for_action(event.action_name)) unique_trackers.append(tracker) else: unique_trackers.append(tracker) tracker.update(event) return training_features, training_labels, unique_trackers