Read the equation
The derivative of tanh(x) is 1−tanh²(x). It is largest at zero and approaches zero in the saturated tails. Reusing the forward output in the backward pass avoids an additional tanh evaluation.
Terms & definitions
| Term | Meaning in this source |
|---|---|
| x | Activation input |
| z | tanh output |
How it works
Read the definition from its right-hand expression to the quantity on the left. Its surrounding source records the intended input, state, or parameter context. Where the source leaves an operation unspecified, this page preserves that gap.
Assumptions & limits
Source recovery establishes that the expression appears in this record. Its mathematical validity, implementation behavior, and interpretation must be assessed separately. See the linked source and research notes for the checks available for this version.
Original context
Read the surrounding source passage
z->backward_fn = [x, y, z]() {
x->grad += z->grad / y->value;
y->grad -= z->grad * x->value / (y->value * y->value);
};
return tape.record(z);
}
// Tanh: z = tanh(x), dz/dx = 1 - tanh^2(x)
inline GradNodePtr tanh_op(GradNodePtr x, TapeRecorder& tape) {
double t = std::tanh(x->value);
auto z = std::make_shared<GradNode>(t);
z->inputs = {x};
z->backward_fn = [x, z, t]() {
x->grad += z->grad * (1.0 - t * t);
};
return tape.record(z);
}
Exact original notation
Tanh: z = tanh(x), dz/dx = 1 - tanh^2(x)