Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def softmax(x):
- # x = x.clone() - this doesn't work
- nx = tr.zeros(x.shape)
- for i in range(x.shape[1]):
- colmax = x[:, i].max()
- for j in range(x.shape[0]):
- nx[j, i] = tr.exp(x[j, i] - colmax)
- col = nx[:, i]
- col /= col.sum()
- return nx
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement