rasa/core/policies/embedding_policy.py
def _create_batch_b(self,
                        batch_pos_b: np.ndarray,
                        intent_ids: np.ndarray
                        ) -> np.ndarray:
        """Create batch of actions.

        The first is correct action
        and the rest are wrong actions sampled randomly.
        """

        batch_pos_b = batch_pos_b[:, :, np.newaxis, :]

        # sample negatives
        batch_neg_b = np.zeros((batch_pos_b.shape[0],
                                batch_pos_b.shape[1],
                                self.num_neg,
                                batch_pos_b.shape[-1]),
                               dtype=int)
        for b in range(batch_pos_b.shape[0]):
            for h in range(batch_pos_b.shape[1]):
                # create negative indexes out of possible ones
                # except for correct index of b
                negative_indexes = [
                    i
                    for i in range(self.encoded_all_actions.shape[0])
                    if i != intent_ids[b, h]
                ]

                negs = np.random.choice(negative_indexes, size=self.num_neg)

                batch_neg_b[b, h] = self.encoded_all_actions[negs]

        return np.concatenate([batch_pos_b, batch_neg_b], -2)
Create batch of actions.

        The first is correct action
        and the rest are wrong actions sampled randomly.
        
Create batch of actions.
The first is correct action
and the rest are wrong actions sampled randomly.
Create batch of actions . The first is correct action and the rest are wrong actions sampled randomly .
def _create_batch_b(self,
                        batch_pos_b: np.ndarray,
                        intent_ids: np.ndarray
                        ) -> np.ndarray:
        batch_pos_b = batch_pos_b[:, :, np.newaxis, :]
        batch_neg_b = np.zeros((batch_pos_b.shape[0],
                                batch_pos_b.shape[1],
                                self.num_neg,
                                batch_pos_b.shape[-1]),
                               dtype=int)
        for b in range(batch_pos_b.shape[0]):
            for h in range(batch_pos_b.shape[1]):
                negative_indexes = [
                    i
                    for i in range(self.encoded_all_actions.shape[0])
                    if i != intent_ids[b, h]
                ]
                negs = np.random.choice(negative_indexes, size=self.num_neg)
                batch_neg_b[b, h] = self.encoded_all_actions[negs]
        return np.concatenate([batch_pos_b, batch_neg_b], -2)
def _create_batch_b ( self , batch_pos_b : np . ndarray , intent_ids : np . ndarray ) -> np . ndarray : batch_pos_b = batch_pos_b [ : , : , np . newaxis , : ] batch_neg_b = np . zeros ( ( batch_pos_b . shape [ 0 ] , batch_pos_b . shape [ 1 ] , self . num_neg , batch_pos_b . shape [ - 1 ] ) , dtype = int ) for b in range ( batch_pos_b . shape [ 0 ] ) : for h in range ( batch_pos_b . shape [ 1 ] ) : negative_indexes = [ i for i in range ( self . encoded_all_actions . shape [ 0 ] ) if i != intent_ids [ b , h ] ] negs = np . random . choice ( negative_indexes , size = self . num_neg ) batch_neg_b [ b , h ] = self . encoded_all_actions [ negs ] return np . concatenate ( [ batch_pos_b , batch_neg_b ] , - 2 )
Create batch of actions.
Create batch of actions .
"""Create batch of actions.

        The first is correct action
        and the rest are wrong actions sampled randomly.
        """ # sample negatives # create negative indexes out of possible ones # except for correct index of b
self
batch_pos_b
np.ndarray
intent_ids
np.ndarray