Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. class Softmax:
  2. # ...
  3.  
  4. def forward(self, input):
  5. '''
  6. Performs a forward pass of the softmax layer using the given input.
  7. Returns a 1d numpy array containing the respective probability values.
  8. - input can be any array with any dimensions.
  9. '''
  10. self.last_input_shape = input.shape
  11.  
  12. input = input.flatten()
  13. self.last_input = input
  14.  
  15. input_len, nodes = self.weights.shape
  16.  
  17. totals = np.dot(input, self.weights) + self.biases
  18. self.last_totals = totals
  19.  
  20. exp = np.exp(totals)
  21. return exp / np.sum(exp, axis=0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement