(self, feats)
return self._log_sum_exp(a + self.stop_transitions.unsqueeze(0), 1)
Computes the partitition function for CRF using the forward algorithm.
        Basically calculate scores for all possible tag sequences for 
        the given feature vector sequence
        Parameters:
            feats: Input features [batch size, sequence length, number of tags]
        Returns:
            Total scores of shape [batch size]
Computes the partitition function for CRF using the forward algorithm.
        Basically calculate scores for all possible tag sequences for 
        the given feature vector sequence
        Parameters:
            feats: Input features [batch size, sequence length, number of tags]
        Returns:
            Total scores of shape [batch size]
Computes the partitition function for CRF using the forward algorithm . Basically calculate scores for all possible tag sequences for the given feature vector sequence Parameters : feats : Input features [ batch size sequence length number of tags ] Returns : Total scores of shape [ batch size ]
def _partition_function(self, feats):
        """
        Computes the partitition function for CRF using the forward algorithm.
        Basically calculate scores for all possible tag sequences for 
        the given feature vector sequence
        Parameters:
            feats: Input features [batch size, sequence length, number of tags]
        Returns:
            Total scores of shape [batch size]
        """
        _, seq_size, num_tags = feats.shape

        if self.num_tags != num_tags:
            raise ValueError('num_tags should be {} but got {}'.format(self.num_tags, num_tags))

        a = feats[:, 0] + self.start_transitions.unsqueeze(0) # [batch_size, num_tags]
        transitions = self.transitions.unsqueeze(0) # [1, num_tags, num_tags] from -> to

        for i in range(1, seq_size):
            feat = feats[:, i].unsqueeze(1) # [batch_size, 1, num_tags]
            a = self._log_sum_exp(a.unsqueeze(-1) + transitions + feat, 1) # [batch_size, num_tags]

        return self._log_sum_exp(a + self.stop_transitions.unsqueeze(0), 1)
def _partition_function ( self , feats ) : _ , seq_size , num_tags = feats . shape if self . num_tags != num_tags : raise ValueError ( 'num_tags should be {} but got {}' . format ( self . num_tags , num_tags ) ) a = feats [ : , 0 ] + self . start_transitions . unsqueeze ( 0 ) # [batch_size, num_tags] transitions = self . transitions . unsqueeze ( 0 ) # [1, num_tags, num_tags] from -> to for i in range ( 1 , seq_size ) : feat = feats [ : , i ] . unsqueeze ( 1 ) # [batch_size, 1, num_tags] a = self . _log_sum_exp ( a . unsqueeze ( - 1 ) + transitions + feat , 1 ) # [batch_size, num_tags] return self . _log_sum_exp ( a + self . stop_transitions . unsqueeze ( 0 ) , 1 )