Get partial derivative of softmax activation
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(array_type), | intent(inout) | :: | this | |||
| type(array_type), | intent(in) | :: | upstream_grad |
function get_partial_softmax(this, upstream_grad) result(output) !! Get partial derivative of softmax activation implicit none class(array_type), intent(inout) :: this type(array_type), intent(in) :: upstream_grad type(array_type) :: output type(array_type), pointer :: ptr integer :: dim if(this%indices(1).eq.1)then dim = 2 else dim = 1 end if ! ptr => this * upstream_grad ! ptr => ptr - this * sum(ptr, dim=dim) ptr => softmax_reverse_array(this, upstream_grad, this%indices(1)) call output%assign_and_deallocate_source(ptr) end function get_partial_softmax