Skip to content

Commit

Permalink
stablized alpha softmax
Browse files Browse the repository at this point in the history
  • Loading branch information
Joost Bastings committed Nov 5, 2015
1 parent 9787eb2 commit b0f0627
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion session2/nmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ def _step_slice(m_, x_, xx_, xc_, h_, ctx_, alpha_, pctx_, cc_,
# compute alignment weights
alpha = tensor.dot(pctx__, U_att)+c_tt
alpha = alpha.reshape([alpha.shape[0], alpha.shape[1]])
alpha = tensor.exp(alpha)
alpha = tensor.exp(alpha - alpha.max(0, keepdims=True))

if context_mask:
alpha = alpha * context_mask
alpha = alpha / alpha.sum(0, keepdims=True)
Expand Down
3 changes: 2 additions & 1 deletion session3/nmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ def _step_slice(m_, x_, xx_, xc_, h_, ctx_, alpha_, pctx_, cc_,
# compute alignment weights
alpha = tensor.dot(pctx__, U_att)+c_tt
alpha = alpha.reshape([alpha.shape[0], alpha.shape[1]])
alpha = tensor.exp(alpha)
alpha = tensor.exp(alpha - alpha.max(0, keepdims=True))

if context_mask:
alpha = alpha * context_mask
alpha = alpha / alpha.sum(0, keepdims=True)
Expand Down

0 comments on commit b0f0627

Please sign in to comment.