#128 · Deep Learning · Easy
⊣ Solve on deep-ml.comImplement the Dynamic Tanh (DyTanh) activation function, a normalization-free alternative for transformers. Given input x and learnable parameter alpha, compute tanh(alpha * x). This provides adaptive nonlinearity without requiring layer normalization.
import numpy as np
def dynamic_tanh(x: np.ndarray, alpha: float = 1.0) -> np.ndarray:
return np.tanh(alpha * x)
def dynamic_tanh_with_params(x: np.ndarray, alpha: np.ndarray, gamma: np.ndarray, beta: np.ndarray) -> np.ndarray:
# Full version: gamma * tanh(alpha * x) + beta
return gamma * np.tanh(alpha * x) + betatanh(alpha * x) where alpha controls the steepness of the activation.