(self, g, r_prev)
return psi, np.rollaxis(r, 2)
Given prefix g, return the probability of all possible sequence y (where y = concat(g,c))
           This function computes all possible tokens for c (memory inefficient)
Given prefix g, return the probability of all possible sequence y (where y = concat(g,c))
           This function computes all possible tokens for c (memory inefficient)
Given prefix g return the probability of all possible sequence y ( where y = concat ( g c )) This function computes all possible tokens for c ( memory inefficient )
def full_compute(self, g, r_prev):
        '''Given prefix g, return the probability of all possible sequence y (where y = concat(g,c))
           This function computes all possible tokens for c (memory inefficient)'''
        prefix_length = len(g)
        last_char = g[-1] if prefix_length > 0 else 0

        # init. r
        r = np.full((self.input_length, 2, self.odim),
                    self.logzero, dtype=np.float32)

        # start from len(g) because is impossible for CTC to generate |y|>|X|
        start = max(1, prefix_length)

        if prefix_length == 0:
            r[0, 0, :] = self.x[0, :]    # if g = <sos>

        psi = r[start-1, 0, :]

        phi = np.logaddexp(r_prev[:, 0], r_prev[:, 1])

        for t in range(start, self.input_length):
            # prev_blank
            prev_blank = np.full((self.odim), r_prev[t-1, 1], dtype=np.float32)
            # prev_nonblank
            prev_nonblank = np.full(
                (self.odim), r_prev[t-1, 0], dtype=np.float32)
            prev_nonblank[last_char] = self.logzero

            phi = np.logaddexp(prev_nonblank, prev_blank)
            # P(h|current step is non-blank) = [ P(prev. step = y) + P()]*P(c)
            r[t, 0, :] = np.logaddexp(r[t-1, 0, :], phi) + self.x[t, :]
            # P(h|current step is blank) = [P(prev. step is blank) + P(prev. step is non-blank)]*P(now=blank)
            r[t, 1, :] = np.logaddexp(
                r[t-1, 1, :], r[t-1, 0, :]) + self.x[t, self.blank]
            psi = np.logaddexp(psi, phi+self.x[t, :])

        #psi[self.eos] = np.logaddexp(r_prev[-1,0], r_prev[-1,1])
        return psi, np.rollaxis(r, 2)
def full_compute ( self , g , r_prev ) : prefix_length = len ( g ) last_char = g [ - 1 ] if prefix_length > 0 else 0 # init. r r = np . full ( ( self . input_length , 2 , self . odim ) , self . logzero , dtype = np . float32 ) # start from len(g) because is impossible for CTC to generate |y|>|X| start = max ( 1 , prefix_length ) if prefix_length == 0 : r [ 0 , 0 , : ] = self . x [ 0 , : ] # if g = <sos> psi = r [ start - 1 , 0 , : ] phi = np . logaddexp ( r_prev [ : , 0 ] , r_prev [ : , 1 ] ) for t in range ( start , self . input_length ) : # prev_blank prev_blank = np . full ( ( self . odim ) , r_prev [ t - 1 , 1 ] , dtype = np . float32 ) # prev_nonblank prev_nonblank = np . full ( ( self . odim ) , r_prev [ t - 1 , 0 ] , dtype = np . float32 ) prev_nonblank [ last_char ] = self . logzero phi = np . logaddexp ( prev_nonblank , prev_blank ) # P(h|current step is non-blank) = [ P(prev. step = y) + P()]*P(c) r [ t , 0 , : ] = np . logaddexp ( r [ t - 1 , 0 , : ] , phi ) + self . x [ t , : ] # P(h|current step is blank) = [P(prev. step is blank) + P(prev. step is non-blank)]*P(now=blank) r [ t , 1 , : ] = np . logaddexp ( r [ t - 1 , 1 , : ] , r [ t - 1 , 0 , : ] ) + self . x [ t , self . blank ] psi = np . logaddexp ( psi , phi + self . x [ t , : ] ) #psi[self.eos] = np.logaddexp(r_prev[-1,0], r_prev[-1,1]) return psi , np . rollaxis ( r , 2 )