Avatar
sigmoidとその微分の実装がここ https://github.com/tensorflow/swift-apis/blob/323b5640c48822340f2f5410d6bff51972fc9f45/Sources/TensorFlow/Operators/Math.swift#L970-L975 /// Returns the sigmoid of the specified tensor element-wise. /// Specifically, computes `1 / (1 + exp(-x))`. @inlinable @differentiable(vjp: _vjpSigmoid) public func sigmoid<T: TensorFlowFloatingPoint>(_ x: Tensor<T>) -> Tensor<T> { Raw.sigmoid(x) } @inlinable internal func _vjpSigmoid<T: TensorFlowFloatingPoint>( _ x: Tensor<T> ) -> (Tensor<T>, (Tensor<T>) -> Tensor<T>) { (sigmoid(x), { v in Raw.sigmoidGrad(x, dy: v) }) } Raw.sigmoidGradがこれなのでyを渡すべきところでxを渡してる? https://raw.githubusercontent.com/tensorflow/swift-apis/master/Sources/TensorFlow/Bindings/RawOpsGenerated.swift /// Computes the gradient of the sigmoid of `x` wrt its input. /// /// Specifically, `grad = dy * y * (1 - y)`, where `y = sigmoid(x)`, and /// `dy` is the corresponding input gradient. @inlinable @inline(__always) public static func sigmoidGrad<T: FloatingPoint & TensorFlowScalar>( _ y: Tensor<T>, dy: Tensor<T> ) -> Tensor<T> (edited)
Swift for TensorFlow Deep Learning Library. Contribute to tensorflow/swift-apis development by creating an account on GitHub.