MCPcopy Create free account
hub / github.com/pytorch/tutorials / log_sum_exp

Function log_sum_exp

beginner_source/nlp/advanced_tutorial.py:142–146  ·  view source on GitHub ↗
(vec)

Source from the content-addressed store, hash-verified

140
141# Compute log sum exp in a numerically stable way for the forward algorithm
142def log_sum_exp(vec):
143 max_score = vec[0, argmax(vec)]
144 max_score_broadcast = max_score.view(1, -1).expand(1, vec.size()[1])
145 return max_score + \
146 torch.log(torch.sum(torch.exp(vec - max_score_broadcast)))
147
148#####################################################################
149# Create model

Callers 1

_forward_algMethod · 0.85

Calls 1

argmaxFunction · 0.85

Tested by

no test coverage detected