Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.32 KB | None | 0 0
  1. def softmax(x):
  2. #     x = x.clone() - this doesn't work
  3.     nx = tr.zeros(x.shape)
  4.  
  5.     for i in range(x.shape[1]):
  6.         colmax = x[:, i].max()
  7.        
  8.         for j in range(x.shape[0]):
  9.             nx[j, i] = tr.exp(x[j, i] - colmax)
  10.        
  11.         col = nx[:, i]
  12.         col /= col.sum()
  13.    
  14.     return nx
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement