rasa/core/policies/embedding_policy.py
def _scale_loss_by_count_actions(self,
                                     X: np.ndarray,
                                     slots: np.ndarray,
                                     previous_actions: np.ndarray,
                                     actions_for_Y: np.ndarray
                                     ) -> Union[np.ndarray, List[List]]:
        """Calculate inverse proportionality of repeated actions."""

        if self.scale_loss_by_action_counts:
            full_X = np.concatenate([X, slots, previous_actions,
                                     actions_for_Y[:, :, np.newaxis]], -1)
            full_X = full_X.reshape((-1, full_X.shape[-1]))

            _, i, c = np.unique(full_X, return_inverse=True,
                                return_counts=True, axis=0)

            counts = c[i].reshape((X.shape[0], X.shape[1]))

            # do not include [-1 -1 ... -1 0] in averaging
            # and smooth it by taking sqrt
            return np.maximum(np.sqrt(np.mean(c[1:]) / counts), 1)
        else:
            return [[None]]
Calculate inverse proportionality of repeated actions.
Calculate inverse proportionality of repeated actions.
Calculate inverse proportionality of repeated actions .
def _scale_loss_by_count_actions(self,
                                     X: np.ndarray,
                                     slots: np.ndarray,
                                     previous_actions: np.ndarray,
                                     actions_for_Y: np.ndarray
                                     ) -> Union[np.ndarray, List[List]]:
        if self.scale_loss_by_action_counts:
            full_X = np.concatenate([X, slots, previous_actions,
                                     actions_for_Y[:, :, np.newaxis]], -1)
            full_X = full_X.reshape((-1, full_X.shape[-1]))
            _, i, c = np.unique(full_X, return_inverse=True,
                                return_counts=True, axis=0)
            counts = c[i].reshape((X.shape[0], X.shape[1]))
            return np.maximum(np.sqrt(np.mean(c[1:]) / counts), 1)
        else:
            return [[None]]
def _scale_loss_by_count_actions ( self , X : np . ndarray , slots : np . ndarray , previous_actions : np . ndarray , actions_for_Y : np . ndarray ) -> Union [ np . ndarray , List [ List ] ] : if self . scale_loss_by_action_counts : full_X = np . concatenate ( [ X , slots , previous_actions , actions_for_Y [ : , : , np . newaxis ] ] , - 1 ) full_X = full_X . reshape ( ( - 1 , full_X . shape [ - 1 ] ) ) _ , i , c = np . unique ( full_X , return_inverse = True , return_counts = True , axis = 0 ) counts = c [ i ] . reshape ( ( X . shape [ 0 ] , X . shape [ 1 ] ) ) return np . maximum ( np . sqrt ( np . mean ( c [ 1 : ] ) / counts ) , 1 ) else : return [ [ None ] ]
Calculate inverse proportionality of repeated actions.
Calculate inverse proportionality of repeated actions .
"""Calculate inverse proportionality of repeated actions.""" # do not include [-1 -1 ... -1 0] in averaging # and smooth it by taking sqrt
self
X
np.ndarray
slots
np.ndarray
previous_actions
np.ndarray
actions_for_Y
np.ndarray