janelu9 commented on issue #13329: problem about lstm_crf 
URL: 
https://github.com/apache/incubator-mxnet/issues/13329#issuecomment-443061287
 
 
   `    def _forward_alg(self, feats):
           # Do the forward algorithm to compute the partition function
           alphas = [[0.] * self.tagset_size]
           alphas[0][self.tag2idx[START_TAG]] = 1
           alphas = nd.array(alphas)
   
           # Iterate through the sentence
           for feat in feats:
               alphas_t = []  # The forward variables at this timestep
               for next_tag in range(self.tagset_size):
                   emit_score = feat[next_tag].reshape((1, -1))
                   trans_score = self.transitions.data()[next_tag].reshape((1, 
-1))
                   next_tag_var = alphas *nd.exp( trans_score + emit_score)
                   alphas_t.append(nsum(next_tag_var))
               alphas = nd.concat(*alphas_t, dim=0).reshape((1, -1))
           terminal_var = alphas *nd.exp( 
self.transitions.data()[self.tag2idx[STOP_TAG]])
           alpha = log_sum(terminal_var)
           return alpha`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to