Technical Reference: Role of ReLU, Softmax, Tanh, and Sigmoid across Model Building, Evaluation, and Pipeline Architectures
Model evaluation and analysis is the measurement, validation, and diagnostic pillar within the machine learning (ML) and neural network (NN) lifecycle. An algorithm fits parameters (weights and biases), but evaluation determines whether those parameters generalize, remain calibrated, and satisfy operational thresholds.
Formula: σ(z) = 1 / (1 + e-z) | Range: (0, 1)
Primary Retail Objective: Binary recommendation prediction (Recommended.IND, 0 vs 1).
Formula: ezi / ∑ ezj | Range: (0, 1), ∑ = 1.0
Primary Retail Objective: Multi-class routing and Transformer self-attention.
Low, Medium, Critical; or 6 apparel departments).Formula: f(z) = max(0, z) | Range: [0, ∞)
Primary Retail Objective: Non-linear feature representation in deep architectures.
Formula: (ez - e-z) / (ez + e-z) | Range: (-1, 1)
Primary Retail Objective: Zero-centered recurrent representations.
| Model Family & Paradigm | Hidden Layer Activations | Output Layer Activations | Relevance & Justification in ChicStyle Architecture |
|---|---|---|---|
| Classical ML Baseline (TF-IDF + Logistic Regression) |
None (Strictly linear feature map) | Sigmoid | Essential: Computes continuous probabilities for binary Recommended.IND triage under 2 ms. |
| Discriminative Neural Networks (PyTorch MLP / DeBERTa Classification Head) |
ReLU or GELU | Sigmoid (Binary) Softmax (Urgency / Dept) |
Essential: Hidden non-linearities capture complex garment aspect interactions; output squashing yields production confidence scores. |
| Generative AI & LLMs (Zero-Shot, Few-Shot, CoT API Calls) |
Internal Transformer units (GELU/SwiGLU) | Softmax over Vocabulary Logits | Internal: Governs next-token generation probability distributions and temperature sampling during structured JSON synthesis. |
The following standalone script demonstrates how each activation function behaves on sample model logits and verifies their operational outputs:
import numpy as np
def relu(z: np.ndarray) -> np.ndarray:
"""Rectified Linear Unit for hidden layer non-linearity."""
return np.maximum(0, z)
def sigmoid(z: np.ndarray) -> np.ndarray:
"""Sigmoid activation for binary classification probability mapping."""
return 1.0 / (1.0 + np.exp(-z))
def tanh(z: np.ndarray) -> np.ndarray:
"""Zero-centered hyperbolic tangent activation."""
return np.tanh(z)
def softmax(z: np.ndarray) -> np.ndarray:
"""Softmax activation for multi-class probability normalization."""
exp_shifted = np.exp(z - np.max(z)) # Shifted for numerical stability
return exp_shifted / np.sum(exp_shifted, axis=-1, keepdims=True)
if __name__ == "__main__":
# 1. Simulating binary recommendation logit (Recommended.IND)
detractor_logit = np.array([-2.19]) # Raw logit for defective zipper review
promoter_logit = np.array([3.45]) # Raw logit for glowing 5-star review
print("--- 1. SIGMOID BINARY EVALUATION ---")
print(f"Detractor Recommendation Probability: {sigmoid(detractor_logit)[0]:.4f} (Target = 0)")
print(f"Promoter Recommendation Probability: {sigmoid(promoter_logit)[0]:.4f} (Target = 1)")
# 2. Simulating multi-class urgency logits: [Low, Medium, Critical]
urgency_logits = np.array([0.45, 1.20, 3.85])
urgency_probs = softmax(urgency_logits)
print("\n--- 2. SOFTMAX MULTI-CLASS URGENCY TRIAGE ---")
tiers = ["Low", "Medium", "Critical"]
for tier, prob in zip(tiers, urgency_probs):
print(f" Urgency Tier [{tier}]: {prob * 100:.2f}%")
print(f" Sum of probabilities: {np.sum(urgency_probs):.1f}")
# 3. Hidden layer feature transformations
hidden_features = np.array([-1.5, -0.2, 0.0, 1.8, 3.2])
print("\n--- 3. HIDDEN LAYER ACTIVATION COMPARISON ---")
print(f"Raw Input Logits: {hidden_features}")
print(f"ReLU Filtered: {relu(hidden_features)}")
print(f"Tanh Transformed: {np.round(tanh(hidden_features), 4)}")