ai-content-maker/.venv/Lib/site-packages/thinc/layers/sigmoid_activation.py

25 lines
652 B
Python
Raw Normal View History

2024-05-03 04:18:51 +03:00
from typing import Callable, Tuple, TypeVar, cast
from ..config import registry
from ..model import Model
from ..types import FloatsXdT
@registry.layers("sigmoid_activation.v1")
def sigmoid_activation() -> Model[FloatsXdT, FloatsXdT]:
return Model("sigmoid_activation", forward)
def forward(
model: Model[FloatsXdT, FloatsXdT], X: FloatsXdT, is_train: bool
) -> Tuple[FloatsXdT, Callable]:
Y = model.ops.sigmoid(X, inplace=False)
def backprop(dY: FloatsXdT) -> FloatsXdT:
return cast(
FloatsXdT,
dY * model.ops.dsigmoid(Y, inplace=False), # type:ignore[operator]
)
return Y, backprop